feat(GraduationProject) 毕设质量分析

sonar7.7
youys 1 year ago
parent 43d5ed2be5
commit cd638b475f

@ -4,13 +4,18 @@ import net.educoder.ecsonar.model.RollPage;
import net.educoder.ecsonar.model.api.QualityInspect; import net.educoder.ecsonar.model.api.QualityInspect;
import net.educoder.ecsonar.model.api.QualityInspectIsCompleted; 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.vo.GraduationProjectQualityInspectVO; import net.educoder.ecsonar.model.dto.AnalyseDetailDTO;
import net.educoder.ecsonar.model.vo.GraduationQualityInspectResultQueryVO; import net.educoder.ecsonar.model.dto.AnalyseDetailListDTO;
import net.educoder.ecsonar.model.dto.CodeDetailDTO;
import net.educoder.ecsonar.model.dto.ProblemAnalysisDTO;
import net.educoder.ecsonar.model.vo.*;
import net.educoder.ecsonar.services.GraduationProjectQualityInspectService; import net.educoder.ecsonar.services.GraduationProjectQualityInspectService;
import net.educoder.ecsonar.services.QualityInspectService;
import net.educoder.ecsonar.utils.ResponseResult; import net.educoder.ecsonar.utils.ResponseResult;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List; import java.util.List;
/** /**
@ -27,14 +32,18 @@ public class GraduationProjectController {
@Resource @Resource
private GraduationProjectQualityInspectService graduationProjectQualityInspect; private GraduationProjectQualityInspectService graduationProjectQualityInspect;
@Resource
private QualityInspectService qualityInspectService;
/** /**
* *
*
* @param qualityInspectVOList * @param qualityInspectVOList
* @return * @return
*/ */
@PostMapping("/qualityInspect") @PostMapping("/qualityInspect")
public ResponseResult graduationQualityInspect(@RequestBody List<GraduationProjectQualityInspectVO> qualityInspectVOList){ public ResponseResult graduationQualityInspect(@RequestBody List<GraduationProjectQualityInspectVO> qualityInspectVOList) {
QualityInspect qualityInspect = graduationProjectQualityInspect.graduationProjectQualityInspect(qualityInspectVOList); QualityInspect qualityInspect = graduationProjectQualityInspect.graduationProjectQualityInspect(qualityInspectVOList);
return ResponseResult.success(qualityInspect); return ResponseResult.success(qualityInspect);
} }
@ -45,8 +54,7 @@ public class GraduationProjectController {
* @param graduationQualityInspectResultQueryVO * @param graduationQualityInspectResultQueryVO
* @return * @return
*/ */
@RequestMapping(value = "qualityInspectResultQuery", method = RequestMethod.GET) @PostMapping(value = "qualityInspectResultQuery")
@ResponseBody
public ResponseResult graduationQualityInspectResultQuery(@RequestBody GraduationQualityInspectResultQueryVO graduationQualityInspectResultQueryVO) { public ResponseResult graduationQualityInspectResultQuery(@RequestBody GraduationQualityInspectResultQueryVO graduationQualityInspectResultQueryVO) {
QualityInspectIsCompleted isCompleted = graduationProjectQualityInspect.qualityInspectIsCompleted(graduationQualityInspectResultQueryVO.getTaskId()); QualityInspectIsCompleted isCompleted = graduationProjectQualityInspect.qualityInspectIsCompleted(graduationQualityInspectResultQueryVO.getTaskId());
if (isCompleted.getCompleted() != 1) { if (isCompleted.getCompleted() != 1) {
@ -58,5 +66,51 @@ public class GraduationProjectController {
} }
/**
*
*
* @return
*/
@GetMapping("/analyseDetail")
public ResponseResult<AnalyseDetailDTO> analyseDetail(@RequestParam("taskDetailId") String taskDetailId) {
AnalyseDetailDTO analyseDetailDTO = graduationProjectQualityInspect.getAnalyseDetail(taskDetailId);
return ResponseResult.success(analyseDetailDTO);
}
/**
*
*
* @return
*/
@GetMapping("/analyseDetailList")
public ResponseResult analyseDetailList(@Valid GraduationProjectAnalyseDetailListVO analyseDetailListVO) {
RollPage<AnalyseDetailListDTO> rollPage = graduationProjectQualityInspect.getAnalyseDetailList(analyseDetailListVO);
return ResponseResult.success(rollPage);
}
/**
*
*
* @return
*/
@GetMapping("/problemAnalysis")
public ResponseResult problemAnalysis(@RequestParam Integer ruleId) {
ProblemAnalysisDTO problemAnalysis = qualityInspectService.getProblemAnalysis(ruleId);
return ResponseResult.success(problemAnalysis);
}
/**
*
*
* @return
*/
@GetMapping("/codeDetail")
public ResponseResult<CodeDetailDTO> codeDetail(@Valid CodeDetailVO codeDetailVO) {
CodeDetailDTO codeDetail = qualityInspectService.getCodeDetail(codeDetailVO);
return ResponseResult.success(codeDetail);
}
} }

@ -53,7 +53,7 @@ public interface GraduationProjectTaskInfoDetailDao {
*/ */
@Select("select id,task_id taskId,project_name projectName,language,student_id studentId,user_id " + @Select("select id,task_id taskId,project_name projectName,language,student_id studentId,user_id " +
"userId,name,git_url gitUrl,status,create_time createTime,update_time updateTime " + "userId,name,git_url gitUrl,status,create_time createTime,update_time updateTime " +
"from task_info_detail where id=#{id}") "from graduation_project_task_info_detail where id=#{id}")
GraduationProjectTaskInfoDetail selectById(String id); GraduationProjectTaskInfoDetail selectById(String id);
/** /**

@ -62,6 +62,11 @@ public class QualityInspectResultData {
*/ */
private BigDecimal qualityScore; private BigDecimal qualityScore;
/**
* id
*/
private String taskDetailId;
public String getMentor() { public String getMentor() {
return mentor; return mentor;
} }
@ -149,4 +154,12 @@ public class QualityInspectResultData {
public void setQualityScore(BigDecimal qualityScore) { public void setQualityScore(BigDecimal qualityScore) {
this.qualityScore = qualityScore; this.qualityScore = qualityScore;
} }
public String getTaskDetailId() {
return taskDetailId;
}
public void setTaskDetailId(String taskDetailId) {
this.taskDetailId = taskDetailId;
}
} }

@ -2,6 +2,9 @@ package net.educoder.ecsonar.model.vo;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/** /**
* @Author: youys * @Author: youys
* @Date: 2022/9/27 * @Date: 2022/9/27
@ -11,7 +14,12 @@ import lombok.Data;
public class CodeDetailVO { public class CodeDetailVO {
@NotBlank(message = "uuid不能为空")
private String uuid; private String uuid;
@NotNull(message = "ruleId不能为空")
private Integer ruleId; private Integer ruleId;
@NotNull(message = "issueId不能为空")
private Long issueId; private Long issueId;
} }

@ -0,0 +1,33 @@
package net.educoder.ecsonar.model.vo;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @Author: youys
* @Date: 2022/12/20
* @Description:
*/
@Data
public class GraduationProjectAnalyseDetailListVO extends PageVO {
/**
*
* 1
* 2 bug
* 3
*/
private Integer type;
/**
*
* all
*/
private Integer degree;
@NotBlank(message = "作业id不能为空")
private String taskDetailId;
}

@ -13,13 +13,9 @@ import javax.validation.constraints.NotBlank;
*/ */
@Data @Data
public class GraduationQualityInspectResultQueryVO { public class GraduationQualityInspectResultQueryVO extends PageVO{
private Integer pageSize;
@Min(value = 1, message = "起始页最少是1")
private Integer pageNumber;
@NotBlank(message = "任务id不能为空") @NotBlank(message = "任务id不能为空")
private String taskId; private String taskId;

@ -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);
* }
* @param codeDetailVO
* @return if (analyseDetailListVO.getPageSize() >= 10000) {
*/ analyseDetailListVO.setPageSize(10000);
public CodeDetailDTO getCodeDetail(CodeDetailVO codeDetailVO) { }
return null;
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) { 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);
} }

Loading…
Cancel
Save