From cd638b475f3f7203a19ba707054211a17d02636b Mon Sep 17 00:00:00 2001 From: youys <1272586223@qq.com> Date: Tue, 5 Sep 2023 11:20:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(GraduationProject)=20=E6=AF=95=E8=AE=BE?= =?UTF-8?q?=E8=B4=A8=E9=87=8F=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GraduationProjectController.java | 64 +++++++++- .../GraduationProjectTaskInfoDetailDao.java | 2 +- .../model/api/QualityInspectResultData.java | 13 ++ .../ecsonar/model/vo/CodeDetailVO.java | 8 ++ .../GraduationProjectAnalyseDetailListVO.java | 33 +++++ ...GraduationQualityInspectResultQueryVO.java | 6 +- ...raduationProjectQualityInspectService.java | 118 +++++++++++++++--- 7 files changed, 214 insertions(+), 30 deletions(-) create mode 100644 src/main/java/net/educoder/ecsonar/model/vo/GraduationProjectAnalyseDetailListVO.java diff --git a/src/main/java/net/educoder/ecsonar/controller/GraduationProjectController.java b/src/main/java/net/educoder/ecsonar/controller/GraduationProjectController.java index 89e2822..500fd79 100644 --- a/src/main/java/net/educoder/ecsonar/controller/GraduationProjectController.java +++ b/src/main/java/net/educoder/ecsonar/controller/GraduationProjectController.java @@ -4,13 +4,18 @@ import net.educoder.ecsonar.model.RollPage; import net.educoder.ecsonar.model.api.QualityInspect; import net.educoder.ecsonar.model.api.QualityInspectIsCompleted; import net.educoder.ecsonar.model.api.QualityInspectResultData; -import net.educoder.ecsonar.model.vo.GraduationProjectQualityInspectVO; -import net.educoder.ecsonar.model.vo.GraduationQualityInspectResultQueryVO; +import net.educoder.ecsonar.model.dto.AnalyseDetailDTO; +import net.educoder.ecsonar.model.dto.AnalyseDetailListDTO; +import net.educoder.ecsonar.model.dto.CodeDetailDTO; +import net.educoder.ecsonar.model.dto.ProblemAnalysisDTO; +import net.educoder.ecsonar.model.vo.*; import net.educoder.ecsonar.services.GraduationProjectQualityInspectService; +import net.educoder.ecsonar.services.QualityInspectService; import net.educoder.ecsonar.utils.ResponseResult; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.validation.Valid; import java.util.List; /** @@ -27,14 +32,18 @@ public class GraduationProjectController { @Resource private GraduationProjectQualityInspectService graduationProjectQualityInspect; + @Resource + private QualityInspectService qualityInspectService; + /** * 质量检测 + * * @param qualityInspectVOList * @return */ @PostMapping("/qualityInspect") - public ResponseResult graduationQualityInspect(@RequestBody List qualityInspectVOList){ + public ResponseResult graduationQualityInspect(@RequestBody List qualityInspectVOList) { QualityInspect qualityInspect = graduationProjectQualityInspect.graduationProjectQualityInspect(qualityInspectVOList); return ResponseResult.success(qualityInspect); } @@ -45,8 +54,7 @@ public class GraduationProjectController { * @param graduationQualityInspectResultQueryVO * @return */ - @RequestMapping(value = "qualityInspectResultQuery", method = RequestMethod.GET) - @ResponseBody + @PostMapping(value = "qualityInspectResultQuery") public ResponseResult graduationQualityInspectResultQuery(@RequestBody GraduationQualityInspectResultQueryVO graduationQualityInspectResultQueryVO) { QualityInspectIsCompleted isCompleted = graduationProjectQualityInspect.qualityInspectIsCompleted(graduationQualityInspectResultQueryVO.getTaskId()); if (isCompleted.getCompleted() != 1) { @@ -58,5 +66,51 @@ public class GraduationProjectController { } + /** + * 分析详情 + * + * @return + */ + @GetMapping("/analyseDetail") + public ResponseResult analyseDetail(@RequestParam("taskDetailId") String taskDetailId) { + AnalyseDetailDTO analyseDetailDTO = graduationProjectQualityInspect.getAnalyseDetail(taskDetailId); + return ResponseResult.success(analyseDetailDTO); + } + + /** + * 分析详情列表 + * + * @return + */ + @GetMapping("/analyseDetailList") + public ResponseResult analyseDetailList(@Valid GraduationProjectAnalyseDetailListVO analyseDetailListVO) { + RollPage rollPage = graduationProjectQualityInspect.getAnalyseDetailList(analyseDetailListVO); + return ResponseResult.success(rollPage); + } + + + /** + * 问题分析 + * + * @return + */ + @GetMapping("/problemAnalysis") + public ResponseResult problemAnalysis(@RequestParam Integer ruleId) { + ProblemAnalysisDTO problemAnalysis = qualityInspectService.getProblemAnalysis(ruleId); + return ResponseResult.success(problemAnalysis); + } + + + /** + * 代码详情 + * + * @return + */ + @GetMapping("/codeDetail") + public ResponseResult codeDetail(@Valid CodeDetailVO codeDetailVO) { + CodeDetailDTO codeDetail = qualityInspectService.getCodeDetail(codeDetailVO); + return ResponseResult.success(codeDetail); + } + } diff --git a/src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDetailDao.java b/src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDetailDao.java index 47c0175..ce9589f 100644 --- a/src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDetailDao.java +++ b/src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDetailDao.java @@ -53,7 +53,7 @@ public interface GraduationProjectTaskInfoDetailDao { */ @Select("select id,task_id taskId,project_name projectName,language,student_id studentId,user_id " + "userId,name,git_url gitUrl,status,create_time createTime,update_time updateTime " + - "from task_info_detail where id=#{id}") + "from graduation_project_task_info_detail where id=#{id}") GraduationProjectTaskInfoDetail selectById(String id); /** diff --git a/src/main/java/net/educoder/ecsonar/model/api/QualityInspectResultData.java b/src/main/java/net/educoder/ecsonar/model/api/QualityInspectResultData.java index 8f1dd16..dada35b 100644 --- a/src/main/java/net/educoder/ecsonar/model/api/QualityInspectResultData.java +++ b/src/main/java/net/educoder/ecsonar/model/api/QualityInspectResultData.java @@ -62,6 +62,11 @@ public class QualityInspectResultData { */ private BigDecimal qualityScore; + /** + * 任务详情id + */ + private String taskDetailId; + public String getMentor() { return mentor; } @@ -149,4 +154,12 @@ public class QualityInspectResultData { public void setQualityScore(BigDecimal qualityScore) { this.qualityScore = qualityScore; } + + public String getTaskDetailId() { + return taskDetailId; + } + + public void setTaskDetailId(String taskDetailId) { + this.taskDetailId = taskDetailId; + } } diff --git a/src/main/java/net/educoder/ecsonar/model/vo/CodeDetailVO.java b/src/main/java/net/educoder/ecsonar/model/vo/CodeDetailVO.java index 7319900..c2fac70 100644 --- a/src/main/java/net/educoder/ecsonar/model/vo/CodeDetailVO.java +++ b/src/main/java/net/educoder/ecsonar/model/vo/CodeDetailVO.java @@ -2,6 +2,9 @@ package net.educoder.ecsonar.model.vo; import lombok.Data; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + /** * @Author: youys * @Date: 2022/9/27 @@ -11,7 +14,12 @@ import lombok.Data; public class CodeDetailVO { + @NotBlank(message = "uuid不能为空") private String uuid; + + @NotNull(message = "ruleId不能为空") private Integer ruleId; + + @NotNull(message = "issueId不能为空") private Long issueId; } diff --git a/src/main/java/net/educoder/ecsonar/model/vo/GraduationProjectAnalyseDetailListVO.java b/src/main/java/net/educoder/ecsonar/model/vo/GraduationProjectAnalyseDetailListVO.java new file mode 100644 index 0000000..5c810fa --- /dev/null +++ b/src/main/java/net/educoder/ecsonar/model/vo/GraduationProjectAnalyseDetailListVO.java @@ -0,0 +1,33 @@ +package net.educoder.ecsonar.model.vo; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * @Author: youys + * @Date: 2022/12/20 + * @Description: 分析详情列表入参 + */ +@Data +public class GraduationProjectAnalyseDetailListVO extends PageVO { + + /** + * 类型 + * 1 代码规范 + * 2 bug + * 3 漏洞 + */ + private Integer type; + + /** + * 严重程度 + * all 全部 + */ + private Integer degree; + + + @NotBlank(message = "作业id不能为空") + private String taskDetailId; + +} diff --git a/src/main/java/net/educoder/ecsonar/model/vo/GraduationQualityInspectResultQueryVO.java b/src/main/java/net/educoder/ecsonar/model/vo/GraduationQualityInspectResultQueryVO.java index af9a305..c309b7b 100644 --- a/src/main/java/net/educoder/ecsonar/model/vo/GraduationQualityInspectResultQueryVO.java +++ b/src/main/java/net/educoder/ecsonar/model/vo/GraduationQualityInspectResultQueryVO.java @@ -13,13 +13,9 @@ import javax.validation.constraints.NotBlank; */ @Data -public class GraduationQualityInspectResultQueryVO { +public class GraduationQualityInspectResultQueryVO extends PageVO{ - private Integer pageSize; - @Min(value = 1, message = "起始页最少是1") - private Integer pageNumber; - @NotBlank(message = "任务id不能为空") private String taskId; diff --git a/src/main/java/net/educoder/ecsonar/services/GraduationProjectQualityInspectService.java b/src/main/java/net/educoder/ecsonar/services/GraduationProjectQualityInspectService.java index 247bcaf..d2217f4 100644 --- a/src/main/java/net/educoder/ecsonar/services/GraduationProjectQualityInspectService.java +++ b/src/main/java/net/educoder/ecsonar/services/GraduationProjectQualityInspectService.java @@ -1,7 +1,10 @@ package net.educoder.ecsonar.services; import cn.hutool.core.util.RandomUtil; +import com.google.protobuf.InvalidProtocolBufferException; import net.educoder.ecsonar.dao.*; +import net.educoder.ecsonar.enums.AnalyseTypeEnum; +import net.educoder.ecsonar.enums.DegreeEnum; import net.educoder.ecsonar.exception.BusinessException; import net.educoder.ecsonar.model.*; import net.educoder.ecsonar.model.api.Quality; @@ -10,6 +13,7 @@ import net.educoder.ecsonar.model.api.QualityInspectIsCompleted; import net.educoder.ecsonar.model.api.QualityInspectResultData; import net.educoder.ecsonar.model.dto.*; import net.educoder.ecsonar.model.vo.*; +import net.educoder.ecsonar.protobuf.DbIssues; import net.educoder.ecsonar.task.GraduationProjectQualityInspectRunnable; import net.educoder.ecsonar.utils.IdUtils; import net.educoder.ecsonar.utils.SystemUtil; @@ -57,9 +61,6 @@ public class GraduationProjectQualityInspectService { @Autowired private ProjectDao projectDao; - @Autowired - private FileSourceDao fileSourceDao; - @Autowired @Qualifier("sonarScannerPool") @@ -114,13 +115,13 @@ public class GraduationProjectQualityInspectService { public RollPage qualityInspectResultQuery(GraduationQualityInspectResultQueryVO queryVO) { int pageSize = queryVO.getPageSize(); - int pageNum = queryVO.getPageNumber(); + int pageNum = queryVO.getCurrentPage(); RollPage rollPage = new RollPage<>(); rollPage.setCurrentPage(pageNum); rollPage.setPageSize(pageSize); - int offset = (queryVO.getPageNumber() - 1) * queryVO.getPageSize(); + int offset = (pageNum - 1) * queryVO.getPageSize(); Integer totalCount = graduationProjectTaskInfoDetailDao. selectGraduationProjectTaskInfoDetailPageCount(queryVO.getTaskId(), pageSize, offset); rollPage.setRecordSum(totalCount); @@ -141,6 +142,7 @@ public class GraduationProjectQualityInspectService { resultData.setName(taskInfoDetail.getName()); resultData.setStudentId(taskInfoDetail.getStudentId()); resultData.setUserId(taskInfoDetail.getUserId()); + resultData.setTaskDetailId(taskInfoDetail.getId()); Metrics metrics = reportService.getMetrics(taskInfoDetail.getProjectName()); @@ -259,11 +261,30 @@ public class GraduationProjectQualityInspectService { /** * 分析详情 * - * @param analyseDetailVO + * @param taskDetailId * @return */ - public AnalyseDetailDTO getAnalyseDetail(AnalyseDetailVO analyseDetailVO) { - return null; + public AnalyseDetailDTO getAnalyseDetail(String taskDetailId) { + // 作业id+学号 + GraduationProjectTaskInfoDetail graduationProjectTaskInfoDetail = graduationProjectTaskInfoDetailDao.selectById(taskDetailId); + if (graduationProjectTaskInfoDetail == null) { + throw new BusinessException(-1, "找不到分析记录"); + } + + Project project = projectDao.findByName(graduationProjectTaskInfoDetail.getProjectName()); + if (project == null) { + throw new BusinessException(-1, String.format("找不到分析记录detailId:%s", taskDetailId)); + } + + DegreeDTO codeSmall = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.CodeSmell.getType(), AnalyseTypeEnum.CodeSmell.getMetricId()); + DegreeDTO bug = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.BUG.getType(), AnalyseTypeEnum.BUG.getMetricId()); + DegreeDTO vulnerability = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.Vulnerability.getType(), AnalyseTypeEnum.Vulnerability.getMetricId()); + + AnalyseDetailDTO analyseDetail = new AnalyseDetailDTO(); + analyseDetail.setBug(bug == null ? new DegreeDTO() : bug); + analyseDetail.setVulnerability(vulnerability == null ? new DegreeDTO() : vulnerability); + analyseDetail.setCodeSmall(codeSmall == null ? new DegreeDTO() : codeSmall); + return analyseDetail; } @@ -273,22 +294,81 @@ public class GraduationProjectQualityInspectService { * @param analyseDetailListVO * @return */ - public RollPage getAnalyseDetailList(AnalyseDetailListVO analyseDetailListVO) { - return null; - } + public RollPage getAnalyseDetailList(GraduationProjectAnalyseDetailListVO analyseDetailListVO) { + RollPage rollPage = new RollPage<>(); - /** - * 代码详情 - * - * @param codeDetailVO - * @return - */ - public CodeDetailDTO getCodeDetail(CodeDetailVO codeDetailVO) { - return null; + if (analyseDetailListVO.getCurrentPage() <= 0) { + analyseDetailListVO.setCurrentPage(1); + } + + if (analyseDetailListVO.getPageSize() >= 10000) { + analyseDetailListVO.setPageSize(10000); + } + + rollPage.setCurrentPage(analyseDetailListVO.getCurrentPage()); + rollPage.setPageSize(analyseDetailListVO.getPageSize()); + + // 作业id+学号 + GraduationProjectTaskInfoDetail graduationProjectTaskInfoDetail = graduationProjectTaskInfoDetailDao.selectById(analyseDetailListVO.getTaskDetailId()); + if (graduationProjectTaskInfoDetail == null) { + throw new BusinessException(-1, String.format("找不到分析记录detailId:%s", analyseDetailListVO.getTaskDetailId())); + } + + Project project = projectDao.findByName(graduationProjectTaskInfoDetail.getProjectName()); + if (project == null) { + throw new BusinessException(-1, String.format("找不到分析记录detailId:%s", analyseDetailListVO.getTaskDetailId())); + } + + // 分析类型 + AnalyseTypeEnum analyseTypeEnum = AnalyseTypeEnum.getAnalyseTypeEnum(analyseDetailListVO.getType()); + + // 严重程度 + DegreeEnum degreeEnum = DegreeEnum.getDegreeEnum(analyseDetailListVO.getDegree()); + String severity = null; + if (degreeEnum != DegreeEnum.All) { + severity = degreeEnum.getValue(); + } + + Integer pageIssuesCount = issuesDao.getPageIssuesCount(project.getProject_uuid(), analyseTypeEnum.getType(), severity); + rollPage.setRecordSum(pageIssuesCount); + if (pageIssuesCount > 0) { + int start = (analyseDetailListVO.getCurrentPage() - 1) * analyseDetailListVO.getPageSize(); + List pageIssues = issuesDao.getPageIssues(project.getProject_uuid(), analyseTypeEnum.getType(), severity, start, analyseDetailListVO.getPageSize()); + processPageIssues(pageIssues, rollPage); + } else { + rollPage.setRecordList(new ArrayList(0)); + } + + return rollPage; } private void processPageIssues(List pageIssues, RollPage rollPage) { + List analyseDetailLists = new ArrayList<>(pageIssues.size()); + + for (Issues pageIssue : pageIssues) { + AnalyseDetailListDTO detailListDTO = new AnalyseDetailListDTO(); + analyseDetailLists.add(detailListDTO); + + detailListDTO.setName(pageIssue.getName()); + detailListDTO.setDescription(pageIssue.getMessage()); + + detailListDTO.setIssueId(pageIssue.getId()); + detailListDTO.setUuid(pageIssue.getUuid()); + detailListDTO.setRuleId(pageIssue.getRuleId()); + detailListDTO.setFilePath(pageIssue.getPath()); + detailListDTO.setLanguage(pageIssue.getLanguage()); + detailListDTO.setLevel(DegreeEnum.getDegreeEnumByValue(pageIssue.getSeverity()).getDesc()); + try { + DbIssues.Locations locations = DbIssues.Locations.parseFrom(pageIssue.getLocations()); + detailListDTO.setRowNumber(locations.getTextRange().getStartLine()); + } catch (InvalidProtocolBufferException e) { + detailListDTO.setRowNumber(0); + LOGGER.error("Fail to read ISSUES.LOCATIONS [KEE=%s]", e); + } + } + + rollPage.setRecordList(analyseDetailLists); }