|
|
@ -1,7 +1,10 @@
|
|
|
|
package net.educoder.ecsonar.services;
|
|
|
|
package net.educoder.ecsonar.services;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
|
|
|
import com.google.protobuf.InvalidProtocolBufferException;
|
|
|
|
import net.educoder.ecsonar.dao.*;
|
|
|
|
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.exception.BusinessException;
|
|
|
|
import net.educoder.ecsonar.model.*;
|
|
|
|
import net.educoder.ecsonar.model.*;
|
|
|
|
import net.educoder.ecsonar.model.api.Quality;
|
|
|
|
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.api.QualityInspectResultData;
|
|
|
|
import net.educoder.ecsonar.model.dto.*;
|
|
|
|
import net.educoder.ecsonar.model.dto.*;
|
|
|
|
import net.educoder.ecsonar.model.vo.*;
|
|
|
|
import net.educoder.ecsonar.model.vo.*;
|
|
|
|
|
|
|
|
import net.educoder.ecsonar.protobuf.DbIssues;
|
|
|
|
import net.educoder.ecsonar.task.GraduationProjectQualityInspectRunnable;
|
|
|
|
import net.educoder.ecsonar.task.GraduationProjectQualityInspectRunnable;
|
|
|
|
import net.educoder.ecsonar.utils.IdUtils;
|
|
|
|
import net.educoder.ecsonar.utils.IdUtils;
|
|
|
|
import net.educoder.ecsonar.utils.SystemUtil;
|
|
|
|
import net.educoder.ecsonar.utils.SystemUtil;
|
|
|
@ -57,9 +61,6 @@ public class GraduationProjectQualityInspectService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ProjectDao projectDao;
|
|
|
|
private ProjectDao projectDao;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private FileSourceDao fileSourceDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
@Qualifier("sonarScannerPool")
|
|
|
|
@Qualifier("sonarScannerPool")
|
|
|
@ -114,13 +115,13 @@ public class GraduationProjectQualityInspectService {
|
|
|
|
|
|
|
|
|
|
|
|
public RollPage<QualityInspectResultData> qualityInspectResultQuery(GraduationQualityInspectResultQueryVO queryVO) {
|
|
|
|
public RollPage<QualityInspectResultData> qualityInspectResultQuery(GraduationQualityInspectResultQueryVO queryVO) {
|
|
|
|
int pageSize = queryVO.getPageSize();
|
|
|
|
int pageSize = queryVO.getPageSize();
|
|
|
|
int pageNum = queryVO.getPageNumber();
|
|
|
|
int pageNum = queryVO.getCurrentPage();
|
|
|
|
|
|
|
|
|
|
|
|
RollPage<QualityInspectResultData> rollPage = new RollPage<>();
|
|
|
|
RollPage<QualityInspectResultData> rollPage = new RollPage<>();
|
|
|
|
rollPage.setCurrentPage(pageNum);
|
|
|
|
rollPage.setCurrentPage(pageNum);
|
|
|
|
rollPage.setPageSize(pageSize);
|
|
|
|
rollPage.setPageSize(pageSize);
|
|
|
|
|
|
|
|
|
|
|
|
int offset = (queryVO.getPageNumber() - 1) * queryVO.getPageSize();
|
|
|
|
int offset = (pageNum - 1) * queryVO.getPageSize();
|
|
|
|
Integer totalCount = graduationProjectTaskInfoDetailDao.
|
|
|
|
Integer totalCount = graduationProjectTaskInfoDetailDao.
|
|
|
|
selectGraduationProjectTaskInfoDetailPageCount(queryVO.getTaskId(), pageSize, offset);
|
|
|
|
selectGraduationProjectTaskInfoDetailPageCount(queryVO.getTaskId(), pageSize, offset);
|
|
|
|
rollPage.setRecordSum(totalCount);
|
|
|
|
rollPage.setRecordSum(totalCount);
|
|
|
@ -141,6 +142,7 @@ public class GraduationProjectQualityInspectService {
|
|
|
|
resultData.setName(taskInfoDetail.getName());
|
|
|
|
resultData.setName(taskInfoDetail.getName());
|
|
|
|
resultData.setStudentId(taskInfoDetail.getStudentId());
|
|
|
|
resultData.setStudentId(taskInfoDetail.getStudentId());
|
|
|
|
resultData.setUserId(taskInfoDetail.getUserId());
|
|
|
|
resultData.setUserId(taskInfoDetail.getUserId());
|
|
|
|
|
|
|
|
resultData.setTaskDetailId(taskInfoDetail.getId());
|
|
|
|
|
|
|
|
|
|
|
|
Metrics metrics = reportService.getMetrics(taskInfoDetail.getProjectName());
|
|
|
|
Metrics metrics = reportService.getMetrics(taskInfoDetail.getProjectName());
|
|
|
|
|
|
|
|
|
|
|
@ -259,11 +261,30 @@ public class GraduationProjectQualityInspectService {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 分析详情
|
|
|
|
* 分析详情
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param analyseDetailVO
|
|
|
|
* @param taskDetailId
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public AnalyseDetailDTO getAnalyseDetail(AnalyseDetailVO analyseDetailVO) {
|
|
|
|
public AnalyseDetailDTO getAnalyseDetail(String taskDetailId) {
|
|
|
|
return null;
|
|
|
|
// 作业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
|
|
|
|
* @param analyseDetailListVO
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public RollPage<AnalyseDetailListDTO> getAnalyseDetailList(AnalyseDetailListVO analyseDetailListVO) {
|
|
|
|
public RollPage<AnalyseDetailListDTO> getAnalyseDetailList(GraduationProjectAnalyseDetailListVO analyseDetailListVO) {
|
|
|
|
return null;
|
|
|
|
RollPage<AnalyseDetailListDTO> rollPage = new RollPage<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (analyseDetailListVO.getCurrentPage() <= 0) {
|
|
|
|
|
|
|
|
analyseDetailListVO.setCurrentPage(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
if (analyseDetailListVO.getPageSize() >= 10000) {
|
|
|
|
* 代码详情
|
|
|
|
analyseDetailListVO.setPageSize(10000);
|
|
|
|
*
|
|
|
|
}
|
|
|
|
* @param codeDetailVO
|
|
|
|
|
|
|
|
* @return
|
|
|
|
rollPage.setCurrentPage(analyseDetailListVO.getCurrentPage());
|
|
|
|
*/
|
|
|
|
rollPage.setPageSize(analyseDetailListVO.getPageSize());
|
|
|
|
public CodeDetailDTO getCodeDetail(CodeDetailVO codeDetailVO) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
// 作业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) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|