From 0783540035ecccbf0afa2d2bb6a8f90d2c2baf5b Mon Sep 17 00:00:00 2001 From: youys <1272586223@qq.com> Date: Thu, 31 Aug 2023 18:18:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(api)=20=E6=AF=95=E8=AE=BE=E8=B4=A8?= =?UTF-8?q?=E9=87=8F=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GraduationProjectController.java | 38 ++++ .../dao/GraduationProjectTaskInfoDao.java | 27 +++ .../GraduationProjectTaskInfoDetailDao.java | 87 +++++++++ .../model/GraduationProjectTaskInfo.java | 61 ++++++ .../GraduationProjectTaskInfoDetail.java | 139 ++++++++++++++ .../vo/GraduationProjectQualityInspectVO.java | 33 ++++ .../ecsonar/services/DbOperateService.java | 6 + ...raduationProjectQualityInspectService.java | 175 ++++++++++++++++++ .../ecsonar/services/SonarService.java | 2 + ...aduationProjectQualityInspectRunnable.java | 92 +++++++++ .../GraduationProjectQueryResultRunnable.java | 44 +++++ .../ecsonar/task/QualityInspectRunnable.java | 2 +- .../task/SonarQueryResultRunnable.java | 2 +- 13 files changed, 706 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/educoder/ecsonar/controller/GraduationProjectController.java create mode 100644 src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDao.java create mode 100644 src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDetailDao.java create mode 100644 src/main/java/net/educoder/ecsonar/model/GraduationProjectTaskInfo.java create mode 100644 src/main/java/net/educoder/ecsonar/model/GraduationProjectTaskInfoDetail.java create mode 100644 src/main/java/net/educoder/ecsonar/model/vo/GraduationProjectQualityInspectVO.java create mode 100644 src/main/java/net/educoder/ecsonar/services/GraduationProjectQualityInspectService.java create mode 100644 src/main/java/net/educoder/ecsonar/task/GraduationProjectQualityInspectRunnable.java create mode 100644 src/main/java/net/educoder/ecsonar/task/GraduationProjectQueryResultRunnable.java diff --git a/src/main/java/net/educoder/ecsonar/controller/GraduationProjectController.java b/src/main/java/net/educoder/ecsonar/controller/GraduationProjectController.java new file mode 100644 index 0000000..c37e9e8 --- /dev/null +++ b/src/main/java/net/educoder/ecsonar/controller/GraduationProjectController.java @@ -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 qualityInspectVOList){ + QualityInspect qualityInspect = qualityInspectService.graduationProjectQualityInspect(qualityInspectVOList); + return ResponseResult.success(qualityInspect); + } + + + +} diff --git a/src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDao.java b/src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDao.java new file mode 100644 index 0000000..b40500e --- /dev/null +++ b/src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDao.java @@ -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); +} diff --git a/src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDetailDao.java b/src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDetailDao.java new file mode 100644 index 0000000..47c0175 --- /dev/null +++ b/src/main/java/net/educoder/ecsonar/dao/GraduationProjectTaskInfoDetailDao.java @@ -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 selectGraduationProjectTaskInfoDetailPageList(@Param("taskId") String taskId, + @Param("pageSize") Integer pageSize, + @Param("position") Integer position); +} diff --git a/src/main/java/net/educoder/ecsonar/model/GraduationProjectTaskInfo.java b/src/main/java/net/educoder/ecsonar/model/GraduationProjectTaskInfo.java new file mode 100644 index 0000000..a4f2d8d --- /dev/null +++ b/src/main/java/net/educoder/ecsonar/model/GraduationProjectTaskInfo.java @@ -0,0 +1,61 @@ +package net.educoder.ecsonar.model; + +import java.util.Date; + +/** + * @Author: youys + * @Date: 2023/8/31 + * @Description: 毕设质量分析任务 + */ +public class GraduationProjectTaskInfo { + + private String id; + /** + * 状态 0:处理中 1成功 + */ + private Integer status; + private Integer peopleNumber; + private Date createTime; + private Date updateTime; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public Integer getPeopleNumber() { + return peopleNumber; + } + + public void setPeopleNumber(Integer peopleNumber) { + this.peopleNumber = peopleNumber; + } + + 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; + } + +} diff --git a/src/main/java/net/educoder/ecsonar/model/GraduationProjectTaskInfoDetail.java b/src/main/java/net/educoder/ecsonar/model/GraduationProjectTaskInfoDetail.java new file mode 100644 index 0000000..f3d794c --- /dev/null +++ b/src/main/java/net/educoder/ecsonar/model/GraduationProjectTaskInfoDetail.java @@ -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; + } +} diff --git a/src/main/java/net/educoder/ecsonar/model/vo/GraduationProjectQualityInspectVO.java b/src/main/java/net/educoder/ecsonar/model/vo/GraduationProjectQualityInspectVO.java new file mode 100644 index 0000000..42e0595 --- /dev/null +++ b/src/main/java/net/educoder/ecsonar/model/vo/GraduationProjectQualityInspectVO.java @@ -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; +} diff --git a/src/main/java/net/educoder/ecsonar/services/DbOperateService.java b/src/main/java/net/educoder/ecsonar/services/DbOperateService.java index 24823e3..d8b7fd4 100644 --- a/src/main/java/net/educoder/ecsonar/services/DbOperateService.java +++ b/src/main/java/net/educoder/ecsonar/services/DbOperateService.java @@ -32,6 +32,8 @@ public class DbOperateService { @Autowired private CloudTaskInfoDetailDao cloudTaskInfoDetailDao; + private GraduationProjectTaskInfoDao graduationProjectTaskInfoDao; + /** * 根据id查询用户传的code * @@ -64,6 +66,10 @@ public class DbOperateService { taskInfoDetailDao.updateTaskInfoDetailStatus(id, status); } + public void updateGraduationProjectTaskInfoDetail(String id, Integer status) { + graduationProjectTaskInfoDao.updateTaskInfoStatus(id, status); + } + public void updateCloudTaskInfoDetail(String id, Integer status) { cloudTaskInfoDetailDao.updateCloudTaskInfoDetailStatus(id, status); } diff --git a/src/main/java/net/educoder/ecsonar/services/GraduationProjectQualityInspectService.java b/src/main/java/net/educoder/ecsonar/services/GraduationProjectQualityInspectService.java new file mode 100644 index 0000000..7826f97 --- /dev/null +++ b/src/main/java/net/educoder/ecsonar/services/GraduationProjectQualityInspectService.java @@ -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 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 qualityInspectResultQuery(Integer pageNum, Integer pageSize, String taskId) { + RollPage 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 getAnalyseDetailList(AnalyseDetailListVO analyseDetailListVO) { + return null; + } + + /** + * 代码详情 + * + * @param codeDetailVO + * @return + */ + public CodeDetailDTO getCodeDetail(CodeDetailVO codeDetailVO) { + return null; + } + + + private void processPageIssues(List pageIssues, RollPage rollPage) { + } + + +} diff --git a/src/main/java/net/educoder/ecsonar/services/SonarService.java b/src/main/java/net/educoder/ecsonar/services/SonarService.java index bc66a31..5356490 100644 --- a/src/main/java/net/educoder/ecsonar/services/SonarService.java +++ b/src/main/java/net/educoder/ecsonar/services/SonarService.java @@ -180,6 +180,8 @@ public class SonarService { if (consumer != null) { log.info("语言:{},projectName:{},path:{}找到了consumer", language, sonarScannerParam.getProjectKey(),sonarScannerParam.getProjectPath()); consumer.accept(sonarScannerParam); + }else{ + sonar(sonarScannerParam.getProjectPath(), sonarScannerParam.getProjectKey()); } } diff --git a/src/main/java/net/educoder/ecsonar/task/GraduationProjectQualityInspectRunnable.java b/src/main/java/net/educoder/ecsonar/task/GraduationProjectQualityInspectRunnable.java new file mode 100644 index 0000000..636373b --- /dev/null +++ b/src/main/java/net/educoder/ecsonar/task/GraduationProjectQualityInspectRunnable.java @@ -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 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; + } +} diff --git a/src/main/java/net/educoder/ecsonar/task/GraduationProjectQueryResultRunnable.java b/src/main/java/net/educoder/ecsonar/task/GraduationProjectQueryResultRunnable.java new file mode 100644 index 0000000..4f17895 --- /dev/null +++ b/src/main/java/net/educoder/ecsonar/task/GraduationProjectQueryResultRunnable.java @@ -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 { + + 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; + } +} diff --git a/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java b/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java index c0c2b77..169654b 100644 --- a/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java +++ b/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java @@ -22,7 +22,7 @@ import java.util.concurrent.ExecutorService; /** * @Author: youys * @Date: 2022/1/18 - * @Description: 质量检测任务 + * @Description: 教学课堂质量检测任务 */ public class QualityInspectRunnable implements Runnable { diff --git a/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java b/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java index e22a247..98e4b1f 100644 --- a/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java +++ b/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java @@ -7,7 +7,7 @@ import org.slf4j.LoggerFactory; /** * @Author: youys * @Date: 2022/1/18 - * @Description: 查询分析结果 + * @Description: 教学课堂质量分析 查询分析结果 */ public class SonarQueryResultRunnable implements Runnable {