Compare commits
No commits in common. "ad63181c335c49d51c42c699571c24fb935e1b22" and "ef72a38345f0d8f2df1b2f449d57fb9968b9396e" have entirely different histories.
ad63181c33
...
ef72a38345
@ -1,17 +0,0 @@
|
||||
package cd.casic.ci.common.pipeline.req.stage;
|
||||
|
||||
import cd.casic.ci.common.pipeline.req.task.TaskCreateReq;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class StageCreateReq {
|
||||
//@ApiProperty(name = "stageId",desc="id")
|
||||
private String stageId;
|
||||
//@ApiProperty(name="pipelineId",desc="流水线id")
|
||||
private String pipelineId;
|
||||
//@ApiProperty(name="stageSort",desc="阶段顺序")
|
||||
private int stageSort;
|
||||
//@ApiProperty(name = "parentId",desc="主阶段")
|
||||
private String parentId;
|
||||
private TaskCreateReq task;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package cd.casic.ci.common.pipeline.req.task;
|
||||
|
||||
import lombok.Data;
|
||||
import org.json.JSONObject;
|
||||
@Data
|
||||
public class TaskCreateReq {
|
||||
private String stageId;
|
||||
private String taskName;
|
||||
private String pipelineId;
|
||||
private String taskType;
|
||||
private String taskSort;
|
||||
private JSONObject taskProperties;
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
package cd.casic.ci.process.process.service.stage.impl;
|
||||
|
||||
|
||||
import cd.casic.ci.common.pipeline.req.stage.StageReq;
|
||||
import cd.casic.ci.common.pipeline.resp.stage.StageResp;
|
||||
|
||||
import cd.casic.ci.process.process.dal.pipeline.PipStageDao;
|
||||
import cd.casic.ci.process.process.dataObject.stage.PipStage;
|
||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||
@ -16,17 +14,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cd.casic.ci.process.constant.PipelineFinalConstant.TASK_TYPE_CODE;
|
||||
|
||||
@ -183,53 +179,9 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
||||
|
||||
@Override
|
||||
public void deleteStagesOrTask(String taskId) {
|
||||
PipTask taskQuery = new PipTask();
|
||||
taskQuery.setTaskId(taskId);
|
||||
List<PipTask> taskList = taskService.getTask(taskQuery);
|
||||
if (CollectionUtils.isEmpty(taskList)) {
|
||||
return;
|
||||
}
|
||||
PipTask task = taskList.get(0);
|
||||
taskService.deleteTaskById(taskId);
|
||||
// 查询上一级stage下有无其他task 没有则连着stage删除
|
||||
String stageId = task.getStageId();
|
||||
String pipelineId = task.getPipelineId();
|
||||
taskQuery.setTaskId("");
|
||||
taskQuery.setStageId(stageId);
|
||||
List<PipTask> otherTask = taskService.getTask(task);
|
||||
if (CollectionUtils.isEmpty(otherTask)) {
|
||||
// 删除当前task的父stage,然后判断父stage的父级有无其他子集如果没有就继续删除当前阶段
|
||||
|
||||
PipStage stageQuery = new PipStage();
|
||||
stageQuery.setPipelineId(stageId);
|
||||
List<PipStage> currStageList = getPipStageList(stageQuery);
|
||||
if (CollectionUtils.isEmpty(currStageList)) {
|
||||
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"stage不存在");
|
||||
}
|
||||
PipStage currStage = currStageList.get(0);
|
||||
deleteStages(stageId);
|
||||
String parentId = currStage.getParentId();
|
||||
stageQuery.setParentId(parentId);
|
||||
stageQuery.setStageId(null);
|
||||
// 查询同阶段其他二级stage,如果不存在其他stage则删除阶段stage并整理sort值
|
||||
List<PipStage> otherStageList = getPipStageList(stageQuery);
|
||||
if (CollectionUtils.isEmpty(otherStageList)) {
|
||||
//没有其他并行路径就需要删除当前阶段
|
||||
deleteStages(parentId);
|
||||
} else {
|
||||
for (PipStage stage : otherStageList) {
|
||||
if (currStage.getStageSort()<stage.getStageSort()) {
|
||||
stage.setStageSort(stage.getStageSort()-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (PipTask pipTask : otherTask) {
|
||||
if (task.getTaskSort()<pipTask.getTaskSort()) {
|
||||
pipTask.setTaskSort(pipTask.getTaskSort()-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
PipTask pipTask = new PipTask();
|
||||
// pipTask.set
|
||||
List<PipTask> taskById = taskService.getTask(pipTask);
|
||||
|
||||
}
|
||||
|
||||
@ -238,14 +190,6 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
||||
|
||||
}
|
||||
|
||||
private List<PipStage> getPipStageList(PipStage pipStage){
|
||||
LambdaQueryWrapper<PipStage> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(StringUtils.isNotEmpty(pipStage.getStageId()),PipStage::getStageId,pipStage.getStageId());
|
||||
wrapper.eq(StringUtils.isNotEmpty(pipStage.getPipelineId()),PipStage::getPipelineId,pipStage.getPipelineId());
|
||||
wrapper.eq(StringUtils.isNotEmpty(pipStage.getParentId()),PipStage::getParentId,pipStage.getParentId());
|
||||
return stageDao.selectList(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStageName(StageReq stage) {
|
||||
LambdaUpdateWrapper<PipStage> wrapper = new LambdaUpdateWrapper<>();
|
||||
@ -288,7 +232,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
||||
|
||||
@Override
|
||||
public void deleteStages(String stageId) {
|
||||
stageDao.deleteById(stageId);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cd.casic.ci.process.process.service.task;
|
||||
|
||||
import cd.casic.ci.common.pipeline.resp.task.TasksResp;
|
||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
@ -14,6 +13,4 @@ public interface TaskService extends IService<PipTask> {
|
||||
public String createTasksOrTask(PipTask tasks);
|
||||
List<PipTask> finAllStageTask(String stageId);
|
||||
List<PipTask> getTask(PipTask pipTask);
|
||||
void deleteTaskById(String taskId);
|
||||
public TasksResp getById(String taskId);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package cd.casic.ci.process.process.service.task.impl;
|
||||
|
||||
import cd.casic.ci.common.pipeline.annotation.Plugin;
|
||||
import cd.casic.ci.common.pipeline.resp.task.TasksResp;
|
||||
import cd.casic.ci.process.process.dal.pipeline.PipStageDao;
|
||||
import cd.casic.ci.process.process.dal.pipeline.PipTaskDao;
|
||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||
@ -12,12 +11,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
@ -114,22 +111,6 @@ public class TaskServiceImpl extends ServiceImpl<PipTaskDao, PipTask> implements
|
||||
wrapper.eq(StringUtils.isNotEmpty(task.getStageId()),PipTask::getStageId,task.getStageId());
|
||||
return taskDao.selectList(wrapper);
|
||||
}
|
||||
@Override
|
||||
public TasksResp getById(String taskId){
|
||||
PipTask pipTask = new PipTask();
|
||||
pipTask.setTaskId(taskId);
|
||||
List<PipTask> taskList = getTask(pipTask);
|
||||
if (!CollectionUtils.isEmpty(taskList)) {
|
||||
return null;
|
||||
}
|
||||
TasksResp tasksResp = new TasksResp();
|
||||
BeanUtils.copyProperties(taskList.get(0),tasksResp);
|
||||
return tasksResp;
|
||||
}
|
||||
@Override
|
||||
public void deleteTaskById(String taskId) {
|
||||
taskDao.deleteById(taskId);
|
||||
}
|
||||
|
||||
void createDifferentTask(String taskId,String taskType,Object values){
|
||||
// TODO
|
||||
|
@ -1,63 +0,0 @@
|
||||
package cd.casic.ci.process.snowflake;
|
||||
|
||||
public class SnowflakeIdWorker {
|
||||
// 开始时间戳 (2020-01-01)
|
||||
private final long twepoch = 1577808000000L;
|
||||
private final long workerIdBits = 5L;
|
||||
private final long datacenterIdBits = 5L;
|
||||
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
|
||||
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
|
||||
private final long sequenceBits = 12L;
|
||||
private final long workerIdShift = sequenceBits;
|
||||
private final long datacenterIdShift = sequenceBits + workerIdBits;
|
||||
private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
|
||||
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
|
||||
|
||||
private long workerId;
|
||||
private long datacenterId;
|
||||
private long sequence = 0L;
|
||||
private long lastTimestamp = -1L;
|
||||
|
||||
public SnowflakeIdWorker(long workerId, long datacenterId) {
|
||||
if (workerId > maxWorkerId || workerId < 0) {
|
||||
throw new IllegalArgumentException("workerId 超出范围");
|
||||
}
|
||||
if (datacenterId > maxDatacenterId || datacenterId < 0) {
|
||||
throw new IllegalArgumentException("datacenterId 超出范围");
|
||||
}
|
||||
this.workerId = workerId;
|
||||
this.datacenterId = datacenterId;
|
||||
}
|
||||
|
||||
public synchronized long nextId() {
|
||||
long timestamp = timeGen();
|
||||
if (timestamp < lastTimestamp) {
|
||||
throw new RuntimeException("时钟回拨,拒绝生成id");
|
||||
}
|
||||
if (lastTimestamp == timestamp) {
|
||||
sequence = (sequence + 1) & sequenceMask;
|
||||
if (sequence == 0) {
|
||||
timestamp = tilNextMillis(lastTimestamp);
|
||||
}
|
||||
} else {
|
||||
sequence = 0L;
|
||||
}
|
||||
lastTimestamp = timestamp;
|
||||
return ((timestamp - twepoch) << timestampLeftShift)
|
||||
| (datacenterId << datacenterIdShift)
|
||||
| (workerId << workerIdShift)
|
||||
| sequence;
|
||||
}
|
||||
|
||||
private long tilNextMillis(long lastTimestamp) {
|
||||
long timestamp = timeGen();
|
||||
while (timestamp <= lastTimestamp) {
|
||||
timestamp = timeGen();
|
||||
}
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
private long timeGen() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package cd.casic.ci.process.snowflake;
|
||||
|
||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SnowflakeIdentifierGenerator implements IdentifierGenerator {
|
||||
private final SnowflakeIdWorker idWorker;
|
||||
|
||||
public SnowflakeIdentifierGenerator() {
|
||||
this(1,1);
|
||||
}
|
||||
|
||||
public SnowflakeIdentifierGenerator(long workerId, long datacenterId) {
|
||||
this.idWorker = new SnowflakeIdWorker(workerId, datacenterId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number nextId(Object entity) {
|
||||
return idWorker.nextId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextUUID(Object entity) {
|
||||
return String.valueOf(idWorker.nextId());
|
||||
}
|
||||
}
|
@ -1,23 +1,13 @@
|
||||
package cd.casic.server.controller;
|
||||
|
||||
import cd.casic.ci.common.pipeline.resp.task.TasksResp;
|
||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||
import cd.casic.ci.process.process.service.task.TaskService;
|
||||
import cd.casic.framework.commons.pojo.CommonResult;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/task")
|
||||
public class TasksController {
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
/**
|
||||
* @pi.name:查询任务及任务详情
|
||||
* @pi.path:/tasks/findOneTasksOrTask
|
||||
@ -27,6 +17,53 @@ public class TasksController {
|
||||
*/
|
||||
@RequestMapping(path="/findOneTasksOrTask",method = RequestMethod.POST)
|
||||
public CommonResult<TasksResp> findOneTasksOrTask(@NotNull String taskId){
|
||||
return CommonResult.success(taskService.getById(taskId));
|
||||
// Tasks tasksOrTask = tasksService.findOneTasksOrTask(taskId);
|
||||
String tasksStr = "{\n" +
|
||||
" \"taskId\": \"842b38734ded\",\n" +
|
||||
" \"createTime\": \"2025-05-10 16:58:55\",\n" +
|
||||
" \"taskType\": \"maventest\",\n" +
|
||||
" \"taskSort\": 1,\n" +
|
||||
" \"taskName\": \"Maven单元测试\",\n" +
|
||||
" \"values\": {\n" +
|
||||
" \"taskId\": \"842b38734ded\",\n" +
|
||||
" \"testOrder\": \"mvn test\",\n" +
|
||||
" \"address\": \"${DEFAULT_CODE_ADDRESS}\",\n" +
|
||||
" \"testSpace\": null,\n" +
|
||||
" \"testPlan\": null,\n" +
|
||||
" \"apiEnv\": null,\n" +
|
||||
" \"appEnv\": null,\n" +
|
||||
" \"webEnv\": null,\n" +
|
||||
" \"authId\": null,\n" +
|
||||
" \"auth\": null,\n" +
|
||||
" \"type\": null,\n" +
|
||||
" \"sort\": 0,\n" +
|
||||
" \"instanceId\": null,\n" +
|
||||
" \"toolJdk\": null,\n" +
|
||||
" \"toolMaven\": null\n" +
|
||||
" },\n" +
|
||||
" \"pipelineId\": null,\n" +
|
||||
" \"postprocessId\": null,\n" +
|
||||
" \"stageId\": \"5656dfdfe90d\",\n" +
|
||||
" \"task\": {\n" +
|
||||
" \"taskId\": \"842b38734ded\",\n" +
|
||||
" \"testOrder\": \"mvn test\",\n" +
|
||||
" \"address\": \"${DEFAULT_CODE_ADDRESS}\",\n" +
|
||||
" \"testSpace\": null,\n" +
|
||||
" \"testPlan\": null,\n" +
|
||||
" \"apiEnv\": null,\n" +
|
||||
" \"appEnv\": null,\n" +
|
||||
" \"webEnv\": null,\n" +
|
||||
" \"authId\": null,\n" +
|
||||
" \"auth\": null,\n" +
|
||||
" \"type\": null,\n" +
|
||||
" \"sort\": 0,\n" +
|
||||
" \"instanceId\": null,\n" +
|
||||
" \"toolJdk\": null,\n" +
|
||||
" \"toolMaven\": null\n" +
|
||||
" },\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
"}";
|
||||
TasksResp tasksResp = JSON.parseObject(tasksStr, TasksResp.class);
|
||||
return CommonResult.success(tasksResp);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user