|
|
|
@ -1,7 +1,10 @@
|
|
|
|
|
package net.educoder.ecsonar.services;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
import com.google.protobuf.InvalidProtocolBufferException;
|
|
|
|
|
import net.educoder.ecsonar.dao.*;
|
|
|
|
|
import net.educoder.ecsonar.enums.AnalyseTypeEnum;
|
|
|
|
|
import net.educoder.ecsonar.enums.DegreeEnum;
|
|
|
|
|
import net.educoder.ecsonar.exception.BusinessException;
|
|
|
|
|
import net.educoder.ecsonar.model.*;
|
|
|
|
|
import net.educoder.ecsonar.model.api.Quality;
|
|
|
|
@ -10,6 +13,7 @@ import net.educoder.ecsonar.model.api.QualityInspectIsCompleted;
|
|
|
|
|
import net.educoder.ecsonar.model.api.QualityInspectResultData;
|
|
|
|
|
import net.educoder.ecsonar.model.dto.*;
|
|
|
|
|
import net.educoder.ecsonar.model.vo.*;
|
|
|
|
|
import net.educoder.ecsonar.protobuf.DbIssues;
|
|
|
|
|
import net.educoder.ecsonar.task.GraduationProjectQualityInspectRunnable;
|
|
|
|
|
import net.educoder.ecsonar.utils.IdUtils;
|
|
|
|
|
import net.educoder.ecsonar.utils.SystemUtil;
|
|
|
|
@ -57,9 +61,6 @@ public class GraduationProjectQualityInspectService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ProjectDao projectDao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private FileSourceDao fileSourceDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
@Qualifier("sonarScannerPool")
|
|
|
|
@ -114,13 +115,13 @@ public class GraduationProjectQualityInspectService {
|
|
|
|
|
|
|
|
|
|
public RollPage<QualityInspectResultData> qualityInspectResultQuery(GraduationQualityInspectResultQueryVO queryVO) {
|
|
|
|
|
int pageSize = queryVO.getPageSize();
|
|
|
|
|
int pageNum = queryVO.getPageNumber();
|
|
|
|
|
int pageNum = queryVO.getCurrentPage();
|
|
|
|
|
|
|
|
|
|
RollPage<QualityInspectResultData> rollPage = new RollPage<>();
|
|
|
|
|
rollPage.setCurrentPage(pageNum);
|
|
|
|
|
rollPage.setPageSize(pageSize);
|
|
|
|
|
|
|
|
|
|
int offset = (queryVO.getPageNumber() - 1) * queryVO.getPageSize();
|
|
|
|
|
int offset = (pageNum - 1) * queryVO.getPageSize();
|
|
|
|
|
Integer totalCount = graduationProjectTaskInfoDetailDao.
|
|
|
|
|
selectGraduationProjectTaskInfoDetailPageCount(queryVO.getTaskId(), pageSize, offset);
|
|
|
|
|
rollPage.setRecordSum(totalCount);
|
|
|
|
@ -141,6 +142,7 @@ public class GraduationProjectQualityInspectService {
|
|
|
|
|
resultData.setName(taskInfoDetail.getName());
|
|
|
|
|
resultData.setStudentId(taskInfoDetail.getStudentId());
|
|
|
|
|
resultData.setUserId(taskInfoDetail.getUserId());
|
|
|
|
|
resultData.setTaskDetailId(taskInfoDetail.getId());
|
|
|
|
|
|
|
|
|
|
Metrics metrics = reportService.getMetrics(taskInfoDetail.getProjectName());
|
|
|
|
|
|
|
|
|
@ -259,11 +261,30 @@ public class GraduationProjectQualityInspectService {
|
|
|
|
|
/**
|
|
|
|
|
* 分析详情
|
|
|
|
|
*
|
|
|
|
|
* @param analyseDetailVO
|
|
|
|
|
* @param taskDetailId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public AnalyseDetailDTO getAnalyseDetail(AnalyseDetailVO analyseDetailVO) {
|
|
|
|
|
return null;
|
|
|
|
|
public AnalyseDetailDTO getAnalyseDetail(String taskDetailId) {
|
|
|
|
|
// 作业id+学号
|
|
|
|
|
GraduationProjectTaskInfoDetail graduationProjectTaskInfoDetail = graduationProjectTaskInfoDetailDao.selectById(taskDetailId);
|
|
|
|
|
if (graduationProjectTaskInfoDetail == null) {
|
|
|
|
|
throw new BusinessException(-1, "找不到分析记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Project project = projectDao.findByName(graduationProjectTaskInfoDetail.getProjectName());
|
|
|
|
|
if (project == null) {
|
|
|
|
|
throw new BusinessException(-1, String.format("找不到分析记录detailId:%s", taskDetailId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DegreeDTO codeSmall = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.CodeSmell.getType(), AnalyseTypeEnum.CodeSmell.getMetricId());
|
|
|
|
|
DegreeDTO bug = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.BUG.getType(), AnalyseTypeEnum.BUG.getMetricId());
|
|
|
|
|
DegreeDTO vulnerability = issuesDao.queryDegree(project.getProject_uuid(), AnalyseTypeEnum.Vulnerability.getType(), AnalyseTypeEnum.Vulnerability.getMetricId());
|
|
|
|
|
|
|
|
|
|
AnalyseDetailDTO analyseDetail = new AnalyseDetailDTO();
|
|
|
|
|
analyseDetail.setBug(bug == null ? new DegreeDTO() : bug);
|
|
|
|
|
analyseDetail.setVulnerability(vulnerability == null ? new DegreeDTO() : vulnerability);
|
|
|
|
|
analyseDetail.setCodeSmall(codeSmall == null ? new DegreeDTO() : codeSmall);
|
|
|
|
|
return analyseDetail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -273,22 +294,81 @@ public class GraduationProjectQualityInspectService {
|
|
|
|
|
* @param analyseDetailListVO
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public RollPage<AnalyseDetailListDTO> getAnalyseDetailList(AnalyseDetailListVO analyseDetailListVO) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
public RollPage<AnalyseDetailListDTO> getAnalyseDetailList(GraduationProjectAnalyseDetailListVO analyseDetailListVO) {
|
|
|
|
|
RollPage<AnalyseDetailListDTO> rollPage = new RollPage<>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 代码详情
|
|
|
|
|
*
|
|
|
|
|
* @param codeDetailVO
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public CodeDetailDTO getCodeDetail(CodeDetailVO codeDetailVO) {
|
|
|
|
|
return null;
|
|
|
|
|
if (analyseDetailListVO.getCurrentPage() <= 0) {
|
|
|
|
|
analyseDetailListVO.setCurrentPage(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (analyseDetailListVO.getPageSize() >= 10000) {
|
|
|
|
|
analyseDetailListVO.setPageSize(10000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rollPage.setCurrentPage(analyseDetailListVO.getCurrentPage());
|
|
|
|
|
rollPage.setPageSize(analyseDetailListVO.getPageSize());
|
|
|
|
|
|
|
|
|
|
// 作业id+学号
|
|
|
|
|
GraduationProjectTaskInfoDetail graduationProjectTaskInfoDetail = graduationProjectTaskInfoDetailDao.selectById(analyseDetailListVO.getTaskDetailId());
|
|
|
|
|
if (graduationProjectTaskInfoDetail == null) {
|
|
|
|
|
throw new BusinessException(-1, String.format("找不到分析记录detailId:%s", analyseDetailListVO.getTaskDetailId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Project project = projectDao.findByName(graduationProjectTaskInfoDetail.getProjectName());
|
|
|
|
|
if (project == null) {
|
|
|
|
|
throw new BusinessException(-1, String.format("找不到分析记录detailId:%s", analyseDetailListVO.getTaskDetailId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 分析类型
|
|
|
|
|
AnalyseTypeEnum analyseTypeEnum = AnalyseTypeEnum.getAnalyseTypeEnum(analyseDetailListVO.getType());
|
|
|
|
|
|
|
|
|
|
// 严重程度
|
|
|
|
|
DegreeEnum degreeEnum = DegreeEnum.getDegreeEnum(analyseDetailListVO.getDegree());
|
|
|
|
|
String severity = null;
|
|
|
|
|
if (degreeEnum != DegreeEnum.All) {
|
|
|
|
|
severity = degreeEnum.getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Integer pageIssuesCount = issuesDao.getPageIssuesCount(project.getProject_uuid(), analyseTypeEnum.getType(), severity);
|
|
|
|
|
rollPage.setRecordSum(pageIssuesCount);
|
|
|
|
|
if (pageIssuesCount > 0) {
|
|
|
|
|
int start = (analyseDetailListVO.getCurrentPage() - 1) * analyseDetailListVO.getPageSize();
|
|
|
|
|
List<Issues> pageIssues = issuesDao.getPageIssues(project.getProject_uuid(), analyseTypeEnum.getType(), severity, start, analyseDetailListVO.getPageSize());
|
|
|
|
|
processPageIssues(pageIssues, rollPage);
|
|
|
|
|
} else {
|
|
|
|
|
rollPage.setRecordList(new ArrayList(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rollPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void processPageIssues(List<Issues> pageIssues, RollPage<AnalyseDetailListDTO> rollPage) {
|
|
|
|
|
List<AnalyseDetailListDTO> analyseDetailLists = new ArrayList<>(pageIssues.size());
|
|
|
|
|
|
|
|
|
|
for (Issues pageIssue : pageIssues) {
|
|
|
|
|
AnalyseDetailListDTO detailListDTO = new AnalyseDetailListDTO();
|
|
|
|
|
analyseDetailLists.add(detailListDTO);
|
|
|
|
|
|
|
|
|
|
detailListDTO.setName(pageIssue.getName());
|
|
|
|
|
detailListDTO.setDescription(pageIssue.getMessage());
|
|
|
|
|
|
|
|
|
|
detailListDTO.setIssueId(pageIssue.getId());
|
|
|
|
|
detailListDTO.setUuid(pageIssue.getUuid());
|
|
|
|
|
detailListDTO.setRuleId(pageIssue.getRuleId());
|
|
|
|
|
detailListDTO.setFilePath(pageIssue.getPath());
|
|
|
|
|
detailListDTO.setLanguage(pageIssue.getLanguage());
|
|
|
|
|
detailListDTO.setLevel(DegreeEnum.getDegreeEnumByValue(pageIssue.getSeverity()).getDesc());
|
|
|
|
|
try {
|
|
|
|
|
DbIssues.Locations locations = DbIssues.Locations.parseFrom(pageIssue.getLocations());
|
|
|
|
|
detailListDTO.setRowNumber(locations.getTextRange().getStartLine());
|
|
|
|
|
} catch (InvalidProtocolBufferException e) {
|
|
|
|
|
detailListDTO.setRowNumber(0);
|
|
|
|
|
LOGGER.error("Fail to read ISSUES.LOCATIONS [KEE=%s]", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rollPage.setRecordList(analyseDetailLists);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|