From 3d35d48c95effa20a3f1443384aef3dcd7acf124 Mon Sep 17 00:00:00 2001 From: youys <1272586223@qq.com> Date: Fri, 21 Jan 2022 11:48:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/QualityInspectController.java | 4 ++- .../net/educoder/ecsonar/dao/ProjectDao.java | 22 ++++++++++++++++ .../net/educoder/ecsonar/model/Metrics.java | 6 ++--- .../services/QualityInspectService.java | 4 +-- .../ecsonar/services/ReportService.java | 25 ++++--------------- 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/main/java/net/educoder/ecsonar/controller/QualityInspectController.java b/src/main/java/net/educoder/ecsonar/controller/QualityInspectController.java index 675d6e8..6213e13 100644 --- a/src/main/java/net/educoder/ecsonar/controller/QualityInspectController.java +++ b/src/main/java/net/educoder/ecsonar/controller/QualityInspectController.java @@ -31,7 +31,9 @@ public class QualityInspectController { /** * 质量检测 - * @param qualityInspectVO + * @param language 语言 + * @param homeworkId 实训作业id + * @param userDatas 用户数据 * @return */ @RequestMapping(value = "qualityInspect", method = RequestMethod.POST) diff --git a/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java b/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java index 1120d21..8097198 100644 --- a/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java +++ b/src/main/java/net/educoder/ecsonar/dao/ProjectDao.java @@ -1,5 +1,6 @@ package net.educoder.ecsonar.dao; +import net.educoder.ecsonar.model.Metrics; import net.educoder.ecsonar.model.Project; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -26,4 +27,25 @@ public interface ProjectDao { @Select("SELECT count(*) FROM issues where project_uuid=#{uuid} and " + "status='OPEN' and issue_type=#{issue_type} and severity=#{severity}") int getIndicator(@Param("uuid") String uuid, @Param("issue_type") int issue_type, @Param("severity") String severity); + + + @Select("select " + + "(select COALESCE(value,0) complexity from project_measures where component_uuid = #{projectUuid} and metric_id = 19 order by id desc limit 1)," + + "(select COALESCE(value,0) lines from project_measures where component_uuid = #{projectUuid} and metric_id = 1 order by id desc 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_id = 80 order by id desc 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_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 = 93 order by id desc limit 1)") + Metrics selectMetricsByProjectUuid(String projectUuid); } diff --git a/src/main/java/net/educoder/ecsonar/model/Metrics.java b/src/main/java/net/educoder/ecsonar/model/Metrics.java index f1713c1..e80c039 100644 --- a/src/main/java/net/educoder/ecsonar/model/Metrics.java +++ b/src/main/java/net/educoder/ecsonar/model/Metrics.java @@ -3,7 +3,7 @@ package net.educoder.ecsonar.model; public class Metrics { // 复杂度 - private String complexity; + private Float complexity; private int lines; @@ -31,10 +31,10 @@ public class Metrics { public String getComplexity() { - return complexity; + return complexity+""; } - public void setComplexity(String complexity) { + public void setComplexity(Float complexity) { this.complexity = complexity; } diff --git a/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java b/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java index 0058eaa..3bd5bc1 100644 --- a/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java +++ b/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java @@ -167,8 +167,8 @@ public class QualityInspectService { if (taskInfo.getStatus() == 0 && completed == 1) { taskInfoDao.updateTaskInfoStatus(taskInfo.getId(), 1); - // 并且删除文件 /tmp/taskId/* /tmp/homeworkId/* - String command = String.format("rm -rf /tmp/%s/* && rm -rf /tmp/%s/*", taskId, taskInfo.getHomeworkId()); + // 并且删除文件 /tmp/$taskId /tmp/homeworkId/* + String command = String.format("rm -rf /tmp/%s && rm -rf /tmp/%s/*", taskId, taskInfo.getHomeworkId()); SystemUtil.executeAndGetExitStatus(command); } diff --git a/src/main/java/net/educoder/ecsonar/services/ReportService.java b/src/main/java/net/educoder/ecsonar/services/ReportService.java index 31aaa7b..19ea85c 100644 --- a/src/main/java/net/educoder/ecsonar/services/ReportService.java +++ b/src/main/java/net/educoder/ecsonar/services/ReportService.java @@ -11,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.File; -import java.io.IOException; @Service public class ReportService { @@ -35,31 +34,14 @@ public class ReportService { } String uuid = project.getProject_uuid(); - Metrics metrics = new Metrics(); - metrics.setComplexity(getComplexity(uuid)); - metrics.setLines(getLines(uuid)); - metrics.setBlock_bugs(getBlockBugs(uuid)); - metrics.setBlock_code_smells(getBlockCodeSmells(uuid)); - metrics.setBlock_violations(getBlockViolations(uuid)); - metrics.setCritical_bugs(getCriticalBugs(uuid)); - metrics.setCritical_code_smells(getCriticalCodeSmells(uuid)); - metrics.setCritical_violations(getCriticalViolations(uuid)); - metrics.setMajor_bugs(getMajorBugs(uuid)); - metrics.setMajor_code_smells(getMajorCodeSmells(uuid)); - metrics.setMajor_violations(getMajorViolations(uuid)); - metrics.setMinor_bugs(getMinorBugs(uuid)); - metrics.setMinor_code_smells(getMinorCodeSmells(uuid)); - metrics.setMinor_violations(getMinorViolations(uuid)); - metrics.setBugs(getBugs(uuid)); - metrics.setViolations(getViolations(uuid)); - metrics.setCode_smells(getCodeSmells(uuid)); + Metrics metrics = projectDao.selectMetricsByProjectUuid(uuid); return metrics; } public Metrics getDefault(){ Metrics metrics = new Metrics(); - metrics.setComplexity("0"); + metrics.setComplexity(0f); metrics.setLines(0); metrics.setBlock_bugs(0); metrics.setBlock_code_smells(0); @@ -276,4 +258,7 @@ public class ReportService { //80 return projectDao.getLevel(uuid, 80); } + + + }