雪花算法添加实体类添加
This commit is contained in:
parent
6479e0112d
commit
908d65b688
@ -0,0 +1,17 @@
|
||||
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;
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
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;
|
||||
}
|
@ -39,6 +39,7 @@ public class StageServiceImpl implements StageService {
|
||||
|
||||
@Override
|
||||
public String createStagesOrTask(StageReq stageReq) {
|
||||
// TODO 需要重写
|
||||
PipStage stage = new PipStage();
|
||||
BeanUtils.copyProperties(stageReq,stage);
|
||||
String stagesId = stage.getStageId();
|
||||
|
@ -15,4 +15,5 @@ public interface TaskService {
|
||||
List<PipTask> finAllStageTask(String stageId);
|
||||
List<PipTask> getTask(PipTask pipTask);
|
||||
void deleteTaskById(String taskId);
|
||||
public TasksResp getById(String taskId);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cd.casic.ci.process.process.service.task.impl;
|
||||
|
||||
import cd.casic.ci.common.pipeline.annotation.Plugin;
|
||||
import cd.casic.ci.common.pipeline.constant.PipelineDateUtilConstant;
|
||||
import cd.casic.ci.common.pipeline.resp.task.TasksResp;
|
||||
import cd.casic.ci.common.pipeline.utils.PipelineDateUtil;
|
||||
import cd.casic.ci.process.process.dal.pipeline.PipStageDao;
|
||||
import cd.casic.ci.process.process.dal.pipeline.PipTaskDao;
|
||||
@ -14,10 +15,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -113,7 +116,18 @@ public class TaskServiceImpl implements TaskService {
|
||||
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);
|
||||
|
@ -0,0 +1,63 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
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,13 +1,23 @@
|
||||
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
|
||||
@ -17,53 +27,6 @@ public class TasksController {
|
||||
*/
|
||||
@RequestMapping(path="/findOneTasksOrTask",method = RequestMethod.POST)
|
||||
public CommonResult<TasksResp> findOneTasksOrTask(@NotNull String 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);
|
||||
return CommonResult.success(taskService.getById(taskId));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user