diff --git a/src/main/java/net/educoder/ecsonar/dao/IssuesDao.java b/src/main/java/net/educoder/ecsonar/dao/IssuesDao.java index fcd6447..83ec773 100644 --- a/src/main/java/net/educoder/ecsonar/dao/IssuesDao.java +++ b/src/main/java/net/educoder/ecsonar/dao/IssuesDao.java @@ -39,10 +39,10 @@ public interface IssuesDao { * 查询不同程度的漏洞、缺陷、代码规范数量 * @param projectUuid * @param issueType - * @param metricUUid + * @param metricName * @return */ - DegreeDTO queryDegree(String projectUuid, Integer issueType, String metricUUid); + DegreeDTO queryDegree(String projectUuid, Integer issueType, String metricName); /** diff --git a/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java b/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java index e63251a..74ccac1 100644 --- a/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java +++ b/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java @@ -22,7 +22,7 @@ public interface ProjectDao { * @param uuid * @return */ - @Select("select COALESCE(value,0) from project_measures where component_uuid = #{uuid} and metric_uuid = 'AYeNSwarTEppvP7II92z' limit 1") + @Select("select COALESCE(value,0) from project_measures where component_uuid = #{uuid} and metric_uuid = select uuid from metrics m where name='file_complexity' limit 1") Float getComplexity(@Param("uuid") String uuid); /** @@ -30,17 +30,17 @@ public interface ProjectDao { * @param uuid * @return */ - @Select("select COALESCE(value,0) from project_measures where component_uuid = #{uuid} and metric_uuid = 'AYeNSwakTEppvP7II92h' limit 1") + @Select("select COALESCE(value,0) from project_measures where component_uuid = #{uuid} and metric_uuid=(select uuid from metrics m where name='lines') limit 1") Integer getLines(@Param("uuid") String uuid); /** * 等级 * @param uuid - * @param metricUUid + * @param metricName * @return */ - @Select("select text_value from project_measures where component_uuid = #{uuid} and metric_uuid = #{metric_uuid} limit 1") - String getLevel(@Param("uuid") String uuid, @Param("metric_uuid") String metricUUid); + @Select("select text_value from project_measures where component_uuid = #{uuid} and metric_uuid=(select uuid from metrics m where name=#{metricName}}) limit 1") + String getLevel(@Param("uuid") String uuid, @Param("metricName") String metricName); @Select("SELECT count(*) FROM issues where project_uuid=#{uuid} and " + "status='OPEN' and issue_type=#{issue_type} and severity=#{severity}") @@ -56,23 +56,23 @@ public interface ProjectDao { * @return */ @Select("select " + - "(select COALESCE(value,0) complexity from project_measures where component_uuid = #{projectUuid} and metric_uuid = 'AYeNSwarTEppvP7II92z' limit 1)," + - "(select COALESCE(value,0) lines from project_measures where component_uuid = #{projectUuid} and metric_uuid = 'AYeNSwakTEppvP7II92h' limit 1)," + + "(select COALESCE(value,0) complexity from project_measures where component_uuid = #{projectUuid} and metric_uuid = (select uuid from metrics m where name='file_complexity') limit 1)," + + "(select COALESCE(value,0) lines from project_measures where component_uuid = #{projectUuid} and metric_uuid = (select uuid from metrics m where name='lines') limit 1)," + "(SELECT COALESCE(count(*),0) block_code_smells FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=1 and severity='BLOCKER'), " + "(SELECT COALESCE(count(*),0) critical_code_smells FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=1 and severity='CRITICAL')," + "(SELECT COALESCE(count(*),0) major_code_smells FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=1 and severity='MAJOR')," + "(SELECT COALESCE(count(*),0) minor_code_smells FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=1 and severity='MINOR')," + - "(select text_value code_smells from project_measures where component_uuid = #{projectUuid} and metric_uuid = 'AYeNSwaxTEppvP7II93y' limit 1)," + + "(select text_value code_smells from project_measures where component_uuid = #{projectUuid} and metric_uuid = (select uuid from metrics m where name='sqale_rating') limit 1)," + "(SELECT COALESCE(count(*),0) block_bugs FROM issues where project_uuid=#{projectUuid} and status='OPEN' and issue_type=2 and severity='BLOCKER'), " + "(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_uuid = 'AYeNSwayTEppvP7II94B' limit 1)," + + "(select text_value bugs from project_measures where component_uuid = #{projectUuid} and metric_uuid = (select uuid from metrics m where name='security_review_rating') 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_uuid = 'AYeNSwayTEppvP7II93_' limit 1)") + "(select text_value violations from project_measures where component_uuid = #{projectUuid} and metric_uuid = (select uuid from metrics m where name='security_rating') limit 1)") Metrics selectMetricsByProjectUuid(String projectUuid); @@ -81,7 +81,7 @@ public interface ProjectDao { @Select("select (select count(1) from issues where project_uuid=#{projectUuid} and issue_type=1) codeSmell," + "(select count(1) from issues where project_uuid=#{projectUuid} and issue_type=2) bugs," + "(select count(1) from issues where project_uuid=#{projectUuid} and issue_type=3) vulnerability," + - "(select value from project_measures pm where component_uuid=#{projectUuid} and metric_id=3) codeLines") + "(select value from project_measures pm where component_uuid=#{projectUuid} and metric_uuid=(select uuid from metrics m where name='ncloc')) codeLines") IssuesMetrics selectIssuesMetrics(String projectUuid); /** @@ -90,4 +90,7 @@ public interface ProjectDao { * @return */ Rule findRuleById(@Param("uuid") String uuid); + +// @Select("select uuid from metrics m where name=#{name}}") +// String findMetricUUIDByName(@Param("name") String name); } diff --git a/src/main/java/net/educoder/ecsonar/enums/AnalyseTypeEnum.java b/src/main/java/net/educoder/ecsonar/enums/AnalyseTypeEnum.java index d612e43..9e014cd 100644 --- a/src/main/java/net/educoder/ecsonar/enums/AnalyseTypeEnum.java +++ b/src/main/java/net/educoder/ecsonar/enums/AnalyseTypeEnum.java @@ -8,20 +8,20 @@ package net.educoder.ecsonar.enums; */ public enum AnalyseTypeEnum { - CodeSmell(1,80, "AYeNSwaxTEppvP7II93y"), - BUG(2, 89, "AYeNSwayTEppvP7II94B"), - Vulnerability(3,93, "AYeNSwayTEppvP7II93_"); + CodeSmell(1,80, "sqale_rating"), + BUG(2, 89, "security_review_rating"), + Vulnerability(3,93, "security_rating"); private Integer type; private Integer metricId; - private String metricUUId; + private String metricName; - AnalyseTypeEnum(Integer type, Integer metricId, String metricUUId) { + AnalyseTypeEnum(Integer type, Integer metricId, String metricName) { this.type = type; this.metricId = metricId; - this.metricUUId = metricUUId; + this.metricName = metricName; } @@ -33,8 +33,8 @@ public enum AnalyseTypeEnum { return metricId; } - public String getMetricUUId() { - return metricUUId; + public String getMetricName() { + return metricName; } public static AnalyseTypeEnum getAnalyseTypeEnum(Integer type) { diff --git a/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java b/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java index 8c77bac..d030292 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.getUuid(), AnalyseTypeEnum.CodeSmell.getType(), AnalyseTypeEnum.CodeSmell.getMetricUUId()); - DegreeDTO bug = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.BUG.getType(), AnalyseTypeEnum.BUG.getMetricUUId()); - DegreeDTO vulnerability = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.Vulnerability.getType(), AnalyseTypeEnum.Vulnerability.getMetricUUId()); + DegreeDTO codeSmall = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.CodeSmell.getType(), AnalyseTypeEnum.CodeSmell.getMetricName()); + DegreeDTO bug = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.BUG.getType(), AnalyseTypeEnum.BUG.getMetricName()); + DegreeDTO vulnerability = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.Vulnerability.getType(), AnalyseTypeEnum.Vulnerability.getMetricName()); AnalyseDetailDTO analyseDetail = new AnalyseDetailDTO(); analyseDetail.setBug(bug == null ? new DegreeDTO() : bug); diff --git a/src/main/java/net/educoder/ecsonar/services/ReportService.java b/src/main/java/net/educoder/ecsonar/services/ReportService.java index f2e8457..155c822 100644 --- a/src/main/java/net/educoder/ecsonar/services/ReportService.java +++ b/src/main/java/net/educoder/ecsonar/services/ReportService.java @@ -1,6 +1,7 @@ package net.educoder.ecsonar.services; import net.educoder.ecsonar.dao.ProjectDao; +import net.educoder.ecsonar.enums.AnalyseTypeEnum; import net.educoder.ecsonar.model.Metrics; import net.educoder.ecsonar.model.Project; import net.educoder.ecsonar.utils.ExcelUtil; @@ -162,7 +163,7 @@ public class ReportService { */ private String getViolations(String uuid) { //93 - return projectDao.getLevel(uuid, "AYeNSwayTEppvP7II93_"); + return projectDao.getLevel(uuid, AnalyseTypeEnum.Vulnerability.getMetricName()); } @@ -209,7 +210,7 @@ public class ReportService { */ private String getBugs(String uuid) { //89 - return projectDao.getLevel(uuid, "AYeNSwayTEppvP7II94B"); + return projectDao.getLevel(uuid, AnalyseTypeEnum.BUG.getMetricName()); } @@ -256,7 +257,7 @@ public class ReportService { */ private String getCodeSmells(String uuid) { //80 - return projectDao.getLevel(uuid, "AYeNSwaxTEppvP7II93y"); + return projectDao.getLevel(uuid, AnalyseTypeEnum.CodeSmell.getMetricName()); } diff --git a/src/main/resources/mapper/IssuesMapper.xml b/src/main/resources/mapper/IssuesMapper.xml index 3700209..28498ad 100644 --- a/src/main/resources/mapper/IssuesMapper.xml +++ b/src/main/resources/mapper/IssuesMapper.xml @@ -50,7 +50,7 @@ (select count(1) from issues i where project_uuid =#{projectUuid} and issue_type=#{issueType} and severity = 'MINOR' and status='OPEN') minor, (select count(1) from issues i where project_uuid =#{projectUuid} and issue_type=#{issueType} and severity = 'BLOCKER' and status='OPEN') blocker, (select count(1) from issues i where project_uuid =#{projectUuid} and issue_type=#{issueType} and severity = 'CRITICAL' and status='OPEN') critical, - (select text_value from project_measures i where component_uuid =#{projectUuid} and metric_uuid = #{metricUUid} limit 1) levelStr + (select text_value from project_measures i where component_uuid =#{projectUuid} and metric_uuid = (select uuid from metrics where name=#{metricName}) limit 1) levelStr