拆分工作流定义的枚举分成2个

This commit is contained in:
戚辰先生 2024-12-07 20:33:14 +08:00
parent fe966f1865
commit 3dc944d255
18 changed files with 243 additions and 102 deletions

View File

@ -1,7 +1,7 @@
package com.qqchen.deploy.backend.workflow.dto;
import com.qqchen.deploy.backend.framework.dto.BaseDTO;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowDefinitionStatusEnum;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@ -37,7 +37,7 @@ public class WorkflowDefinitionDTO extends BaseDTO {
* 工作流状态
*/
@NotNull(message = "工作流状态不能为空")
private WorkflowStatusEnum status;
private WorkflowDefinitionStatusEnum status;
/**
* 版本号

View File

@ -1,7 +1,7 @@
package com.qqchen.deploy.backend.workflow.dto;
import com.qqchen.deploy.backend.framework.dto.BaseDTO;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowInstanceStatusEnum;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -25,9 +25,9 @@ public class WorkflowInstanceDTO extends BaseDTO {
private String businessKey;
/**
* 状态
* 工作流状态
*/
private WorkflowStatusEnum status;
private WorkflowInstanceStatusEnum status;
/**
* 开始时间

View File

@ -10,7 +10,8 @@ import com.qqchen.deploy.backend.workflow.entity.WorkflowDefinition;
import com.qqchen.deploy.backend.workflow.entity.WorkflowInstance;
import com.qqchen.deploy.backend.workflow.enums.NodeStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.NodeTypeEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowDefinitionStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowInstanceStatusEnum;
import com.qqchen.deploy.backend.workflow.repository.INodeInstanceRepository;
import com.qqchen.deploy.backend.workflow.repository.IWorkflowDefinitionRepository;
import com.qqchen.deploy.backend.workflow.repository.IWorkflowInstanceRepository;
@ -51,14 +52,16 @@ public class DefaultWorkflowEngine implements WorkflowEngine {
throw new WorkflowEngineException(ResponseCode.WORKFLOW_NOT_FOUND);
}
if (definition.getStatus() != WorkflowStatusEnum.PUBLISHED) {
// 检查工作流定义状态
if (definition.getStatus() != WorkflowDefinitionStatusEnum.PUBLISHED) {
throw new WorkflowEngineException(ResponseCode.WORKFLOW_NOT_PUBLISHED);
}
// 2. 创建工作流实例
WorkflowInstance instance = new WorkflowInstance();
instance.setDefinition(definition);
instance.setStatus(WorkflowStatusEnum.RUNNING);
// 设置工作流实例状态
instance.setStatus(WorkflowInstanceStatusEnum.RUNNING);
instance.setStartTime(LocalDateTime.now());
workflowInstanceRepository.save(instance);
@ -82,7 +85,8 @@ public class DefaultWorkflowEngine implements WorkflowEngine {
.orElseThrow(() -> new WorkflowEngineException(ResponseCode.WORKFLOW_NODE_NOT_FOUND));
WorkflowInstance instance = nodeInstance.getWorkflowInstance();
if (instance.getStatus() != WorkflowStatusEnum.RUNNING) {
// 检查工作流实例状态
if (instance.getStatus() != WorkflowInstanceStatusEnum.RUNNING) {
throw new WorkflowEngineException(ResponseCode.WORKFLOW_INSTANCE_NOT_RUNNING);
}
@ -137,7 +141,8 @@ public class DefaultWorkflowEngine implements WorkflowEngine {
WorkflowInstance instance = workflowInstanceRepository.findById(instanceId)
.orElseThrow(() -> new WorkflowEngineException(ResponseCode.WORKFLOW_INSTANCE_NOT_FOUND));
if (instance.getStatus() != WorkflowStatusEnum.RUNNING) {
// 检查工作流实例状态
if (instance.getStatus() != WorkflowInstanceStatusEnum.RUNNING) {
throw new WorkflowEngineException(ResponseCode.WORKFLOW_INSTANCE_NOT_RUNNING);
}
@ -156,7 +161,8 @@ public class DefaultWorkflowEngine implements WorkflowEngine {
nodeInstanceRepository.save(node);
}
instance.setStatus(WorkflowStatusEnum.TERMINATED);
// 更新工作流实例状态
instance.setStatus(WorkflowInstanceStatusEnum.TERMINATED);
instance.setEndTime(LocalDateTime.now());
instance.setError(reason);
workflowInstanceRepository.save(instance);
@ -168,7 +174,8 @@ public class DefaultWorkflowEngine implements WorkflowEngine {
WorkflowInstance instance = workflowInstanceRepository.findById(instanceId)
.orElseThrow(() -> new WorkflowEngineException(ResponseCode.WORKFLOW_INSTANCE_NOT_FOUND));
if (instance.getStatus() != WorkflowStatusEnum.RUNNING) {
// 检查工作流实例状态
if (instance.getStatus() != WorkflowInstanceStatusEnum.RUNNING) {
throw new WorkflowEngineException(ResponseCode.WORKFLOW_INSTANCE_NOT_RUNNING);
}
@ -181,7 +188,8 @@ public class DefaultWorkflowEngine implements WorkflowEngine {
nodeInstanceRepository.save(node);
}
instance.setStatus(WorkflowStatusEnum.PAUSED);
// 更新工作流实例状态
instance.setStatus(WorkflowInstanceStatusEnum.PAUSED);
workflowInstanceRepository.save(instance);
}
@ -191,7 +199,8 @@ public class DefaultWorkflowEngine implements WorkflowEngine {
WorkflowInstance instance = workflowInstanceRepository.findById(instanceId)
.orElseThrow(() -> new WorkflowEngineException(ResponseCode.WORKFLOW_INSTANCE_NOT_FOUND));
if (instance.getStatus() != WorkflowStatusEnum.PAUSED) {
// 检查工作流实例状态
if (instance.getStatus() != WorkflowInstanceStatusEnum.PAUSED) {
throw new WorkflowEngineException(ResponseCode.WORKFLOW_INSTANCE_NOT_RUNNING);
}
@ -205,7 +214,8 @@ public class DefaultWorkflowEngine implements WorkflowEngine {
executeNode(node.getId());
}
instance.setStatus(WorkflowStatusEnum.RUNNING);
// 更新工作流实例状态
instance.setStatus(WorkflowInstanceStatusEnum.RUNNING);
workflowInstanceRepository.save(instance);
}

View File

@ -9,7 +9,7 @@ import com.qqchen.deploy.backend.workflow.entity.NodeInstance;
import com.qqchen.deploy.backend.workflow.entity.WorkflowInstance;
import com.qqchen.deploy.backend.workflow.enums.NodeStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.NodeTypeEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowInstanceStatusEnum;
import com.qqchen.deploy.backend.workflow.repository.IWorkflowInstanceRepository;
import jakarta.annotation.Resource;
import lombok.Data;
@ -40,8 +40,8 @@ public class EndNodeExecutor implements NodeExecutor {
nodeInstance.setEndTime(LocalDateTime.now());
// 2. 完成工作流实例
WorkflowInstance instance = context.getInstance();
instance.setStatus(WorkflowStatusEnum.COMPLETED);
WorkflowInstance instance = nodeInstance.getWorkflowInstance();
instance.setStatus(WorkflowInstanceStatusEnum.COMPLETED);
instance.setEndTime(LocalDateTime.now());
workflowInstanceRepository.save(instance);

View File

@ -2,7 +2,7 @@ package com.qqchen.deploy.backend.workflow.entity;
import com.qqchen.deploy.backend.framework.annotation.LogicDelete;
import com.qqchen.deploy.backend.framework.domain.Entity;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowDefinitionStatusEnum;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -43,7 +43,7 @@ public class WorkflowDefinition extends Entity<Long> {
*/
@Enumerated(EnumType.ORDINAL)
@Column(nullable = false)
private WorkflowStatusEnum status = WorkflowStatusEnum.DRAFT;
private WorkflowDefinitionStatusEnum status = WorkflowDefinitionStatusEnum.DRAFT;
/**
* 是否启用

View File

@ -2,7 +2,7 @@ package com.qqchen.deploy.backend.workflow.entity;
import com.qqchen.deploy.backend.framework.annotation.LogicDelete;
import com.qqchen.deploy.backend.framework.domain.Entity;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowInstanceStatusEnum;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -38,11 +38,11 @@ public class WorkflowInstance extends Entity<Long> {
private String businessKey;
/**
* 状态
* 工作流状态
*/
@Enumerated(EnumType.ORDINAL)
@Column(nullable = false)
private WorkflowStatusEnum status = WorkflowStatusEnum.RUNNING;
private WorkflowInstanceStatusEnum status = WorkflowInstanceStatusEnum.CREATED;
/**
* 开始时间

View File

@ -15,7 +15,10 @@ public enum NodeTypeEnum {
TASK(2, "TASK", "任务节点"),
GATEWAY(3, "GATEWAY", "网关节点"),
SUB_PROCESS(4, "SUB_PROCESS", "子流程节点"),
SHELL(5, "SHELL", "Shell脚本节点");
SHELL(5, "SHELL", "Shell脚本节点"),
APPROVAL(6, "APPROVAL", "审批节点"),
JENKINS(7, "JENKINS", "Jenkins任务节点"),
GIT(8, "GIT", "Git操作节点");
private final int value;
private final String code;

View File

@ -0,0 +1,29 @@
package com.qqchen.deploy.backend.workflow.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 工作流定义状态枚举
*/
@Getter
@AllArgsConstructor
public enum WorkflowDefinitionStatusEnum {
DRAFT(0, "DRAFT", "草稿"),
PUBLISHED(1, "PUBLISHED", "已发布"),
DISABLED(2, "DISABLED", "已禁用");
private final int value;
private final String code;
private final String description;
public static WorkflowDefinitionStatusEnum fromValue(int value) {
for (WorkflowDefinitionStatusEnum status : values()) {
if (status.getValue() == value) {
return status;
}
}
throw new IllegalArgumentException("No matching WorkflowDefinitionStatusEnum for value: " + value);
}
}

View File

@ -4,37 +4,39 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 工作流状态枚举
* 工作流实例状态枚举
*/
@Getter
@AllArgsConstructor
public enum WorkflowStatusEnum {
public enum WorkflowInstanceStatusEnum {
// 工作流定义状态
DRAFT(0, "DRAFT", "草稿"),
PUBLISHED(1, "PUBLISHED", "已发布"),
DISABLED(2, "DISABLED", "已禁用"),
// 工作流实例状态
CREATED(3, "CREATED", "已创建"),
PENDING(4, "PENDING", "等待执行"),
RUNNING(5, "RUNNING", "执行中"),
CREATED(0, "CREATED", "已创建"),
PENDING(1, "PENDING", "等待执行"),
RUNNING(2, "RUNNING", "执行中"),
COMPLETED(3, "COMPLETED", "已完成"),
FAILED(4, "FAILED", "执行失败"),
CANCELLED(5, "CANCELLED", "已取消"),
PAUSED(6, "PAUSED", "已暂停"),
COMPLETED(7, "COMPLETED", "已完成"),
FAILED(8, "FAILED", "执行失败"),
CANCELLED(9, "CANCELLED", "已取消"),
SUSPENDED(10, "SUSPENDED", "已暂停"),
TERMINATED(11, "TERMINATED", "已终止");
TERMINATED(7, "TERMINATED", "已终止");
private final int value;
private final String code;
private final String description;
public static WorkflowInstanceStatusEnum fromValue(int value) {
for (WorkflowInstanceStatusEnum status : values()) {
if (status.getValue() == value) {
return status;
}
}
throw new IllegalArgumentException("No matching WorkflowInstanceStatusEnum for value: " + value);
}
/**
* 判断是否为终态
*/
public boolean isFinalStatus() {
return this == COMPLETED || this == FAILED || this == CANCELLED || this == SUSPENDED || this == TERMINATED;
return this == COMPLETED || this == FAILED || this == CANCELLED || this == TERMINATED;
}
/**
@ -62,6 +64,6 @@ public enum WorkflowStatusEnum {
* 判断是否可以取消
*/
public boolean canCancel() {
return this == PENDING || this == RUNNING || this == PAUSED;
return this == RUNNING || this == PAUSED || this == PENDING;
}
}

View File

@ -3,7 +3,7 @@ package com.qqchen.deploy.backend.workflow.query;
import com.qqchen.deploy.backend.framework.annotation.QueryField;
import com.qqchen.deploy.backend.framework.enums.QueryType;
import com.qqchen.deploy.backend.framework.query.BaseQuery;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowDefinitionStatusEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -17,6 +17,9 @@ public class WorkflowDefinitionQuery extends BaseQuery {
@QueryField(field = "code", type = QueryType.LIKE)
private String code;
/**
* 工作流状态
*/
@QueryField(field = "status")
private WorkflowStatusEnum status;
private WorkflowDefinitionStatusEnum status;
}

View File

@ -3,7 +3,7 @@ package com.qqchen.deploy.backend.workflow.query;
import com.qqchen.deploy.backend.framework.annotation.QueryField;
import com.qqchen.deploy.backend.framework.enums.QueryType;
import com.qqchen.deploy.backend.framework.query.BaseQuery;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowInstanceStatusEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -17,6 +17,9 @@ public class WorkflowInstanceQuery extends BaseQuery {
@QueryField(field = "definitionId")
private Long definitionId;
/**
* 工作流状态
*/
@QueryField(field = "status")
private WorkflowStatusEnum status;
private WorkflowInstanceStatusEnum status;
}

View File

@ -2,7 +2,7 @@ package com.qqchen.deploy.backend.workflow.repository;
import com.qqchen.deploy.backend.framework.repository.IBaseRepository;
import com.qqchen.deploy.backend.workflow.entity.WorkflowDefinition;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowDefinitionStatusEnum;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@ -44,12 +44,10 @@ public interface IWorkflowDefinitionRepository extends IBaseRepository<WorkflowD
List<WorkflowDefinition> findAllVersionsByCode(@Param("code") String code);
/**
* 根据状态查询工作流定义列表
*
* @param status 状态
* @return 工作流定义列表
* 查询指定状态的工作流定义
*/
List<WorkflowDefinition> findByStatusAndDeletedFalse(WorkflowStatusEnum status);
@Query("SELECT d FROM WorkflowDefinition d WHERE d.status = :status AND d.deleted = false")
List<WorkflowDefinition> findByStatus(@Param("status") WorkflowDefinitionStatusEnum status);
/**
* 检查编码是否已存在

View File

@ -2,7 +2,7 @@ package com.qqchen.deploy.backend.workflow.repository;
import com.qqchen.deploy.backend.framework.repository.IBaseRepository;
import com.qqchen.deploy.backend.workflow.entity.WorkflowInstance;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowInstanceStatusEnum;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@ -19,7 +19,12 @@ public interface IWorkflowInstanceRepository extends IBaseRepository<WorkflowIns
* 查询指定状态的工作流实例
*/
@Query("SELECT i FROM WorkflowInstance i WHERE i.status IN :statuses AND i.deleted = false")
List<WorkflowInstance> findByStatusIn(@Param("statuses") List<WorkflowStatusEnum> statuses);
List<WorkflowInstance> findByStatusIn(@Param("statuses") List<WorkflowInstanceStatusEnum> statuses);
/**
* 根据工作流定义ID和状态查询工作流实例数量
*/
long countByDefinitionIdAndStatus(Long definitionId, WorkflowInstanceStatusEnum status);
/**
* 查询项目环境的工作流实例

View File

@ -6,7 +6,7 @@ import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl;
import com.qqchen.deploy.backend.workflow.converter.WorkflowDefinitionConverter;
import com.qqchen.deploy.backend.workflow.dto.WorkflowDefinitionDTO;
import com.qqchen.deploy.backend.workflow.entity.WorkflowDefinition;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowDefinitionStatusEnum;
import com.qqchen.deploy.backend.workflow.repository.INodeDefinitionRepository;
import com.qqchen.deploy.backend.workflow.repository.IWorkflowDefinitionRepository;
import com.qqchen.deploy.backend.workflow.service.IWorkflowDefinitionService;
@ -45,7 +45,8 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl<WorkflowDefin
}
// 设置初始状态
dto.setStatus(WorkflowStatusEnum.DRAFT);
dto.setVersion(1);
dto.setStatus(WorkflowDefinitionStatusEnum.DRAFT);
dto.setEnabled(true);
// 保存工作流定义
@ -63,7 +64,7 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl<WorkflowDefin
.orElseThrow(() -> new BusinessException(ResponseCode.WORKFLOW_NOT_FOUND));
// 只有草稿状态可以修改
if (current.getStatus() != WorkflowStatusEnum.DRAFT) {
if (current.getStatus() != WorkflowDefinitionStatusEnum.DRAFT) {
throw new BusinessException(ResponseCode.WORKFLOW_NOT_DRAFT);
}
@ -95,7 +96,7 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl<WorkflowDefin
.orElseThrow(() -> new BusinessException(ResponseCode.WORKFLOW_NOT_FOUND));
// 验证当前状态
if (current.getStatus() != WorkflowStatusEnum.DRAFT) {
if (current.getStatus() != WorkflowDefinitionStatusEnum.DRAFT) {
throw new BusinessException(ResponseCode.WORKFLOW_NOT_DRAFT);
}
@ -105,7 +106,7 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl<WorkflowDefin
}
// 更新状态
current.setStatus(WorkflowStatusEnum.PUBLISHED);
current.setStatus(WorkflowDefinitionStatusEnum.PUBLISHED);
current = workflowDefinitionRepository.save(current);
return workflowDefinitionConverter.toDto(current);
@ -119,12 +120,12 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl<WorkflowDefin
.orElseThrow(() -> new BusinessException(ResponseCode.WORKFLOW_NOT_FOUND));
// 验证当前状态
if (current.getStatus() != WorkflowStatusEnum.PUBLISHED) {
if (current.getStatus() != WorkflowDefinitionStatusEnum.PUBLISHED) {
throw new BusinessException(ResponseCode.WORKFLOW_NOT_PUBLISHED);
}
// 更新状态
current.setStatus(WorkflowStatusEnum.DISABLED);
current.setStatus(WorkflowDefinitionStatusEnum.DISABLED);
current = workflowDefinitionRepository.save(current);
return workflowDefinitionConverter.toDto(current);
@ -138,12 +139,12 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl<WorkflowDefin
.orElseThrow(() -> new BusinessException(ResponseCode.WORKFLOW_NOT_FOUND));
// 验证当前状态
if (current.getStatus() != WorkflowStatusEnum.DISABLED) {
if (current.getStatus() != WorkflowDefinitionStatusEnum.DISABLED) {
throw new BusinessException(ResponseCode.WORKFLOW_NOT_DISABLED);
}
// 更新状态
current.setStatus(WorkflowStatusEnum.PUBLISHED);
current.setStatus(WorkflowDefinitionStatusEnum.PUBLISHED);
current = workflowDefinitionRepository.save(current);
return workflowDefinitionConverter.toDto(current);
@ -219,7 +220,7 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl<WorkflowDefin
newDefinition.setCode(oldDefinition.getCode());
newDefinition.setName(oldDefinition.getName());
newDefinition.setDescription(oldDefinition.getDescription());
newDefinition.setStatus(WorkflowStatusEnum.DRAFT);
newDefinition.setStatus(WorkflowDefinitionStatusEnum.DRAFT);
newDefinition.setEnabled(true);
newDefinition.setNodeConfig(oldDefinition.getNodeConfig());
newDefinition.setTransitionConfig(oldDefinition.getTransitionConfig());

View File

@ -6,7 +6,8 @@ import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl;
import com.qqchen.deploy.backend.workflow.dto.WorkflowInstanceDTO;
import com.qqchen.deploy.backend.workflow.entity.WorkflowDefinition;
import com.qqchen.deploy.backend.workflow.entity.WorkflowInstance;
import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowInstanceStatusEnum;
import com.qqchen.deploy.backend.workflow.enums.WorkflowDefinitionStatusEnum;
import com.qqchen.deploy.backend.workflow.repository.IWorkflowDefinitionRepository;
import com.qqchen.deploy.backend.workflow.repository.IWorkflowInstanceRepository;
import com.qqchen.deploy.backend.workflow.service.IWorkflowInstanceService;
@ -43,7 +44,7 @@ public class WorkflowInstanceServiceImpl extends BaseServiceImpl<WorkflowInstanc
.orElseThrow(() -> new BusinessException(ResponseCode.WORKFLOW_NOT_FOUND));
// 2. 检查工作流定义状态
if (definition.getStatus() != WorkflowStatusEnum.PUBLISHED) {
if (definition.getStatus() != WorkflowDefinitionStatusEnum.PUBLISHED) {
throw new BusinessException(ResponseCode.WORKFLOW_NOT_PUBLISHED);
}
if (!definition.getEnabled()) {
@ -54,7 +55,7 @@ public class WorkflowInstanceServiceImpl extends BaseServiceImpl<WorkflowInstanc
WorkflowInstance instance = new WorkflowInstance();
instance.setDefinition(definition);
instance.setBusinessKey(businessKey);
instance.setStatus(WorkflowStatusEnum.CREATED);
instance.setStatus(WorkflowInstanceStatusEnum.CREATED);
final WorkflowInstance savedInstance = workflowInstanceRepository.save(instance);
// 4. 设置初始变量
@ -73,12 +74,12 @@ public class WorkflowInstanceServiceImpl extends BaseServiceImpl<WorkflowInstanc
.orElseThrow(() -> new BusinessException(ResponseCode.WORKFLOW_INSTANCE_NOT_FOUND));
// 2. 检查状态
if (instance.getStatus() != WorkflowStatusEnum.CREATED) {
if (instance.getStatus() != WorkflowInstanceStatusEnum.CREATED) {
throw new BusinessException(ResponseCode.WORKFLOW_INSTANCE_NOT_RUNNING);
}
// 3. 更新状态
instance.setStatus(WorkflowStatusEnum.RUNNING);
instance.setStatus(WorkflowInstanceStatusEnum.RUNNING);
instance.setStartTime(LocalDateTime.now());
instance = workflowInstanceRepository.save(instance);
@ -98,7 +99,7 @@ public class WorkflowInstanceServiceImpl extends BaseServiceImpl<WorkflowInstanc
}
// 3. 更新状态
instance.setStatus(WorkflowStatusEnum.PAUSED);
instance.setStatus(WorkflowInstanceStatusEnum.PAUSED);
instance = workflowInstanceRepository.save(instance);
return converter.toDto(instance);
@ -117,7 +118,7 @@ public class WorkflowInstanceServiceImpl extends BaseServiceImpl<WorkflowInstanc
}
// 3. 更新状态
instance.setStatus(WorkflowStatusEnum.RUNNING);
instance.setStatus(WorkflowInstanceStatusEnum.RUNNING);
instance = workflowInstanceRepository.save(instance);
return converter.toDto(instance);
@ -135,8 +136,8 @@ public class WorkflowInstanceServiceImpl extends BaseServiceImpl<WorkflowInstanc
throw new BusinessException(ResponseCode.WORKFLOW_INSTANCE_NOT_RUNNING);
}
// 3. <EFBFBD><EFBFBD><EFBFBD>新状态
instance.setStatus(WorkflowStatusEnum.TERMINATED);
// 3. 新状态
instance.setStatus(WorkflowInstanceStatusEnum.TERMINATED);
instance.setEndTime(LocalDateTime.now());
instance.setError(reason);
instance = workflowInstanceRepository.save(instance);

View File

@ -418,7 +418,7 @@ CREATE TABLE wf_node_definition (
workflow_definition_id BIGINT NOT NULL COMMENT '工作流定义ID',
node_id VARCHAR(100) NOT NULL COMMENT '节点ID',
name VARCHAR(100) NOT NULL COMMENT '节点名称',
type TINYINT NOT NULL COMMENT '节点类型0开始节点1结束节点2任务节点3网关节点4子流程节点5Shell脚本节点',
type TINYINT NOT NULL COMMENT '节点类型0开始节点1结束节点2任务节点3网关节点4子流程节点5Shell脚本节点6审批节点7Jenkins任务节点8Git操作节点',
config TEXT NULL COMMENT '节点配置(JSON)',
order_num INT NOT NULL DEFAULT 0 COMMENT '排序号',
@ -438,7 +438,7 @@ CREATE TABLE wf_workflow_instance (
workflow_definition_id BIGINT NOT NULL COMMENT '工作流定义ID',
business_key VARCHAR(100) NOT NULL COMMENT '业务标识',
status TINYINT NOT NULL COMMENT '状态(3已创建4等待执行5执行中6已暂停7已完成8执行失败9已取消10已暂停11:已终止)',
status TINYINT NOT NULL COMMENT '状态(0已创建1等待执行2执行中3已完成4执行失败5已取消6已暂停7:已终止)',
start_time DATETIME(6) NULL COMMENT '开始时间',
end_time DATETIME(6) NULL COMMENT '结束时间',
error TEXT NULL COMMENT '错误信息',
@ -459,9 +459,9 @@ CREATE TABLE wf_node_instance (
workflow_instance_id BIGINT NOT NULL COMMENT '工作流实例ID',
node_id VARCHAR(100) NOT NULL COMMENT '节点ID',
node_type TINYINT NOT NULL COMMENT '节点类型0开始节点1结束节点2任务节点3网关节点4子流程节点5Shell脚本节点',
node_type TINYINT NOT NULL COMMENT '节点类型0开始节点1结束节点2任务节点3网关节点4子流程节点5Shell脚本节点6审批节点7Jenkins任务节点8Git操作节点',
name VARCHAR(100) NOT NULL COMMENT '节点名称',
status TINYINT NOT NULL COMMENT '状态(3已创建4等待执行5执行中6已暂停7已完成8执行失败9已取消10已暂停11:已终止)',
status TINYINT NOT NULL COMMENT '状态(0已创建1等待执行2执行中3已完成4执行失败5已取消6已暂停7:已终止)',
start_time DATETIME(6) NULL COMMENT '开始时间',
end_time DATETIME(6) NULL COMMENT '结束时间',
config TEXT NULL COMMENT '节点配置(JSON)',
@ -556,4 +556,3 @@ CREATE TABLE wf_node_type (
CONSTRAINT UK_node_type_code UNIQUE (code)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='节点类型表';

View File

@ -203,7 +203,7 @@ INSERT INTO wf_workflow_instance (
workflow_definition_id, business_key, status, start_time, end_time, error
) VALUES (
1, 'admin', NOW(), 0, 'admin', NOW(), 0,
1, 'TEST-APP-001', 5,
1, 'TEST-APP-001', 2,
NOW(), NULL, NULL
);
@ -214,25 +214,25 @@ INSERT INTO wf_node_instance (
) VALUES
-- 开始节点实例
(1, 'admin', NOW(), 0, 'admin', NOW(), 0,
1, 'startNode', 0, '开始', 7,
1, 'startNode', 0, '开始', 3,
DATE_SUB(NOW(), INTERVAL 5 MINUTE), DATE_SUB(NOW(), INTERVAL 4 MINUTE),
'{"type":"START","name":"开始"}',
'{"appName":"test-app","branch":"master"}', '{}', NULL, NULL),
-- 构建节点实例
(2, 'admin', NOW(), 0, 'admin', NOW(), 0,
1, 'build', 2, '构建', 5,
1, 'build', 2, '构建', 2,
DATE_SUB(NOW(), INTERVAL 3 MINUTE), NULL,
'{"type":"TASK","name":"构建","executor":"JENKINS","jenkinsJob":"app-build"}',
'{"appName":"test-app","branch":"master"}', NULL, NULL, 'startNode'),
-- 部署节点实例
(3, 'admin', NOW(), 0, 'admin', NOW(), 0,
1, 'deploy', 2, '部署', 5,
1, 'deploy', 2, '部署', 1,
DATE_SUB(NOW(), INTERVAL 2 MINUTE), NULL,
'{"type":"TASK","name":"部署","executor":"SHELL","script":"./deploy.sh"}',
'{"appName":"test-app","branch":"master"}', NULL, NULL, 'build'),
-- 结束节点实例
(4, 'admin', NOW(), 0, 'admin', NOW(), 0,
1, 'endNode', 1, '结束', 7,
1, 'endNode', 1, '结束', 0,
DATE_SUB(NOW(), INTERVAL 1 MINUTE), DATE_SUB(NOW(), INTERVAL 0 MINUTE),
'{"type":"END","name":"结束"}',
'{}', '{}', NULL, 'deploy');
@ -380,8 +380,94 @@ true, NOW(), 'system', NOW(), 'system', 1, false),
'{"name": "Shell脚本", "executor": "SHELL"}',
true, NOW(), 'system', NOW(), 'system', 1, false),
-- Git节点类型
(2004, 'GIT', 'Git操作节点', '执行Git操作的任务节点', 'TASK', 'branch', '#722ed1',
'[{
"code": "GIT",
"name": "Git操作执行器",
"description": "执行Git操作支持克隆、拉取、切换分支等操作",
"configSchema": {
"type": "object",
"required": ["operation", "repository"],
"properties": {
"operation": {
"type": "string",
"title": "Git操作",
"enum": ["CLONE", "PULL", "CHECKOUT", "FETCH"],
"enumNames": ["克隆仓库", "拉取代码", "切换分支", "获取更新"],
"description": "要执行的Git操作类型"
},
"repository": {
"type": "string",
"title": "仓库地址",
"description": "Git仓库的URL地址"
},
"branch": {
"type": "string",
"title": "分支名称",
"description": "Git分支名称",
"default": "master"
},
"workingDirectory": {
"type": "string",
"title": "工作目录",
"description": "Git操作的工作目录",
"default": "/tmp"
},
"timeout": {
"type": "number",
"title": "超时时间",
"description": "操作的最大执行时间(秒)",
"minimum": 1,
"maximum": 3600,
"default": 300
},
"credentials": {
"type": "object",
"title": "认证信息",
"properties": {
"username": {
"type": "string",
"title": "用户名"
},
"password": {
"type": "string",
"title": "密码/Token",
"format": "password"
}
}
}
}
}
}]',
'{
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "节点名称",
"minLength": 1,
"maxLength": 50
},
"description": {
"type": "string",
"title": "节点描述",
"maxLength": 200
},
"executor": {
"type": "string",
"title": "执行器",
"enum": ["GIT"],
"enumNames": ["Git操作执行器"]
}
},
"required": ["name", "executor"]
}',
'{"name": "Git操作", "executor": "GIT"}',
true, NOW(), 'system', NOW(), 'system', 1, false),
-- 网关节点类型
(2004, 'GATEWAY', '网关节点', '控制流程流转的网关节点', 'GATEWAY', 'fork', '#faad14', '[]',
(2005, 'GATEWAY', '网关节点', '控制流程流转的网关节点', 'GATEWAY', 'fork', '#faad14', '[]',
'{
"type": "object",
"properties": {
@ -409,7 +495,7 @@ true, NOW(), 'system', NOW(), 'system', 1, false),
true, NOW(), 'system', NOW(), 'system', 1, false),
-- 事件节点类型
(2005, 'TIMER', '定时器节点', '定时触发的事件节点', 'EVENT', 'clock-circle', '#722ed1', '[]',
(2006, 'TIMER', '定时器节点', '定时触发的事件节点', 'EVENT', 'clock-circle', '#722ed1', '[]',
'{
"type": "object",
"properties": {

View File

@ -5,7 +5,8 @@
//import com.qqchen.deploy.backend.workflow.dto.WorkflowInstanceDTO;
//import com.qqchen.deploy.backend.workflow.entity.WorkflowDefinition;
//import com.qqchen.deploy.backend.workflow.entity.WorkflowInstance;
//import com.qqchen.deploy.backend.workflow.enums.WorkflowStatusEnum;
//import com.qqchen.deploy.backend.workflow.enums.WorkflowInstanceStatusEnum;
//import com.qqchen.deploy.backend.workflow.enums.WorkflowDefinitionStatusEnum;
//import com.qqchen.deploy.backend.workflow.repository.IWorkflowDefinitionRepository;
//import com.qqchen.deploy.backend.workflow.repository.IWorkflowInstanceRepository;
//import com.qqchen.deploy.backend.workflow.service.impl.WorkflowInstanceServiceImpl;
@ -50,14 +51,14 @@
// definition.setId(1L);
// definition.setCode("TEST-WF");
// definition.setName("Test Workflow");
// definition.setStatus(WorkflowStatusEnum.PUBLISHED);
// definition.setStatus(WorkflowDefinitionStatusEnum.PUBLISHED);
// definition.setEnabled(true);
//
// instance = new WorkflowInstance();
// instance.setId(1L);
// instance.setDefinition(definition);
// instance.setBusinessKey("TEST-KEY");
// instance.setStatus(WorkflowStatusEnum.CREATED);
// instance.setStatus(WorkflowInstanceStatusEnum.CREATED);
//
// variables = new HashMap<>();
// variables.put("key1", "value1");
@ -72,7 +73,7 @@
// WorkflowInstanceDTO result = workflowInstanceService.createInstance(1L, "TEST-KEY", variables);
//
// assertNotNull(result);
// assertEquals(WorkflowStatusEnum.CREATED, result.getStatus());
// assertEquals(WorkflowInstanceStatusEnum.CREATED, result.getStatus());
// assertEquals("TEST-KEY", result.getBusinessKey());
// verify(workflowDefinitionRepository).findById(1L);
// verify(workflowInstanceRepository).save(any(WorkflowInstance.class));
@ -90,7 +91,7 @@
//
// @Test
// void createInstance_WorkflowNotPublished_ThrowsException() {
// definition.setStatus(WorkflowStatusEnum.DRAFT);
// definition.setStatus(WorkflowDefinitionStatusEnum.DRAFT);
// when(workflowDefinitionRepository.findById(anyLong())).thenReturn(Optional.of(definition));
//
// BusinessException exception = assertThrows(BusinessException.class,
@ -106,7 +107,7 @@
// WorkflowInstanceDTO result = workflowInstanceService.startInstance(1L);
//
// assertNotNull(result);
// assertEquals(WorkflowStatusEnum.RUNNING, result.getStatus());
// assertEquals(WorkflowInstanceStatusEnum.RUNNING, result.getStatus());
// assertNotNull(result.getStartTime());
// verify(workflowInstanceRepository).findById(1L);
// verify(workflowInstanceRepository).save(any(WorkflowInstance.class));
@ -123,7 +124,7 @@
//
// @Test
// void startInstance_NotCreated_ThrowsException() {
// instance.setStatus(WorkflowStatusEnum.RUNNING);
// instance.setStatus(WorkflowInstanceStatusEnum.RUNNING);
// when(workflowInstanceRepository.findById(anyLong())).thenReturn(Optional.of(instance));
//
// BusinessException exception = assertThrows(BusinessException.class,
@ -133,42 +134,42 @@
//
// @Test
// void pauseInstance_Success() {
// instance.setStatus(WorkflowStatusEnum.RUNNING);
// instance.setStatus(WorkflowInstanceStatusEnum.RUNNING);
// when(workflowInstanceRepository.findById(anyLong())).thenReturn(Optional.of(instance));
// when(workflowInstanceRepository.save(any(WorkflowInstance.class))).thenReturn(instance);
//
// WorkflowInstanceDTO result = workflowInstanceService.pauseInstance(1L);
//
// assertNotNull(result);
// assertEquals(WorkflowStatusEnum.PAUSED, result.getStatus());
// assertEquals(WorkflowInstanceStatusEnum.PAUSED, result.getStatus());
// verify(workflowInstanceRepository).findById(1L);
// verify(workflowInstanceRepository).save(any(WorkflowInstance.class));
// }
//
// @Test
// void resumeInstance_Success() {
// instance.setStatus(WorkflowStatusEnum.PAUSED);
// instance.setStatus(WorkflowInstanceStatusEnum.PAUSED);
// when(workflowInstanceRepository.findById(anyLong())).thenReturn(Optional.of(instance));
// when(workflowInstanceRepository.save(any(WorkflowInstance.class))).thenReturn(instance);
//
// WorkflowInstanceDTO result = workflowInstanceService.resumeInstance(1L);
//
// assertNotNull(result);
// assertEquals(WorkflowStatusEnum.RUNNING, result.getStatus());
// assertEquals(WorkflowInstanceStatusEnum.RUNNING, result.getStatus());
// verify(workflowInstanceRepository).findById(1L);
// verify(workflowInstanceRepository).save(any(WorkflowInstance.class));
// }
//
// @Test
// void terminateInstance_Success() {
// instance.setStatus(WorkflowStatusEnum.RUNNING);
// instance.setStatus(WorkflowInstanceStatusEnum.RUNNING);
// when(workflowInstanceRepository.findById(anyLong())).thenReturn(Optional.of(instance));
// when(workflowInstanceRepository.save(any(WorkflowInstance.class))).thenReturn(instance);
//
// WorkflowInstanceDTO result = workflowInstanceService.terminateInstance(1L, "Test reason");
//
// assertNotNull(result);
// assertEquals(WorkflowStatusEnum.TERMINATED, result.getStatus());
// assertEquals(WorkflowInstanceStatusEnum.TERMINATED, result.getStatus());
// assertEquals("Test reason", result.getError());
// assertNotNull(result.getEndTime());
// verify(workflowInstanceRepository).findById(1L);
@ -177,7 +178,7 @@
//
// @Test
// void terminateInstance_AlreadyTerminated_ThrowsException() {
// instance.setStatus(WorkflowStatusEnum.TERMINATED);
// instance.setStatus(WorkflowInstanceStatusEnum.TERMINATED);
// when(workflowInstanceRepository.findById(anyLong())).thenReturn(Optional.of(instance));
//
// BusinessException exception = assertThrows(BusinessException.class,