diff --git a/src/main/java/net/educoder/ecsonar/controller/CloudBrainController.java b/src/main/java/net/educoder/ecsonar/controller/CloudBrainController.java index 73ec300..951243d 100644 --- a/src/main/java/net/educoder/ecsonar/controller/CloudBrainController.java +++ b/src/main/java/net/educoder/ecsonar/controller/CloudBrainController.java @@ -3,6 +3,7 @@ package net.educoder.ecsonar.controller; import com.alibaba.fastjson.JSONObject; import net.educoder.ecsonar.model.api.QualityInspect; import net.educoder.ecsonar.model.api.QualityInspectIsCompleted; +import net.educoder.ecsonar.model.dto.CloudBrainQualityInspectDTO; import net.educoder.ecsonar.model.vo.*; import net.educoder.ecsonar.services.CloudBrainService; import net.educoder.ecsonar.utils.ResponseResult; @@ -37,13 +38,13 @@ public class CloudBrainController { * @return */ @PostMapping("/cloudQualityInspect") - public ResponseResult cloudQualityInspect(@RequestBody List cloudBrainQualityInspectVO) { + public ResponseResult> cloudQualityInspect(@RequestBody List cloudBrainQualityInspectVO) { logger.info("cloudQualityInspect请求参数:{}", JSONObject.toJSONString(cloudBrainQualityInspectVO)); if (CollectionUtils.isEmpty(cloudBrainQualityInspectVO)) { ResponseResult.error("参数不能为空"); } - QualityInspect qualityInspect = cloudBrainService.startQualityInspect(cloudBrainQualityInspectVO); - return ResponseResult.success(qualityInspect); + List inspectDTOList = cloudBrainService.startQualityInspect(cloudBrainQualityInspectVO); + return ResponseResult.success(inspectDTOList); } diff --git a/src/main/java/net/educoder/ecsonar/dao/CloudTaskInfoDetailDao.java b/src/main/java/net/educoder/ecsonar/dao/CloudTaskInfoDetailDao.java index 3433df8..28c5c1e 100644 --- a/src/main/java/net/educoder/ecsonar/dao/CloudTaskInfoDetailDao.java +++ b/src/main/java/net/educoder/ecsonar/dao/CloudTaskInfoDetailDao.java @@ -20,7 +20,7 @@ public interface CloudTaskInfoDetailDao { * * @param cloudTaskInfoDetail */ - @Insert("insert into cloud_task_info_detail(id,task_id,project_name,user_id,language,git_url) values(#{id},#{taskId},#{projectName},#{userId},#{language},#{gitUrl} )") + @Insert("insert into cloud_task_info_detail(id,task_id,project_name,project_id,language,git_url) values(#{id},#{taskId},#{projectName},#{projectId},#{language},#{gitUrl} )") void insertCloudTaskInfoDetail(CloudTaskInfoDetail cloudTaskInfoDetail); @@ -48,5 +48,5 @@ public interface CloudTaskInfoDetailDao { * @return */ @Select("select project_name from cloud_task_info_detail where task_id=#{taskId} and status=1") - List selectProjectNamesByTaskId(String taskId); + String selectProjectNamesByTaskId(String taskId); } diff --git a/src/main/java/net/educoder/ecsonar/model/CloudTaskInfoDetail.java b/src/main/java/net/educoder/ecsonar/model/CloudTaskInfoDetail.java index 1809747..4bf089f 100644 --- a/src/main/java/net/educoder/ecsonar/model/CloudTaskInfoDetail.java +++ b/src/main/java/net/educoder/ecsonar/model/CloudTaskInfoDetail.java @@ -12,7 +12,7 @@ public class CloudTaskInfoDetail { private String id; private String taskId; private String projectName; - private String userId; + private String projectId; private String language; private String gitUrl; /** @@ -46,12 +46,12 @@ public class CloudTaskInfoDetail { this.projectName = projectName; } - public String getUserId() { - return userId; + public String getProjectId() { + return projectId; } - public void setUserId(String userId) { - this.userId = userId; + public void setProjectId(String projectId) { + this.projectId = projectId; } public String getLanguage() { diff --git a/src/main/java/net/educoder/ecsonar/model/dto/CloudBrainQualityInspectDTO.java b/src/main/java/net/educoder/ecsonar/model/dto/CloudBrainQualityInspectDTO.java new file mode 100644 index 0000000..dcd86e7 --- /dev/null +++ b/src/main/java/net/educoder/ecsonar/model/dto/CloudBrainQualityInspectDTO.java @@ -0,0 +1,36 @@ +package net.educoder.ecsonar.model.dto; + +/** + * @Author: youys + * @Date: 2022/7/7 + * @Description: + */ +public class CloudBrainQualityInspectDTO { + + private String taskId; + private String projectId; + + public CloudBrainQualityInspectDTO() { + } + + public CloudBrainQualityInspectDTO(String taskId, String projectId) { + this.taskId = taskId; + this.projectId = projectId; + } + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getProjectId() { + return projectId; + } + + public void setProjectId(String projectId) { + this.projectId = projectId; + } +} diff --git a/src/main/java/net/educoder/ecsonar/model/vo/CloudBrainQualityInspectVO.java b/src/main/java/net/educoder/ecsonar/model/vo/CloudBrainQualityInspectVO.java index dc239b0..c969989 100644 --- a/src/main/java/net/educoder/ecsonar/model/vo/CloudBrainQualityInspectVO.java +++ b/src/main/java/net/educoder/ecsonar/model/vo/CloudBrainQualityInspectVO.java @@ -9,9 +9,9 @@ package net.educoder.ecsonar.model.vo; public class CloudBrainQualityInspectVO { /** - * 用户id + * 项目唯一标识 */ - private String userId; + private String projectId; /** * 仓库代码id @@ -28,12 +28,12 @@ public class CloudBrainQualityInspectVO { */ private String language; - public String getUserId() { - return userId; + public String getProjectId() { + return projectId; } - public void setUserId(String userId) { - this.userId = userId; + public void setProjectId(String projectId) { + this.projectId = projectId; } public String getGitUrl() { diff --git a/src/main/java/net/educoder/ecsonar/model/vo/CloudQualityInspectMetricsVO.java b/src/main/java/net/educoder/ecsonar/model/vo/CloudQualityInspectMetricsVO.java deleted file mode 100644 index b8589f7..0000000 --- a/src/main/java/net/educoder/ecsonar/model/vo/CloudQualityInspectMetricsVO.java +++ /dev/null @@ -1,81 +0,0 @@ -package net.educoder.ecsonar.model.vo; - - -/** - * @Author: youys - * @Date: 2022/7/6 - * @Description: - */ -public class CloudQualityInspectMetricsVO { - - - private String taskId; - private String projectName; - - /** - * bug - */ - private Integer bugs; - /**¬ - * 漏洞 - */ - private Integer vulnerability; - /** - * 代码气味 - */ - private Integer codeSmell; - /** - * 代码行数 - */ - private Integer codeLines; - - - public String getProjectName() { - return projectName; - } - - public void setProjectName(String projectName) { - this.projectName = projectName; - } - - public String getTaskId() { - return taskId; - } - - public void setTaskId(String taskId) { - this.taskId = taskId; - } - - public Integer getBugs() { - return bugs; - } - - public void setBugs(Integer bugs) { - this.bugs = bugs; - } - - public Integer getVulnerability() { - return vulnerability; - } - - public void setVulnerability(Integer vulnerability) { - this.vulnerability = vulnerability; - } - - - public Integer getCodeLines() { - return codeLines; - } - - public void setCodeLines(Integer codeLines) { - this.codeLines = codeLines; - } - - public Integer getCodeSmell() { - return codeSmell; - } - - public void setCodeSmell(Integer codeSmell) { - this.codeSmell = codeSmell; - } -} diff --git a/src/main/java/net/educoder/ecsonar/model/vo/CloudQualityInspectResultVO.java b/src/main/java/net/educoder/ecsonar/model/vo/CloudQualityInspectResultVO.java index 6287ed1..9592996 100644 --- a/src/main/java/net/educoder/ecsonar/model/vo/CloudQualityInspectResultVO.java +++ b/src/main/java/net/educoder/ecsonar/model/vo/CloudQualityInspectResultVO.java @@ -1,8 +1,6 @@ package net.educoder.ecsonar.model.vo; -import java.util.ArrayList; -import java.util.List; /** * @Author: youys @@ -15,7 +13,24 @@ public class CloudQualityInspectResultVO { private String taskId; private Integer completed; - private List metricsVOList = new ArrayList<>(0); + private String taskName; + + /** + * bug + */ + private Integer bugs; + /**¬ + * 漏洞 + */ + private Integer vulnerability; + /** + * 代码气味 + */ + private Integer codeSmell; + /** + * 代码行数 + */ + private Integer codeLines; public String getTaskId() { return taskId; @@ -33,11 +48,43 @@ public class CloudQualityInspectResultVO { this.completed = completed; } - public List getMetricsVOList() { - return metricsVOList; + public String getTaskName() { + return taskName; + } + + public void setTaskName(String taskName) { + this.taskName = taskName; + } + + public Integer getBugs() { + return bugs; + } + + public void setBugs(Integer bugs) { + this.bugs = bugs; + } + + public Integer getVulnerability() { + return vulnerability; + } + + public void setVulnerability(Integer vulnerability) { + this.vulnerability = vulnerability; + } + + public Integer getCodeSmell() { + return codeSmell; + } + + public void setCodeSmell(Integer codeSmell) { + this.codeSmell = codeSmell; + } + + public Integer getCodeLines() { + return codeLines; } - public void setMetricsVOList(List metricsVOList) { - this.metricsVOList = metricsVOList; + public void setCodeLines(Integer codeLines) { + this.codeLines = codeLines; } } diff --git a/src/main/java/net/educoder/ecsonar/model/vo/IssuesSearchVO.java b/src/main/java/net/educoder/ecsonar/model/vo/IssuesSearchVO.java index b6ebbf8..b9b51e1 100644 --- a/src/main/java/net/educoder/ecsonar/model/vo/IssuesSearchVO.java +++ b/src/main/java/net/educoder/ecsonar/model/vo/IssuesSearchVO.java @@ -7,24 +7,15 @@ package net.educoder.ecsonar.model.vo; */ public class IssuesSearchVO { - private String taskId; - private String projectName; + private String taskName; private String type; - public String getTaskId() { - return taskId; + public String getTaskName() { + return taskName; } - public void setTaskId(String taskId) { - this.taskId = taskId; - } - - public String getProjectName() { - return projectName; - } - - public void setProjectName(String projectName) { - this.projectName = projectName; + public void setTaskName(String taskName) { + this.taskName = taskName; } public String getType() { diff --git a/src/main/java/net/educoder/ecsonar/services/CloudBrainService.java b/src/main/java/net/educoder/ecsonar/services/CloudBrainService.java index 9c6c7ea..1dc6da7 100644 --- a/src/main/java/net/educoder/ecsonar/services/CloudBrainService.java +++ b/src/main/java/net/educoder/ecsonar/services/CloudBrainService.java @@ -11,8 +11,8 @@ import net.educoder.ecsonar.model.CloudTaskInfo; import net.educoder.ecsonar.model.CloudTaskInfoDetail; import net.educoder.ecsonar.model.IssuesMetrics; import net.educoder.ecsonar.model.Project; -import net.educoder.ecsonar.model.api.QualityInspect; import net.educoder.ecsonar.model.api.QualityInspectIsCompleted; +import net.educoder.ecsonar.model.dto.CloudBrainQualityInspectDTO; import net.educoder.ecsonar.model.vo.*; import net.educoder.ecsonar.task.CloudBrainQualityInspectRunnable; import net.educoder.ecsonar.utils.IdUtils; @@ -63,35 +63,40 @@ public class CloudBrainService { @Transactional(rollbackFor = Exception.class) - public QualityInspect startQualityInspect(List cloudBrainQualityInspectVO) { + public List startQualityInspect(List cloudBrainQualityInspectVO) { - - CloudTaskInfo cloudTaskInfo = new CloudTaskInfo(); - cloudTaskInfo.setId(IdUtils.nextStrId()); - cloudTaskInfo.setPeopleNumber(cloudBrainQualityInspectVO.size()); - cloudTaskInfoDao.insertCloudTaskInfo(cloudTaskInfo); + List inspectDTOList = new ArrayList<>(cloudBrainQualityInspectVO.size()); for (CloudBrainQualityInspectVO brainQualityInspectVO : cloudBrainQualityInspectVO) { - // taskId-userId-projectName - String finalProjectName = String.format("%s-%s-%s", cloudTaskInfo.getId(), brainQualityInspectVO.getUserId(), brainQualityInspectVO.getProjectName()); + // 创建taskInfo----一个人对应一个taskId + CloudTaskInfo cloudTaskInfo = new CloudTaskInfo(); + cloudTaskInfo.setId(IdUtils.nextStrId()); + cloudTaskInfo.setPeopleNumber(1); + cloudTaskInfoDao.insertCloudTaskInfo(cloudTaskInfo); + + inspectDTOList.add(new CloudBrainQualityInspectDTO(cloudTaskInfo.getId(), brainQualityInspectVO.getProjectId())); + // taskId-projectId + String finalProjectName = String.format("%s-%s", cloudTaskInfo.getId(), brainQualityInspectVO.getProjectId()); + + // 创建taskInfoDetail CloudTaskInfoDetail cloudTaskInfoDetail = new CloudTaskInfoDetail(); cloudTaskInfoDetail.setId(IdUtils.nextStrId()); cloudTaskInfoDetail.setTaskId(cloudTaskInfo.getId()); cloudTaskInfoDetail.setLanguage(brainQualityInspectVO.getLanguage()); cloudTaskInfoDetail.setProjectName(finalProjectName); - cloudTaskInfoDetail.setUserId(brainQualityInspectVO.getUserId()); + cloudTaskInfoDetail.setProjectId(brainQualityInspectVO.getProjectId()); cloudTaskInfoDetail.setGitUrl(brainQualityInspectVO.getGitUrl()); - cloudTaskInfoDetailDao.insertCloudTaskInfoDetail(cloudTaskInfoDetail); + // 创建一个扫描任务 CloudBrainQualityInspectRunnable runnable = new CloudBrainQualityInspectRunnable(cloudTaskInfoDetail, sonarService, dbOperateService, sonarQueryResultPool); sonarScannerPool.execute(runnable); } - return new QualityInspect(cloudTaskInfo.getId()); + return inspectDTOList; } public QualityInspectIsCompleted cloudQualityInspectIsCompleted(String taskId) { @@ -125,7 +130,6 @@ public class CloudBrainService { QualityInspectIsCompleted qualityInspectIsCompleted = cloudQualityInspectIsCompleted(taskId); - CloudQualityInspectResultVO resultVO = new CloudQualityInspectResultVO(); resultVO.setTaskId(taskId); resultVO.setCompleted(qualityInspectIsCompleted.getCompleted()); @@ -139,43 +143,35 @@ public class CloudBrainService { return resultVO; } - List projectNames = cloudTaskInfoDetailDao.selectProjectNamesByTaskId(taskId); - + String projectName = cloudTaskInfoDetailDao.selectProjectNamesByTaskId(taskId); + Project project = projectDao.findByName(projectName); - List metricsVOList = new ArrayList<>(projectNames.size()); - for (String projectName : projectNames) { - Project project = projectDao.findByName(projectName); + IssuesMetrics issuesMetrics = projectDao.selectIssuesMetrics(project.getProject_uuid()); + resultVO.setTaskName(projectName); + resultVO.setBugs(issuesMetrics.getBugs()); + resultVO.setVulnerability(issuesMetrics.getVulnerability()); + resultVO.setCodeSmell(issuesMetrics.getCodeSmell()); + resultVO.setCodeLines(issuesMetrics.getCodeLines()); - IssuesMetrics issuesMetrics = projectDao.selectIssuesMetrics(project.getProject_uuid()); - CloudQualityInspectMetricsVO metricsVO = new CloudQualityInspectMetricsVO(); - metricsVO.setProjectName(projectName); - metricsVO.setBugs(issuesMetrics.getBugs()); - metricsVO.setVulnerability(issuesMetrics.getVulnerability()); - metricsVO.setCodeSmell(issuesMetrics.getCodeSmell()); - metricsVO.setCodeLines(issuesMetrics.getCodeLines()); - metricsVOList.add(metricsVO); - - - } - - resultVO.setMetricsVOList(metricsVOList); return resultVO; } /** * issues 搜索 + * * @param searchVO * @return */ public List issuesSearch(IssuesSearchVO searchVO) { - List issues = doGetIssues(searchVO.getProjectName(), searchVO.getType()); + List issues = doGetIssues(searchVO.getTaskName(), searchVO.getType()); return issues; } /** * 获取源码 + * * @param component * @return */