|
@@ -0,0 +1,302 @@
|
|
|
|
+package com.mooctest.crowd.site.controller;
|
|
|
|
+
|
|
|
|
+import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
|
|
|
|
+import com.mooctest.crowd.domain.domainobject.CrowdTestTask;
|
|
|
|
+import com.mooctest.crowd.domain.domainobject.Defect;
|
|
|
|
+import com.mooctest.crowd.site.annotation.LoginRequired;
|
|
|
|
+import com.mooctest.crowd.site.command.MixDefectSaveCommand;
|
|
|
|
+import com.mooctest.crowd.site.data.response.ResponseVO;
|
|
|
|
+import com.mooctest.crowd.site.data.response.ServerCode;
|
|
|
|
+import com.mooctest.crowd.site.data.vo.MixDefectInfoVO;
|
|
|
|
+import com.mooctest.crowd.site.service.CrowdProjectService;
|
|
|
|
+import com.mooctest.crowd.site.service.CrowdTaskService;
|
|
|
|
+import com.mooctest.crowd.site.service.MixDefectService;
|
|
|
|
+import com.mooctest.crowd.site.service.UserService;
|
|
|
|
+import com.mooctest.crowd.site.util.RequestUtils;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import org.apache.http.client.utils.DateUtils;
|
|
|
|
+import org.apache.logging.log4j.util.Strings;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/api/mixdefect")
|
|
|
|
+@Api(tags = "缺陷融合接口")
|
|
|
|
+public class MixDefectController {
|
|
|
|
+ @Autowired
|
|
|
|
+ private MixDefectService mixDefectService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserService userService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CrowdTaskService crowdTaskService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CrowdProjectService crowdProjectService;
|
|
|
|
+
|
|
|
|
+ @PostMapping("/generate/{taskCode}")
|
|
|
|
+ public ResponseVO generate(@PathVariable("taskCode") String taskCode) {
|
|
|
|
+ boolean res = mixDefectService.post(taskCode);
|
|
|
|
+ return new ResponseVO(res ? ServerCode.SUCCESS : ServerCode.ERROR);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping("/status/{taskCode}")
|
|
|
|
+ public ResponseVO<Byte> getStatus(@PathVariable("taskCode") String taskCode) {
|
|
|
|
+ return new ResponseVO(ServerCode.SUCCESS, mixDefectService.getStatus(taskCode));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/batchsave")
|
|
|
|
+ public ResponseVO batchSave(@RequestBody List<MixDefectSaveCommand> mixDefectSaveCommands) {
|
|
|
|
+ mixDefectService.batchSave(mixDefectSaveCommands);
|
|
|
|
+ return new ResponseVO(ServerCode.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/exchange/{masterDefectId}/{suppDefectId}")
|
|
|
|
+ @LoginRequired
|
|
|
|
+ public ResponseVO exchange(HttpServletRequest request, @PathVariable("masterDefectId") Long masterDefectId, @PathVariable("suppDefectId") Long suppDefectId) {
|
|
|
|
+ mixDefectService.exchange(RequestUtils.getUserId(request), masterDefectId, suppDefectId);
|
|
|
|
+ return new ResponseVO(ServerCode.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/tomaster/{suppDefectId}")
|
|
|
|
+ @LoginRequired
|
|
|
|
+ public ResponseVO toMaster(HttpServletRequest request, @PathVariable("suppDefectId") Long suppDefectId) {
|
|
|
|
+ mixDefectService.toMaster(RequestUtils.getUserId(request), suppDefectId);
|
|
|
|
+ return new ResponseVO(ServerCode.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/toothermasterdefect/{masterDefectId}/{movedDefectId}")
|
|
|
|
+ @LoginRequired
|
|
|
|
+ public ResponseVO toMaster(HttpServletRequest request, @PathVariable("masterDefectId") Long masterDefectId, @PathVariable("movedDefectId") Long movedDefectId) {
|
|
|
|
+ mixDefectService.toOtherMasterDefect(RequestUtils.getUserId(request), masterDefectId, movedDefectId);
|
|
|
|
+ return new ResponseVO(ServerCode.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping("/{taskCode}")
|
|
|
|
+ @LoginRequired
|
|
|
|
+ public ResponseVO<List<MixDefectInfoVO>> list(HttpServletRequest request, @PathVariable("taskCode") String taskCode) {
|
|
|
|
+ List<MixDefectInfoVO> mixDefectInfoVOs = mixDefectService.findAllByTaskCode(RequestUtils.getUserId(request), taskCode);
|
|
|
|
+ return new ResponseVO(ServerCode.SUCCESS, mixDefectInfoVOs);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping(value = "/export/{taskCode}")
|
|
|
|
+ @LoginRequired
|
|
|
|
+ public void export(HttpServletRequest request, HttpServletResponse response, @PathVariable("taskCode") String taskCode) throws IOException {
|
|
|
|
+ Workbook wb = new XSSFWorkbook();
|
|
|
|
+ Long userId = RequestUtils.getUserId(request);
|
|
|
|
+ createTaskDefectSheet(wb, userId, taskCode);
|
|
|
|
+ CrowdTestTask task = crowdTaskService.getByTaskCode(taskCode);
|
|
|
|
+ response.setHeader("Content-Disposition", String.format("attachment;filename=%s.xlsx",
|
|
|
|
+ URLEncoder.encode(task.getName(), "utf-8")));
|
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
|
+ OutputStream os = response.getOutputStream();
|
|
|
|
+ wb.write(os);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping(value = "/exportproject/{projectCode}")
|
|
|
|
+ @LoginRequired
|
|
|
|
+ public void exportProject(HttpServletRequest request, HttpServletResponse response, @PathVariable("projectCode") String projectCode) throws IOException {
|
|
|
|
+ Workbook wb = new XSSFWorkbook();
|
|
|
|
+ Long userId = RequestUtils.getUserId(request);
|
|
|
|
+ createProjectDefectSheet(wb, userId, projectCode);
|
|
|
|
+ CrowdTestProject project = crowdProjectService.findByProjectCode(projectCode);
|
|
|
|
+ response.setHeader("Content-Disposition", String.format("attachment;filename=%s.xlsx",
|
|
|
|
+ URLEncoder.encode(project.getName(), "utf-8")));
|
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
|
+ OutputStream os = response.getOutputStream();
|
|
|
|
+ wb.write(os);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void createTaskDefectSheet (Workbook wb, Long userId, String taskCode) {
|
|
|
|
+ List<MixDefectInfoVO> mixDefectInfoVOs = mixDefectService.findAllByTaskCode(userId, taskCode);
|
|
|
|
+ createSheet(wb, userId, mixDefectInfoVOs);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void createProjectDefectSheet (Workbook wb, Long userId, String projectCode) {
|
|
|
|
+ List<MixDefectInfoVO> mixDefectInfoVOs = mixDefectService.findAllByProjectCode(userId, projectCode);
|
|
|
|
+ createSheet(wb, userId, mixDefectInfoVOs);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void createSheet(Workbook wb, Long userId, List<MixDefectInfoVO> mixDefectInfoVOs) {
|
|
|
|
+ Sheet sheet = wb.createSheet("缺陷记录");
|
|
|
|
+ int i = 0;
|
|
|
|
+ Row row = sheet.createRow(i++);
|
|
|
|
+ row.setHeightInPoints(row.getHeightInPoints() * (short)2);
|
|
|
|
+ CellStyle baseStyle = wb.createCellStyle();
|
|
|
|
+ baseStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ baseStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ baseStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
|
+ baseStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
|
+ baseStyle.setBorderRight(BorderStyle.THIN);
|
|
|
|
+ baseStyle.setBorderTop(BorderStyle.THIN);
|
|
|
|
+ baseStyle.setWrapText(true);
|
|
|
|
+
|
|
|
|
+ Font headerFont = wb.createFont();
|
|
|
|
+ headerFont.setFontHeightInPoints((short)10);
|
|
|
|
+ headerFont.setFontName("宋体");
|
|
|
|
+ headerFont.setBold(true);
|
|
|
|
+
|
|
|
|
+ Font contentFont = wb.createFont();
|
|
|
|
+ contentFont.setFontHeightInPoints((short)10);
|
|
|
|
+ contentFont.setFontName("宋体");
|
|
|
|
+
|
|
|
|
+ CellStyle headerStyle = wb.createCellStyle();
|
|
|
|
+ headerStyle.cloneStyleFrom(baseStyle);
|
|
|
|
+ headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ headerStyle.setFont(headerFont);
|
|
|
|
+
|
|
|
|
+ Cell cell0 = row.createCell(0);
|
|
|
|
+ Cell cell1 = row.createCell(1);
|
|
|
|
+ Cell cell2 = row.createCell(2);
|
|
|
|
+ Cell cell3 = row.createCell(3);
|
|
|
|
+ Cell cell4 = row.createCell(4);
|
|
|
|
+ Cell cell5 = row.createCell(5);
|
|
|
|
+ Cell cell6 = row.createCell(6);
|
|
|
|
+ Cell cell7 = row.createCell(7);
|
|
|
|
+ Cell cell8 = row.createCell(8);
|
|
|
|
+ Cell cell9 = row.createCell(9);
|
|
|
|
+ Cell cell10 = row.createCell(10);
|
|
|
|
+ Cell cell11 = row.createCell(11);
|
|
|
|
+ Cell cell12 = row.createCell(12);
|
|
|
|
+ Cell cell13 = row.createCell(13);
|
|
|
|
+ Cell cell14 = row.createCell(14);
|
|
|
|
+ Cell cell15 = row.createCell(15);
|
|
|
|
+
|
|
|
|
+ cell0.setCellStyle(headerStyle);
|
|
|
|
+ cell0.setCellValue("缺陷编号");
|
|
|
|
+
|
|
|
|
+ cell1.setCellStyle(headerStyle);
|
|
|
|
+ cell1.setCellValue("用例编号");
|
|
|
|
+
|
|
|
|
+ cell2.setCellStyle(headerStyle);
|
|
|
|
+ cell2.setCellValue("缺陷描述");
|
|
|
|
+ sheet.setColumnWidth(2, sheet.getColumnWidth(2) * 3);
|
|
|
|
+
|
|
|
|
+ cell3.setCellStyle(headerStyle);
|
|
|
|
+ cell3.setCellValue("严重程度");
|
|
|
|
+
|
|
|
|
+ cell4.setCellStyle(headerStyle);
|
|
|
|
+ cell4.setCellValue("优先级");
|
|
|
|
+
|
|
|
|
+ cell5.setCellStyle(headerStyle);
|
|
|
|
+ cell5.setCellValue("问题类型");
|
|
|
|
+
|
|
|
|
+ cell6.setCellStyle(headerStyle);
|
|
|
|
+ cell6.setCellValue("前置条件");
|
|
|
|
+ sheet.setColumnWidth(6, sheet.getColumnWidth(6) * 3);
|
|
|
|
+
|
|
|
|
+ cell7.setCellStyle(headerStyle);
|
|
|
|
+ cell7.setCellValue("环境配置");
|
|
|
|
+ sheet.setColumnWidth(7, sheet.getColumnWidth(7) * 3);
|
|
|
|
+
|
|
|
|
+ cell8.setCellStyle(headerStyle);
|
|
|
|
+ cell8.setCellValue("操作步骤");
|
|
|
|
+ sheet.setColumnWidth(8, sheet.getColumnWidth(8) * 3);
|
|
|
|
+
|
|
|
|
+ cell9.setCellStyle(headerStyle);
|
|
|
|
+ cell9.setCellValue("输入数据");
|
|
|
|
+ sheet.setColumnWidth(9, sheet.getColumnWidth(9) * 3);
|
|
|
|
+
|
|
|
|
+ cell10.setCellStyle(headerStyle);
|
|
|
|
+ cell10.setCellValue("预期结果");
|
|
|
|
+ sheet.setColumnWidth(10, sheet.getColumnWidth(10) * 3);
|
|
|
|
+
|
|
|
|
+ cell11.setCellStyle(headerStyle);
|
|
|
|
+ cell11.setCellValue("实际结果");
|
|
|
|
+ sheet.setColumnWidth(11, sheet.getColumnWidth(11) * 3);
|
|
|
|
+
|
|
|
|
+ cell12.setCellStyle(headerStyle);
|
|
|
|
+ cell12.setCellValue("其他说明");
|
|
|
|
+ sheet.setColumnWidth(12, sheet.getColumnWidth(12) * 3);
|
|
|
|
+
|
|
|
|
+ cell13.setCellStyle(headerStyle);
|
|
|
|
+ cell13.setCellValue("提交人员");
|
|
|
|
+ sheet.setColumnWidth(13, sheet.getColumnWidth(13) * 2);
|
|
|
|
+
|
|
|
|
+ cell14.setCellStyle(headerStyle);
|
|
|
|
+ cell14.setCellValue("提交时间");
|
|
|
|
+ sheet.setColumnWidth(14, sheet.getColumnWidth(14) * 2);
|
|
|
|
+
|
|
|
|
+ cell15.setCellStyle(headerStyle);
|
|
|
|
+ cell15.setCellValue("附件");
|
|
|
|
+ sheet.setColumnWidth(15, sheet.getColumnWidth(15) * 4);
|
|
|
|
+
|
|
|
|
+ CellStyle contentStyle = wb.createCellStyle();
|
|
|
|
+ contentStyle.cloneStyleFrom(baseStyle);
|
|
|
|
+ contentStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ contentStyle.setFont(contentFont);
|
|
|
|
+ Map<Long, String> userIdNameMap = new HashMap();
|
|
|
|
+
|
|
|
|
+ for(MixDefectInfoVO mixDefectInfoVO: mixDefectInfoVOs) {
|
|
|
|
+ Defect defect = mixDefectInfoVO.getMasterDefect();
|
|
|
|
+ if (!userIdNameMap.containsKey(defect.getCommiterId())) {
|
|
|
|
+ String realname = userService.getById(defect.getCommiterId()).getName();
|
|
|
|
+ userIdNameMap.put(defect.getCommiterId(), realname);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ row = sheet.createRow(i++);
|
|
|
|
+ cell0 = row.createCell(0);
|
|
|
|
+ cell0.setCellStyle(contentStyle);
|
|
|
|
+ cell1 = row.createCell(1);
|
|
|
|
+ cell1.setCellStyle(contentStyle);
|
|
|
|
+ cell2 = row.createCell(2);
|
|
|
|
+ cell2.setCellStyle(contentStyle);
|
|
|
|
+ cell3 = row.createCell(3);
|
|
|
|
+ CellStyle cellStyle = wb.createCellStyle();
|
|
|
|
+ cellStyle.cloneStyleFrom(contentStyle);
|
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.LEFT);
|
|
|
|
+ cell3.setCellStyle(cellStyle);
|
|
|
|
+ cell4 = row.createCell(4);
|
|
|
|
+ cell4.setCellStyle(cellStyle);
|
|
|
|
+ cell5 = row.createCell(5);
|
|
|
|
+ cell5.setCellStyle(cellStyle);
|
|
|
|
+ cell6 = row.createCell(6);
|
|
|
|
+ cell6.setCellStyle(cellStyle);
|
|
|
|
+ cell7 = row.createCell(7);
|
|
|
|
+ cell7.setCellStyle(contentStyle);
|
|
|
|
+ cell8 = row.createCell(8);
|
|
|
|
+ cell8.setCellStyle(contentStyle);
|
|
|
|
+ cell9 = row.createCell(9);
|
|
|
|
+ cell9.setCellStyle(contentStyle);
|
|
|
|
+ cell10 = row.createCell(10);
|
|
|
|
+ cell10.setCellStyle(contentStyle);
|
|
|
|
+ cell11 = row.createCell(11);
|
|
|
|
+ cell11.setCellStyle(contentStyle);
|
|
|
|
+ cell12 = row.createCell(12);
|
|
|
|
+ cell12.setCellStyle(contentStyle);
|
|
|
|
+ cell13 = row.createCell(13);
|
|
|
|
+ cell13.setCellStyle(contentStyle);
|
|
|
|
+ cell14 = row.createCell(14);
|
|
|
|
+ cell14.setCellStyle(contentStyle);
|
|
|
|
+ cell15 = row.createCell(15);
|
|
|
|
+ cell15.setCellStyle(contentStyle);
|
|
|
|
+
|
|
|
|
+ cell0.setCellValue(defect.getCode());
|
|
|
|
+ cell1.setCellValue(defect.getTestCaseCode());
|
|
|
|
+ cell2.setCellValue(defect.getDescr());
|
|
|
|
+ cell3.setCellValue(defect.getSeriousness().getName());
|
|
|
|
+ cell4.setCellValue(defect.getPriority().getName());
|
|
|
|
+ cell5.setCellValue(defect.getDefectType().getName());
|
|
|
|
+ cell6.setCellValue(defect.getPreconditions() == null ? "" : defect.getPreconditions());
|
|
|
|
+ cell7.setCellValue(defect.getEnvConfig() == null ? "" : defect.getEnvConfig());
|
|
|
|
+ cell8.setCellValue(defect.getOpeSteps() == null ? "" : defect.getOpeSteps());
|
|
|
|
+ cell9.setCellValue(defect.getInputDatas() == null ? "" : defect.getInputDatas());
|
|
|
|
+ cell10.setCellValue(defect.getExpectedResult() == null ? "" : defect.getExpectedResult());
|
|
|
|
+ cell11.setCellValue(defect.getTestResult());
|
|
|
|
+ cell12.setCellValue(defect.getOthers() == null ? "" : defect.getOthers());
|
|
|
|
+ cell13.setCellValue(userIdNameMap.get(defect.getCommiterId()));
|
|
|
|
+ cell14.setCellValue(DateUtils.formatDate(new Date(defect.getCommitTime().getTime()), "yyyy-MM-dd"));
|
|
|
|
+ List<String> files = new ArrayList();
|
|
|
|
+ files.addAll(defect.getFiles());
|
|
|
|
+ files.addAll(defect.getScreenshots());
|
|
|
|
+ cell15.setCellValue(Strings.join(files, '、'));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|