diff --git a/src/main/java/net/educoder/ecsonar/dao/IssuesDao.java b/src/main/java/net/educoder/ecsonar/dao/IssuesDao.java index 37e8c1a..1073116 100644 --- a/src/main/java/net/educoder/ecsonar/dao/IssuesDao.java +++ b/src/main/java/net/educoder/ecsonar/dao/IssuesDao.java @@ -40,7 +40,7 @@ public interface IssuesDao { * @param issueType * @return */ - DegreeDTO queryDegree(String projectUuid, Integer issueType); + DegreeDTO queryDegree(String projectUuid, Integer issueType, Integer metricId); /** diff --git a/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java b/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java index c7d9da1..ccb1482 100644 --- a/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java +++ b/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java @@ -43,12 +43,12 @@ public interface ProjectDao { "(SELECT COALESCE(count(*),0) critical_bugs FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=2 and severity='CRITICAL')," + "(SELECT COALESCE(count(*),0) major_bugs FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=2 and severity='MAJOR')," + "(SELECT COALESCE(count(*),0) minor_bugs FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=2 and severity='MINOR')," + - "(select text_value bugs from project_measures where component_uuid = #{projectUuid} and metric_id = 80 order by id desc limit 1)," + + "(select text_value bugs from project_measures where component_uuid = #{projectUuid} and metric_id = 89 order by id desc limit 1)," + "(SELECT COALESCE(count(*),0) block_violations FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=3 and severity='BLOCKER'), " + "(SELECT COALESCE(count(*),0) critical_violations FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=3 and severity='CRITICAL')," + "(SELECT COALESCE(count(*),0) major_violations FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=3 and severity='MAJOR')," + "(SELECT COALESCE(count(*),0) minor_violations FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=3 and severity='MINOR')," + - "(select text_value violations from project_measures where component_uuid = #{projectUuid} and metric_id = 80 order by id desc limit 1)") + "(select text_value violations from project_measures where component_uuid = #{projectUuid} and metric_id = 93 order by id desc limit 1)") Metrics selectMetricsByProjectUuid(String projectUuid); diff --git a/src/main/java/net/educoder/ecsonar/enums/AnalyseTypeEnum.java b/src/main/java/net/educoder/ecsonar/enums/AnalyseTypeEnum.java index 54c7af4..730cdf8 100644 --- a/src/main/java/net/educoder/ecsonar/enums/AnalyseTypeEnum.java +++ b/src/main/java/net/educoder/ecsonar/enums/AnalyseTypeEnum.java @@ -8,15 +8,17 @@ package net.educoder.ecsonar.enums; */ public enum AnalyseTypeEnum { - CodeSmell(1), - BUG(2), - Vulnerability(3); + CodeSmell(1,80), + BUG(2, 89), + Vulnerability(3,93); private Integer type; + private Integer metricId; - AnalyseTypeEnum(Integer type) { + AnalyseTypeEnum(Integer type, Integer metricId) { this.type = type; + this.metricId = metricId; } @@ -24,6 +26,10 @@ public enum AnalyseTypeEnum { return type; } + public Integer getMetricId() { + return metricId; + } + public static AnalyseTypeEnum getAnalyseTypeEnum(Integer type) { for (AnalyseTypeEnum analyseType : values()) { if (analyseType.type.equals(type)) { diff --git a/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java b/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java index 2a59d75..b15236a 100644 --- a/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java +++ b/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java @@ -240,9 +240,9 @@ public class QualityInspectService { throw new BusinessException(-1, String.format("找不到分析记录homeworkId:%s,studentNo:%s", analyseDetailVO.getHomeworkId(), analyseDetailVO.getStudentNo())); } - DegreeDTO codeSmall = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.CodeSmell.getType()); - DegreeDTO bug = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.BUG.getType()); - DegreeDTO vulnerability = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.Vulnerability.getType()); + 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); @@ -317,17 +317,17 @@ public class QualityInspectService { problemAnalysisDTO.setTitle(rule.getName()); problemAnalysisDTO.setExample(example); - problemAnalysisDTO.setLanguage(rule.getLanguage()); + problemAnalysisDTO.setLanguage("py".equalsIgnoreCase(rule.getLanguage()) ? "python" : rule.getLanguage()); problemAnalysisDTO.setConstantIssue(rule.getDefRemediationBaseEffort()); if (StringUtils.isBlank(rule.getTags())) { problemAnalysisDTO.setTags(new ArrayList<>()); - }else{ + } else { problemAnalysisDTO.setTags(Arrays.asList(rule.getTags().split(","))); } problemAnalysisDTO.setCreateTime(DateUtil.formatDateTime(new Date(rule.getCreateTime()))); - }else{ + } else { problemAnalysisDTO.setTitle(""); problemAnalysisDTO.setExample(""); problemAnalysisDTO.setLanguage(""); diff --git a/src/main/resources/mapper/IssuesMapper.xml b/src/main/resources/mapper/IssuesMapper.xml index 5ae3b15..1725704 100644 --- a/src/main/resources/mapper/IssuesMapper.xml +++ b/src/main/resources/mapper/IssuesMapper.xml @@ -42,12 +42,12 @@