parent
bada54f8cb
commit
0783540035
@ -0,0 +1,38 @@
|
|||||||
|
package net.educoder.ecsonar.controller;
|
||||||
|
|
||||||
|
import net.educoder.ecsonar.model.api.QualityInspect;
|
||||||
|
import net.educoder.ecsonar.model.vo.GraduationProjectQualityInspectVO;
|
||||||
|
import net.educoder.ecsonar.services.GraduationProjectQualityInspectService;
|
||||||
|
import net.educoder.ecsonar.utils.ResponseResult;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: youys
|
||||||
|
* @Date: 2023/8/30
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/graduation/project")
|
||||||
|
public class GraduationProjectController {
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private GraduationProjectQualityInspectService qualityInspectService;
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/qualityInspect")
|
||||||
|
public ResponseResult qualityInspect(@RequestBody List<GraduationProjectQualityInspectVO> qualityInspectVOList){
|
||||||
|
QualityInspect qualityInspect = qualityInspectService.graduationProjectQualityInspect(qualityInspectVOList);
|
||||||
|
return ResponseResult.success(qualityInspect);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package net.educoder.ecsonar.dao;
|
||||||
|
|
||||||
|
import net.educoder.ecsonar.model.GraduationProjectTaskInfo;
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: youys
|
||||||
|
* @Date: 2023/8/31
|
||||||
|
* @Description: 毕设质量分析任务dao
|
||||||
|
*/
|
||||||
|
public interface GraduationProjectTaskInfoDao {
|
||||||
|
|
||||||
|
@Insert("insert into graduation_project_task_info(id,people_number) values(#{id},#{peopleNumber} )")
|
||||||
|
void insertTaskInfo(GraduationProjectTaskInfo taskInfo);
|
||||||
|
|
||||||
|
|
||||||
|
@Update("update graduation_project_task_info set status=#{status},update_time=current_timestamp where id=#{id}")
|
||||||
|
void updateTaskInfoStatus(@Param("id") String id, @Param("status") Integer status);
|
||||||
|
|
||||||
|
|
||||||
|
@Select("select id,status,people_number peopleNumber,create_time createTime,update_time updateTime " +
|
||||||
|
"from graduation_project_task_info where id=#{id}")
|
||||||
|
GraduationProjectTaskInfo selectById(String id);
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
package net.educoder.ecsonar.dao;
|
||||||
|
|
||||||
|
import net.educoder.ecsonar.model.GraduationProjectTaskInfoDetail;
|
||||||
|
import net.educoder.ecsonar.model.TaskInfoDetail;
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: youys
|
||||||
|
* @Date: 2023/8/31
|
||||||
|
* @Description: 毕设质量分析任务详情dao
|
||||||
|
*/
|
||||||
|
public interface GraduationProjectTaskInfoDetailDao {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入数据
|
||||||
|
*
|
||||||
|
* @param taskInfoDetail
|
||||||
|
*/
|
||||||
|
@Insert("insert into graduation_project_task_info_detail(id,task_id,project_name,language,student_id,user_id,name,git_url) " +
|
||||||
|
"values(#{id},#{taskId},#{projectName},#{language},#{studentId},#{userId} ,#{name},#{gitUrl})")
|
||||||
|
void insertTaskInfoDetail(GraduationProjectTaskInfoDetail taskInfoDetail);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新状态
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @param status
|
||||||
|
*/
|
||||||
|
@Update("update graduation_project_task_info_detail " +
|
||||||
|
"set status=#{status},update_time=current_timestamp where id=#{id}")
|
||||||
|
void updateGraduationProjectTaskInfoDetailStatus(@Param("id") String id, @Param("status") Integer status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询taskId执行完的sonar任务数
|
||||||
|
*
|
||||||
|
* @param taskId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select count(1) from graduation_project_task_info_detail " +
|
||||||
|
"where task_id=#{taskId} and status != 0")
|
||||||
|
Integer selectCountByTaskId(@Param("taskId") String taskId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查TaskInfoDetail
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@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 " +
|
||||||
|
"from task_info_detail where id=#{id}")
|
||||||
|
GraduationProjectTaskInfoDetail selectById(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* count
|
||||||
|
*
|
||||||
|
* @param taskId
|
||||||
|
* @param pageSize
|
||||||
|
* @param offset
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select count(1) from graduation_project_task_info_detail " +
|
||||||
|
"where task_id=#{taskId} limit #{pageSize} offset #{offset}")
|
||||||
|
Integer selectGraduationProjectTaskInfoDetailPageCount(@Param("taskId") String taskId,
|
||||||
|
@Param("pageSize") Integer pageSize,
|
||||||
|
@Param("offset") Integer offset);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @param taskId
|
||||||
|
* @param pageSize
|
||||||
|
* @param position
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@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 " +
|
||||||
|
"from graduation_project_task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{position}")
|
||||||
|
List<GraduationProjectTaskInfoDetail> selectGraduationProjectTaskInfoDetailPageList(@Param("taskId") String taskId,
|
||||||
|
@Param("pageSize") Integer pageSize,
|
||||||
|
@Param("position") Integer position);
|
||||||
|
}
|
@ -0,0 +1,139 @@
|
|||||||
|
package net.educoder.ecsonar.model;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: youys
|
||||||
|
* @Date: 2023/8/31
|
||||||
|
* @Description: 毕设质量分析任务详情
|
||||||
|
*/
|
||||||
|
public class GraduationProjectTaskInfoDetail {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
/**
|
||||||
|
* 任务id
|
||||||
|
*/
|
||||||
|
private String taskId;
|
||||||
|
/**
|
||||||
|
* 项目名称
|
||||||
|
*/
|
||||||
|
private String projectName;
|
||||||
|
/**
|
||||||
|
* 语言
|
||||||
|
*/
|
||||||
|
private String language;
|
||||||
|
/**
|
||||||
|
* 学号
|
||||||
|
*/
|
||||||
|
private String studentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* git地址
|
||||||
|
*/
|
||||||
|
private String gitUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 姓名
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 0处理中 1处理成功 -1 处理失败
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
private Date createTime;
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTaskId() {
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskId(String taskId) {
|
||||||
|
this.taskId = taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectName() {
|
||||||
|
return projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectName(String projectName) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStudentId() {
|
||||||
|
return studentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStudentId(String studentId) {
|
||||||
|
this.studentId = studentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(Long userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Integer status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getUpdateTime() {
|
||||||
|
return updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateTime(Date updateTime) {
|
||||||
|
this.updateTime = updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanguage() {
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLanguage(String language) {
|
||||||
|
this.language = language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGitUrl() {
|
||||||
|
return gitUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGitUrl(String gitUrl) {
|
||||||
|
this.gitUrl = gitUrl;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package net.educoder.ecsonar.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: youys
|
||||||
|
* @Date: 2023/8/30
|
||||||
|
* @Description: 毕设质量分析请求参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class GraduationProjectQualityInspectVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 语言
|
||||||
|
*/
|
||||||
|
private String language;
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
/**
|
||||||
|
* git地址
|
||||||
|
*/
|
||||||
|
private String gitUrl;
|
||||||
|
/**
|
||||||
|
* 学号
|
||||||
|
*/
|
||||||
|
private String studentId;
|
||||||
|
/**
|
||||||
|
* 姓名
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
}
|
@ -0,0 +1,175 @@
|
|||||||
|
package net.educoder.ecsonar.services;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import net.educoder.ecsonar.dao.*;
|
||||||
|
import net.educoder.ecsonar.exception.BusinessException;
|
||||||
|
import net.educoder.ecsonar.model.*;
|
||||||
|
import net.educoder.ecsonar.model.api.QualityInspect;
|
||||||
|
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.task.GraduationProjectQualityInspectRunnable;
|
||||||
|
import net.educoder.ecsonar.utils.IdUtils;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: youys
|
||||||
|
* @Date: 2023/8/31
|
||||||
|
* @Description: 毕设质量分析service
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class GraduationProjectQualityInspectService {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(GraduationProjectQualityInspectService.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GraduationProjectTaskInfoDao taskInfoDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GraduationProjectTaskInfoDetailDao taskInfoDetailDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DbOperateService dbOperateService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SonarService sonarService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReportService reportService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IssuesDao issuesDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProjectDao projectDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FileSourceDao fileSourceDao;
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("sonarScannerPool")
|
||||||
|
private ExecutorService sonarScannerPool;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("sonarQueryResultPool")
|
||||||
|
private ExecutorService sonarQueryResultPool;
|
||||||
|
|
||||||
|
|
||||||
|
public QualityInspect graduationProjectQualityInspect(List<GraduationProjectQualityInspectVO> qualityInspectVOList) {
|
||||||
|
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(qualityInspectVOList)) {
|
||||||
|
throw new BusinessException(2, "用户数据不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
GraduationProjectTaskInfo taskInfo = new GraduationProjectTaskInfo();
|
||||||
|
taskInfo.setId(IdUtils.nextStrId());
|
||||||
|
taskInfo.setPeopleNumber(qualityInspectVOList.size());
|
||||||
|
|
||||||
|
taskInfoDao.insertTaskInfo(taskInfo);
|
||||||
|
LOGGER.info("taskId:{}, {}个人提交了代码", taskInfo.getId(), qualityInspectVOList.size());
|
||||||
|
|
||||||
|
for (GraduationProjectQualityInspectVO qualityInspectVO : qualityInspectVOList) {
|
||||||
|
|
||||||
|
GraduationProjectTaskInfoDetail graduationProjectTaskInfoDetail = new GraduationProjectTaskInfoDetail();
|
||||||
|
graduationProjectTaskInfoDetail.setId(IdUtils.nextStrId());
|
||||||
|
graduationProjectTaskInfoDetail.setTaskId(taskInfo.getId());
|
||||||
|
graduationProjectTaskInfoDetail.setProjectName(String.format("%s-%s", qualityInspectVO.getStudentId(), RandomUtil.randomString(8)));
|
||||||
|
graduationProjectTaskInfoDetail.setName(qualityInspectVO.getName());
|
||||||
|
graduationProjectTaskInfoDetail.setStudentId(qualityInspectVO.getStudentId());
|
||||||
|
graduationProjectTaskInfoDetail.setUserId(qualityInspectVO.getUserId());
|
||||||
|
graduationProjectTaskInfoDetail.setGitUrl(qualityInspectVO.getGitUrl());
|
||||||
|
graduationProjectTaskInfoDetail.setLanguage(qualityInspectVO.getLanguage());
|
||||||
|
|
||||||
|
taskInfoDetailDao.insertTaskInfoDetail(graduationProjectTaskInfoDetail);
|
||||||
|
|
||||||
|
// 提交一个sonar扫描任务
|
||||||
|
GraduationProjectQualityInspectRunnable runnable = new GraduationProjectQualityInspectRunnable(taskInfo.getId(),
|
||||||
|
qualityInspectVO.getLanguage(), graduationProjectTaskInfoDetail, sonarQueryResultPool);
|
||||||
|
runnable.setDbOperateService(dbOperateService);
|
||||||
|
runnable.setSonarService(sonarService);
|
||||||
|
|
||||||
|
// 提交任务
|
||||||
|
sonarScannerPool.execute(runnable);
|
||||||
|
}
|
||||||
|
// 提交之后返回taskId
|
||||||
|
return new QualityInspect(taskInfo.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public RollPage<QualityInspectResultData> qualityInspectResultQuery(Integer pageNum, Integer pageSize, String taskId) {
|
||||||
|
RollPage<QualityInspectResultData> rollPage = new RollPage();
|
||||||
|
rollPage.setCurrentPage(pageNum);
|
||||||
|
rollPage.setPageSize(pageSize);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return rollPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QualityInspectIsCompleted qualityInspectIsCompleted(String taskId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阻断 严重 主要 次要
|
||||||
|
* 10 5 3 1
|
||||||
|
*
|
||||||
|
* @param resultData
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private BigDecimal calcQualityScore(QualityInspectResultData resultData) {
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分析详情
|
||||||
|
*
|
||||||
|
* @param analyseDetailVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public AnalyseDetailDTO getAnalyseDetail(AnalyseDetailVO analyseDetailVO) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 风险详情列表
|
||||||
|
*
|
||||||
|
* @param analyseDetailListVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public RollPage<AnalyseDetailListDTO> getAnalyseDetailList(AnalyseDetailListVO analyseDetailListVO) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码详情
|
||||||
|
*
|
||||||
|
* @param codeDetailVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CodeDetailDTO getCodeDetail(CodeDetailVO codeDetailVO) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void processPageIssues(List<Issues> pageIssues, RollPage<AnalyseDetailListDTO> rollPage) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
package net.educoder.ecsonar.task;
|
||||||
|
|
||||||
|
import net.educoder.ecsonar.constant.Constant;
|
||||||
|
import net.educoder.ecsonar.model.GraduationProjectTaskInfoDetail;
|
||||||
|
import net.educoder.ecsonar.model.SonarScannerParam;
|
||||||
|
import net.educoder.ecsonar.services.DbOperateService;
|
||||||
|
import net.educoder.ecsonar.services.SonarService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: youys
|
||||||
|
* @Date: 2023/8/31
|
||||||
|
* @Description: 毕业设计质量检测任务
|
||||||
|
*/
|
||||||
|
public class GraduationProjectQualityInspectRunnable implements Runnable {
|
||||||
|
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(GraduationProjectQualityInspectRunnable.class);
|
||||||
|
|
||||||
|
private String taskId;
|
||||||
|
|
||||||
|
public String language;
|
||||||
|
|
||||||
|
private ExecutorService queryResultPool;
|
||||||
|
private GraduationProjectTaskInfoDetail taskInfoDetail;
|
||||||
|
private DbOperateService dbOperateService;
|
||||||
|
private SonarService sonarService;
|
||||||
|
|
||||||
|
private static final String SUCCESS = "SUCCESS";
|
||||||
|
|
||||||
|
public GraduationProjectQualityInspectRunnable(String taskId, String language,
|
||||||
|
GraduationProjectTaskInfoDetail taskInfoDetail,
|
||||||
|
ExecutorService queryResultPool) {
|
||||||
|
this.taskId = taskId;
|
||||||
|
this.language = language;
|
||||||
|
this.taskInfoDetail = taskInfoDetail;
|
||||||
|
this.queryResultPool = queryResultPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String projectName = taskInfoDetail.getProjectName();
|
||||||
|
String path = String.format("/tmp/%s/%s/", taskId, projectName);
|
||||||
|
|
||||||
|
// 写完所有文件开始用sonar进行质量分析
|
||||||
|
SonarScannerParam param = new SonarScannerParam(projectName, path);
|
||||||
|
if (Constant.C.equalsIgnoreCase(language) || Constant.CXX.equalsIgnoreCase(language)) {
|
||||||
|
String resultPath = String.format("/tmp/%s", taskId);
|
||||||
|
File f = new File(resultPath);
|
||||||
|
if (!f.exists()) {
|
||||||
|
f.mkdirs();
|
||||||
|
}
|
||||||
|
param.setCppCheckReportPath(resultPath + String.format("/%s-result.xml", projectName));
|
||||||
|
|
||||||
|
}
|
||||||
|
// 调用sonar服务
|
||||||
|
LOGGER.info("taskId:{}, projectName:{}, detailId:{} 开始调用sonar分析,语言:{}", taskId, projectName, taskInfoDetail.getId(), language);
|
||||||
|
// sonarUrl 启动多个,随机一个
|
||||||
|
sonarService.sonar(language, param);
|
||||||
|
|
||||||
|
// 提交一个查结果的任务
|
||||||
|
GraduationProjectQueryResultRunnable queryResultRunnable = new GraduationProjectQueryResultRunnable(projectName, taskInfoDetail.getId(), dbOperateService);
|
||||||
|
LOGGER.info("taskId:{}, projectName:{}, detailId:{} 提交了查询结果的任务", taskId, projectName, taskInfoDetail.getId());
|
||||||
|
Future<String> submit = queryResultPool.submit(queryResultRunnable);
|
||||||
|
String status;
|
||||||
|
try {
|
||||||
|
status = submit.get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("GraduationProjectQueryResultRunnable is Exception", e);
|
||||||
|
status = "FAILED";
|
||||||
|
}
|
||||||
|
dbOperateService.updateGraduationProjectTaskInfoDetail(taskInfoDetail.getId(), SUCCESS.equals(status) ? 1 : -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setDbOperateService(DbOperateService dbOperateService) {
|
||||||
|
this.dbOperateService = dbOperateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSonarService(SonarService sonarService) {
|
||||||
|
this.sonarService = sonarService;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package net.educoder.ecsonar.task;
|
||||||
|
|
||||||
|
import net.educoder.ecsonar.services.DbOperateService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: youys
|
||||||
|
* @Date: 2023/8/31
|
||||||
|
* @Description: 毕业设计 查询分析结果
|
||||||
|
*/
|
||||||
|
public class GraduationProjectQueryResultRunnable implements Callable<String> {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(GraduationProjectQueryResultRunnable.class);
|
||||||
|
|
||||||
|
private String projectName;
|
||||||
|
private String detailId;
|
||||||
|
private DbOperateService dbOperateService;
|
||||||
|
|
||||||
|
public GraduationProjectQueryResultRunnable(String projectName, String detailId, DbOperateService dbOperateService) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
this.detailId = detailId;
|
||||||
|
this.dbOperateService = dbOperateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String call() throws Exception {
|
||||||
|
int count = 0;
|
||||||
|
String status;
|
||||||
|
while ((status = dbOperateService.queryCeActivityStatus(projectName)) == null && count++ <= 60) {
|
||||||
|
LOGGER.info("detailId:[{}],sonar还未执行完,次数:{}", detailId, count);
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 查询
|
||||||
|
LOGGER.info("detailId:[{}], 查询sonar执行状态[{}]", detailId, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue