修改sql语句

sonar10.0
youys 2 years ago
parent b492366dc4
commit 056b2f43b3

@ -39,10 +39,10 @@ public interface IssuesDao {
* *
* @param projectUuid * @param projectUuid
* @param issueType * @param issueType
* @param metricUUid * @param metricName
* @return * @return
*/ */
DegreeDTO queryDegree(String projectUuid, Integer issueType, String metricUUid); DegreeDTO queryDegree(String projectUuid, Integer issueType, String metricName);
/** /**

@ -22,7 +22,7 @@ public interface ProjectDao {
* @param uuid * @param uuid
* @return * @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); Float getComplexity(@Param("uuid") String uuid);
/** /**
@ -30,17 +30,17 @@ public interface ProjectDao {
* @param uuid * @param uuid
* @return * @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); Integer getLines(@Param("uuid") String uuid);
/** /**
* *
* @param uuid * @param uuid
* @param metricUUid * @param metricName
* @return * @return
*/ */
@Select("select text_value from project_measures where component_uuid = #{uuid} and metric_uuid = #{metric_uuid} limit 1") @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("metric_uuid") String metricUUid); String getLevel(@Param("uuid") String uuid, @Param("metricName") String metricName);
@Select("SELECT count(*) FROM issues where project_uuid=#{uuid} and " + @Select("SELECT count(*) FROM issues where project_uuid=#{uuid} and " +
"status='OPEN' and issue_type=#{issue_type} and severity=#{severity}") "status='OPEN' and issue_type=#{issue_type} and severity=#{severity}")
@ -56,23 +56,23 @@ public interface ProjectDao {
* @return * @return
*/ */
@Select("select " + @Select("select " +
"(select COALESCE(value,0) complexity from project_measures where component_uuid = #{projectUuid} and metric_uuid = 'AYeNSwarTEppvP7II92z' 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 = 'AYeNSwakTEppvP7II92h' 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) 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) 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) 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 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) 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) 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) 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 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) 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) 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) 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 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); 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("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=2) bugs," +
"(select count(1) from issues where project_uuid=#{projectUuid} and issue_type=3) vulnerability," + "(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); IssuesMetrics selectIssuesMetrics(String projectUuid);
/** /**
@ -90,4 +90,7 @@ public interface ProjectDao {
* @return * @return
*/ */
Rule findRuleById(@Param("uuid") String uuid); Rule findRuleById(@Param("uuid") String uuid);
// @Select("select uuid from metrics m where name=#{name}}")
// String findMetricUUIDByName(@Param("name") String name);
} }

@ -8,20 +8,20 @@ package net.educoder.ecsonar.enums;
*/ */
public enum AnalyseTypeEnum { public enum AnalyseTypeEnum {
CodeSmell(1,80, "AYeNSwaxTEppvP7II93y"), CodeSmell(1,80, "sqale_rating"),
BUG(2, 89, "AYeNSwayTEppvP7II94B"), BUG(2, 89, "security_review_rating"),
Vulnerability(3,93, "AYeNSwayTEppvP7II93_"); Vulnerability(3,93, "security_rating");
private Integer type; private Integer type;
private Integer metricId; 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.type = type;
this.metricId = metricId; this.metricId = metricId;
this.metricUUId = metricUUId; this.metricName = metricName;
} }
@ -33,8 +33,8 @@ public enum AnalyseTypeEnum {
return metricId; return metricId;
} }
public String getMetricUUId() { public String getMetricName() {
return metricUUId; return metricName;
} }
public static AnalyseTypeEnum getAnalyseTypeEnum(Integer type) { public static AnalyseTypeEnum getAnalyseTypeEnum(Integer type) {

@ -240,9 +240,9 @@ public class QualityInspectService {
throw new BusinessException(-1, String.format("找不到分析记录homeworkId:%s,studentNo:%s", analyseDetailVO.getHomeworkId(), analyseDetailVO.getStudentNo())); 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 codeSmall = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.CodeSmell.getType(), AnalyseTypeEnum.CodeSmell.getMetricName());
DegreeDTO bug = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.BUG.getType(), AnalyseTypeEnum.BUG.getMetricUUId()); DegreeDTO bug = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.BUG.getType(), AnalyseTypeEnum.BUG.getMetricName());
DegreeDTO vulnerability = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.Vulnerability.getType(), AnalyseTypeEnum.Vulnerability.getMetricUUId()); DegreeDTO vulnerability = issuesDao.queryDegree(project.getUuid(), AnalyseTypeEnum.Vulnerability.getType(), AnalyseTypeEnum.Vulnerability.getMetricName());
AnalyseDetailDTO analyseDetail = new AnalyseDetailDTO(); AnalyseDetailDTO analyseDetail = new AnalyseDetailDTO();
analyseDetail.setBug(bug == null ? new DegreeDTO() : bug); analyseDetail.setBug(bug == null ? new DegreeDTO() : bug);

@ -1,6 +1,7 @@
package net.educoder.ecsonar.services; package net.educoder.ecsonar.services;
import net.educoder.ecsonar.dao.ProjectDao; import net.educoder.ecsonar.dao.ProjectDao;
import net.educoder.ecsonar.enums.AnalyseTypeEnum;
import net.educoder.ecsonar.model.Metrics; import net.educoder.ecsonar.model.Metrics;
import net.educoder.ecsonar.model.Project; import net.educoder.ecsonar.model.Project;
import net.educoder.ecsonar.utils.ExcelUtil; import net.educoder.ecsonar.utils.ExcelUtil;
@ -162,7 +163,7 @@ public class ReportService {
*/ */
private String getViolations(String uuid) { private String getViolations(String uuid) {
//93 //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) { private String getBugs(String uuid) {
//89 //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) { private String getCodeSmells(String uuid) {
//80 //80
return projectDao.getLevel(uuid, "AYeNSwaxTEppvP7II93y"); return projectDao.getLevel(uuid, AnalyseTypeEnum.CodeSmell.getMetricName());
} }

@ -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 = '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 = '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 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
</select> </select>

Loading…
Cancel
Save