质量分析改动

dev
youys 2 years ago
parent e8790e9f09
commit 4c7113e67e

@ -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> cloudBrainQualityInspectVO) {
public ResponseResult<List<CloudBrainQualityInspectDTO>> cloudQualityInspect(@RequestBody List<CloudBrainQualityInspectVO> cloudBrainQualityInspectVO) {
logger.info("cloudQualityInspect请求参数:{}", JSONObject.toJSONString(cloudBrainQualityInspectVO));
if (CollectionUtils.isEmpty(cloudBrainQualityInspectVO)) {
ResponseResult.error("参数不能为空");
}
QualityInspect qualityInspect = cloudBrainService.startQualityInspect(cloudBrainQualityInspectVO);
return ResponseResult.success(qualityInspect);
List<CloudBrainQualityInspectDTO> inspectDTOList = cloudBrainService.startQualityInspect(cloudBrainQualityInspectVO);
return ResponseResult.success(inspectDTOList);
}

@ -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<String> selectProjectNamesByTaskId(String taskId);
String selectProjectNamesByTaskId(String taskId);
}

@ -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() {

@ -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;
}
}

@ -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() {

@ -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;
}
}

@ -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<CloudQualityInspectMetricsVO> 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<CloudQualityInspectMetricsVO> 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<CloudQualityInspectMetricsVO> metricsVOList) {
this.metricsVOList = metricsVOList;
public void setCodeLines(Integer codeLines) {
this.codeLines = codeLines;
}
}

@ -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() {

@ -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> cloudBrainQualityInspectVO) {
public List<CloudBrainQualityInspectDTO> startQualityInspect(List<CloudBrainQualityInspectVO> cloudBrainQualityInspectVO) {
CloudTaskInfo cloudTaskInfo = new CloudTaskInfo();
cloudTaskInfo.setId(IdUtils.nextStrId());
cloudTaskInfo.setPeopleNumber(cloudBrainQualityInspectVO.size());
cloudTaskInfoDao.insertCloudTaskInfo(cloudTaskInfo);
List<CloudBrainQualityInspectDTO> 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<String> projectNames = cloudTaskInfoDetailDao.selectProjectNamesByTaskId(taskId);
String projectName = cloudTaskInfoDetailDao.selectProjectNamesByTaskId(taskId);
Project project = projectDao.findByName(projectName);
List<CloudQualityInspectMetricsVO> 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<IssuesVO> issuesSearch(IssuesSearchVO searchVO) {
List<IssuesVO> issues = doGetIssues(searchVO.getProjectName(), searchVO.getType());
List<IssuesVO> issues = doGetIssues(searchVO.getTaskName(), searchVO.getType());
return issues;
}
/**
*
*
* @param component
* @return
*/

Loading…
Cancel
Save