删除掉所有没用的工作流相关的类,重新开发。
This commit is contained in:
parent
412a7e5c91
commit
9312c3a2b3
@ -13,8 +13,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.bpmn.model.SequenceFlow;
|
||||
import org.flowable.bpmn.model.StartEvent;
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.ManagementService;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
import org.flowable.engine.history.HistoricActivityInstance;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.repository.Deployment;
|
||||
@ -23,22 +25,22 @@ import org.flowable.engine.runtime.Execution;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.bpmn.model.Process;
|
||||
import org.flowable.bpmn.model.FlowElement;
|
||||
import org.flowable.bpmn.model.Task;
|
||||
import org.flowable.bpmn.model.Event;
|
||||
import org.flowable.bpmn.model.ServiceTask;
|
||||
import org.flowable.job.api.Job;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.flowable.variable.api.history.HistoricVariableInstance;
|
||||
|
||||
/**
|
||||
* 工作流定义服务实现
|
||||
@ -54,6 +56,12 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl<WorkflowDefin
|
||||
@Resource
|
||||
private RuntimeService runtimeService;
|
||||
|
||||
@Resource
|
||||
private ManagementService managementService;
|
||||
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
@Resource
|
||||
private HistoryService historyService;
|
||||
|
||||
@ -152,50 +160,32 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl<WorkflowDefin
|
||||
throw new RuntimeException("Process instance not found: " + processInstanceId);
|
||||
}
|
||||
|
||||
log.info("流程定义ID: {}", historicInstance.getProcessDefinitionId());
|
||||
log.info("流程是否在运行: {}", runningInstance != null);
|
||||
log.info("流程开始时间: {}", historicInstance.getStartTime());
|
||||
log.info("流程结束时间: {}", historicInstance.getEndTime());
|
||||
|
||||
// 2. 获取流程定义
|
||||
BpmnModel bpmnModel = repositoryService.getBpmnModel(historicInstance.getProcessDefinitionId());
|
||||
Process process = bpmnModel.getMainProcess();
|
||||
|
||||
// 3. 获取所有历史活动实例
|
||||
List<HistoricActivityInstance> historicActivities = historyService.createHistoricActivityInstanceQuery()
|
||||
|
||||
// 3. 获取所有节点(不包括连线)
|
||||
List<FlowElement> nodes = process.getFlowElements().stream()
|
||||
.filter(element -> !(element instanceof SequenceFlow))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 4. 获取正在执行的节点
|
||||
Set<String> runningNodes = runtimeService.createExecutionQuery()
|
||||
.processInstanceId(processInstanceId)
|
||||
.list()
|
||||
.stream()
|
||||
.map(Execution::getActivityId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 5. 获取历史节点
|
||||
Map<String, HistoricActivityInstance> historicNodes = historyService.createHistoricActivityInstanceQuery()
|
||||
.processInstanceId(processInstanceId)
|
||||
.orderByHistoricActivityInstanceStartTime()
|
||||
.asc()
|
||||
.list();
|
||||
|
||||
log.info("=== 历史活动实例信息 ===");
|
||||
for (HistoricActivityInstance activity : historicActivities) {
|
||||
log.info("节点ID: {}, 名称: {}, 类型: {}, 开始时间: {}, 结束时间: {}, 执行ID: {}",
|
||||
activity.getActivityId(),
|
||||
activity.getActivityName(),
|
||||
activity.getActivityType(),
|
||||
activity.getStartTime(),
|
||||
activity.getEndTime(),
|
||||
activity.getExecutionId());
|
||||
}
|
||||
|
||||
// 4. 获取当前正在执行的活动节点
|
||||
List<String> activeActivityIds = new ArrayList<>();
|
||||
if (runningInstance != null) {
|
||||
List<Execution> executions = runtimeService.createExecutionQuery()
|
||||
.processInstanceId(processInstanceId)
|
||||
.list();
|
||||
|
||||
for (Execution execution : executions) {
|
||||
if (execution.getActivityId() != null) {
|
||||
activeActivityIds.add(execution.getActivityId());
|
||||
}
|
||||
}
|
||||
log.info("当前活动节点IDs: {}", activeActivityIds);
|
||||
}
|
||||
|
||||
// 5. 构建历史活动实例映射
|
||||
Map<String, HistoricActivityInstance> historicActivityMap = historicActivities.stream()
|
||||
.list()
|
||||
.stream()
|
||||
.filter(activity -> !(activity.getActivityType().equals("sequenceFlow")))
|
||||
.collect(Collectors.toMap(
|
||||
HistoricActivityInstance::getActivityId,
|
||||
activity -> activity,
|
||||
@ -221,31 +211,52 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl<WorkflowDefin
|
||||
WorkflowInstanceStatus.SUSPENDED : WorkflowInstanceStatus.RUNNING);
|
||||
}
|
||||
|
||||
// 7. 构建阶段列表
|
||||
// 7. 构建节点状态列表
|
||||
List<WorkflowExecutionDTO.StageDTO> stages = new ArrayList<>();
|
||||
List<FlowElement> flowElements = process.getFlowElements().stream()
|
||||
.filter(element -> !(element instanceof SequenceFlow))
|
||||
.collect(Collectors.toList());
|
||||
boolean hasFailedNode = false;
|
||||
|
||||
log.info("=== 开始构建节点状态 ===");
|
||||
for (FlowElement element : flowElements) {
|
||||
for (FlowElement element : nodes) {
|
||||
WorkflowExecutionDTO.StageDTO stage = new WorkflowExecutionDTO.StageDTO();
|
||||
stage.setId(element.getId());
|
||||
stage.setName(element.getName());
|
||||
stage.setType(element.getClass().getSimpleName());
|
||||
|
||||
HistoricActivityInstance historicActivity = historicActivityMap.get(element.getId());
|
||||
|
||||
// 确定节点状态
|
||||
determineStageStatus(stage, element, historicActivity, activeActivityIds);
|
||||
|
||||
log.info("节点[{}] - 名称: {}, 类型: {}, 状态: {}, 开始时间: {}, 结束时间: {}",
|
||||
stage.getId(),
|
||||
stage.getName(),
|
||||
stage.getType(),
|
||||
stage.getStatus(),
|
||||
stage.getStartTime(),
|
||||
stage.getEndTime());
|
||||
// 如果已经有节点失败,后续节点都是未开始
|
||||
if (hasFailedNode) {
|
||||
stage.setStatus(WorkflowInstanceStatus.NOT_STARTED);
|
||||
stages.add(stage);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 判断节点状态
|
||||
if (runningNodes.contains(element.getId())) {
|
||||
// 正在执行的节点
|
||||
stage.setStatus(WorkflowInstanceStatus.RUNNING);
|
||||
} else {
|
||||
// 查找历史记录
|
||||
HistoricActivityInstance historicActivity = historicNodes.get(element.getId());
|
||||
if (historicActivity != null) {
|
||||
stage.setStartTime(historicActivity.getStartTime());
|
||||
stage.setEndTime(historicActivity.getEndTime());
|
||||
|
||||
if (historicActivity.getEndTime() != null) {
|
||||
if (historicActivity.getDeleteReason() != null) {
|
||||
// 节点失败
|
||||
stage.setStatus(WorkflowInstanceStatus.FAILED);
|
||||
hasFailedNode = true;
|
||||
} else {
|
||||
// 节点完成
|
||||
stage.setStatus(WorkflowInstanceStatus.COMPLETED);
|
||||
}
|
||||
} else {
|
||||
// 有开始时间但没有结束时间,说明正在运行
|
||||
stage.setStatus(WorkflowInstanceStatus.RUNNING);
|
||||
}
|
||||
} else {
|
||||
// 没有历史记录,未开始
|
||||
stage.setStatus(WorkflowInstanceStatus.NOT_STARTED);
|
||||
}
|
||||
}
|
||||
|
||||
stages.add(stage);
|
||||
}
|
||||
@ -258,42 +269,4 @@ public class WorkflowDefinitionServiceImpl extends BaseServiceImpl<WorkflowDefin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确定节点状态
|
||||
*/
|
||||
private void determineStageStatus(
|
||||
WorkflowExecutionDTO.StageDTO stage,
|
||||
FlowElement element,
|
||||
HistoricActivityInstance historicActivity,
|
||||
List<String> activeActivityIds
|
||||
) {
|
||||
if (historicActivity == null) {
|
||||
// 节点未执行过
|
||||
stage.setStatus(WorkflowInstanceStatus.NOT_STARTED);
|
||||
stage.setStartTime(null);
|
||||
stage.setEndTime(null);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置时间
|
||||
stage.setStartTime(historicActivity.getStartTime());
|
||||
stage.setEndTime(historicActivity.getEndTime());
|
||||
|
||||
// 确定状态
|
||||
if (historicActivity.getEndTime() != null) {
|
||||
// 节点已结束
|
||||
stage.setStatus(historicActivity.getDeleteReason() == null ?
|
||||
WorkflowInstanceStatus.COMPLETED : WorkflowInstanceStatus.FAILED);
|
||||
} else if (element instanceof StartEvent) {
|
||||
// 开始节点特殊处理:有开始时间就视为完成
|
||||
stage.setStatus(WorkflowInstanceStatus.COMPLETED);
|
||||
} else if (activeActivityIds.contains(element.getId())) {
|
||||
// 节点正在执行
|
||||
stage.setStatus(WorkflowInstanceStatus.RUNNING);
|
||||
} else {
|
||||
// 其他情况:节点已开始但未完成,且不在当前活动节点列表中
|
||||
stage.setStatus(WorkflowInstanceStatus.NOT_STARTED);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -79,6 +79,9 @@ public class BpmnConverter {
|
||||
serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
|
||||
serviceTask.setImplementation("${shellTaskDelegate}");
|
||||
|
||||
// 设置为异步执行
|
||||
serviceTask.setAsynchronous(true);
|
||||
|
||||
JsonNode fields = serviceTaskConfig.path("fields");
|
||||
if (fields != null) {
|
||||
fields.fields().forEachRemaining(entry -> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user