parent
8361590210
commit
9cba668ba3
@ -0,0 +1,53 @@
|
||||
package net.educoder.ecsonar.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import net.educoder.ecsonar.model.api.QualityInspect;
|
||||
import net.educoder.ecsonar.model.api.QualityInspectIsCompleted;
|
||||
import net.educoder.ecsonar.model.vo.CloudBrainQualityInspectVO;
|
||||
import net.educoder.ecsonar.services.CloudBrainService;
|
||||
import net.educoder.ecsonar.utils.ResponseResult;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/7/5
|
||||
* @Description: 云脑质量检测
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class CloudBrainController {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(CloudBrainController.class);
|
||||
|
||||
@Autowired
|
||||
private CloudBrainService cloudBrainService;
|
||||
|
||||
@PostMapping("/cloudQualityInspect")
|
||||
public ResponseResult cloudQualityInspect(@RequestBody List<CloudBrainQualityInspectVO> cloudBrainQualityInspectVO) {
|
||||
logger.info("cloudQualityInspect请求参数:{}", JSONObject.toJSONString(cloudBrainQualityInspectVO));
|
||||
if(CollectionUtils.isEmpty(cloudBrainQualityInspectVO)){
|
||||
ResponseResult.error("参数不能为空");
|
||||
}
|
||||
QualityInspect qualityInspect = cloudBrainService.startQualityInspect(cloudBrainQualityInspectVO);
|
||||
return ResponseResult.success(qualityInspect);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 质量检测任务是否完成
|
||||
* @param taskId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/cloudQualityInspectIsCompleted/{taskId}")
|
||||
public ResponseResult<QualityInspectIsCompleted> cloudQualityInspectIsCompleted(@PathVariable String taskId){
|
||||
QualityInspectIsCompleted result = cloudBrainService.cloudQualityInspectIsCompleted(taskId);
|
||||
return ResponseResult.success(result);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package net.educoder.ecsonar.dao;
|
||||
|
||||
import net.educoder.ecsonar.model.CloudTaskInfo;
|
||||
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: 2022/7/5
|
||||
* @Description:
|
||||
*/
|
||||
public interface CloudTaskInfoDao {
|
||||
|
||||
/**
|
||||
* 插入云脑扫描任务信息
|
||||
* @param cloudTaskInfo
|
||||
*/
|
||||
@Insert("insert into cloud_task_info(id, people_number) values(#{id},#{peopleNumber})")
|
||||
void insertCloudTaskInfo(CloudTaskInfo cloudTaskInfo);
|
||||
|
||||
|
||||
/**
|
||||
* 查询任务信息
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select id,status,people_number peopleNumber from cloud_task_info where id=#{id}")
|
||||
CloudTaskInfo queryById(String id);
|
||||
|
||||
/**
|
||||
* 更新任务状态
|
||||
* @param id
|
||||
* @param status
|
||||
*/
|
||||
@Update("update cloud_task_info set status=#{status} where id=#{id}")
|
||||
void updateCloudTaskInfoStatus(@Param("id") String id, @Param("status") Integer status);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package net.educoder.ecsonar.dao;
|
||||
|
||||
import net.educoder.ecsonar.model.CloudTaskInfoDetail;
|
||||
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: 2022/1/18
|
||||
* @Description:
|
||||
*/
|
||||
public interface CloudTaskInfoDetailDao {
|
||||
|
||||
/**
|
||||
* 插入数据
|
||||
*
|
||||
* @param cloudTaskInfoDetail
|
||||
*/
|
||||
@Insert("insert into cloud_task_info_detail(id,task_id,project_name,user_id,language,git_url) values(#{id},#{taskId},#{projectName},#{userId},#{language},#{gitUrl} )")
|
||||
void insertCloudTaskInfoDetail(CloudTaskInfoDetail cloudTaskInfoDetail);
|
||||
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
* @param id
|
||||
* @param status
|
||||
*/
|
||||
@Update("update cloud_task_info_detail set status=#{status},update_time=current_timestamp where id=#{id}")
|
||||
void updateCloudTaskInfoDetailStatus(@Param("id") String id, @Param("status") Integer status);
|
||||
|
||||
|
||||
@Select("select count(1) from cloud_task_info_detail where task_id=#{taskId} and status=1")
|
||||
Integer selectCountByTaskId(String taskId);
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package net.educoder.ecsonar.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/7/5
|
||||
* @Description:
|
||||
*/
|
||||
public class CloudTaskInfoDetail {
|
||||
|
||||
private String id;
|
||||
private String taskId;
|
||||
private String projectName;
|
||||
private String userId;
|
||||
private String language;
|
||||
private String gitUrl;
|
||||
/**
|
||||
* 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 getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
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 getGitUrl() {
|
||||
return gitUrl;
|
||||
}
|
||||
|
||||
public void setGitUrl(String gitUrl) {
|
||||
this.gitUrl = gitUrl;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package net.educoder.ecsonar.model.vo;
|
||||
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/7/5
|
||||
* @Description: 云脑质量分析请求参数
|
||||
*/
|
||||
public class CloudBrainQualityInspectVO {
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 仓库代码id
|
||||
*/
|
||||
private String gitUrl;
|
||||
|
||||
/**
|
||||
* 项目名称
|
||||
*/
|
||||
private String projectName;
|
||||
|
||||
/**
|
||||
* 项目语言
|
||||
*/
|
||||
private String language;
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getGitUrl() {
|
||||
return gitUrl;
|
||||
}
|
||||
|
||||
public void setGitUrl(String gitUrl) {
|
||||
this.gitUrl = gitUrl;
|
||||
}
|
||||
|
||||
public String getProjectName() {
|
||||
return projectName;
|
||||
}
|
||||
|
||||
public void setProjectName(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package net.educoder.ecsonar.task;
|
||||
|
||||
import net.educoder.ecsonar.constant.Constant;
|
||||
import net.educoder.ecsonar.services.DbOperateService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/7/5
|
||||
* @Description:
|
||||
*/
|
||||
public class CloudBrainQueryResultRunnable implements Runnable {
|
||||
|
||||
private final Logger LOGGER = LoggerFactory.getLogger(CloudBrainQueryResultRunnable.class);
|
||||
|
||||
|
||||
private String projectName;
|
||||
private String detailId;
|
||||
private DbOperateService dbOperateService;
|
||||
|
||||
public CloudBrainQueryResultRunnable(String projectName, String detailId, DbOperateService dbOperateService) {
|
||||
this.projectName = projectName;
|
||||
this.detailId = detailId;
|
||||
this.dbOperateService = dbOperateService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
int count = 0;
|
||||
String status;
|
||||
while ((status = dbOperateService.queryCeActivityStatus(projectName)) == null && count++ <= 60) {
|
||||
LOGGER.info("CloudBrainQueryResultRunnable#detailId:[{}],sonar还未执行完,次数:{}", detailId, count);
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
// 查询
|
||||
LOGGER.info("CloudBrainQueryResultRunnable#detailId:[{}], 查询sonar执行状态[{}]", detailId, status);
|
||||
dbOperateService.updateCloudTaskInfoDetail(detailId, Constant.SUCCESS.equals(status) ? 1 : -1);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue