From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master
---
jnpf-flow-engine/src/main/java/jnpf/workflow/flowable/cmd/JumpCmd.java | 126 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 126 insertions(+), 0 deletions(-)
diff --git a/jnpf-flow-engine/src/main/java/jnpf/workflow/flowable/cmd/JumpCmd.java b/jnpf-flow-engine/src/main/java/jnpf/workflow/flowable/cmd/JumpCmd.java
new file mode 100644
index 0000000..93f3523
--- /dev/null
+++ b/jnpf-flow-engine/src/main/java/jnpf/workflow/flowable/cmd/JumpCmd.java
@@ -0,0 +1,126 @@
+package jnpf.workflow.flowable.cmd;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.flowable.bpmn.model.BpmnModel;
+import org.flowable.bpmn.model.FlowNode;
+import org.flowable.common.engine.impl.interceptor.Command;
+import org.flowable.common.engine.impl.interceptor.CommandContext;
+import org.flowable.engine.RuntimeService;
+import org.flowable.engine.history.HistoricActivityInstance;
+import org.flowable.engine.impl.HistoricActivityInstanceQueryImpl;
+import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
+import org.flowable.engine.impl.persistence.entity.ExecutionEntityManager;
+import org.flowable.engine.impl.persistence.entity.HistoricActivityInstanceEntity;
+import org.flowable.engine.impl.util.CommandContextUtil;
+import org.flowable.engine.runtime.Execution;
+import org.flowable.task.api.history.HistoricTaskInstance;
+import org.flowable.task.service.HistoricTaskService;
+import org.flowable.task.service.impl.HistoricTaskInstanceQueryImpl;
+import org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntity;
+import org.flowable.variable.service.VariableService;
+import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity;
+
+import cn.hutool.core.collection.CollectionUtil;
+
+/**
+ * 鑷畾涔夎妭鐐硅烦杞懡浠わ細鍒犻櫎婧愯妭鐐规墽琛屾祦锛堝惈鍙橀噺銆佸巻鍙蹭换鍔℃爣璁帮級锛�
+ * 鍦ㄧ洰鏍囪妭鐐归噸寤哄瓙鎵ц娴佸苟鎭㈠鍙橀噺锛岀劧鍚庣户缁帹杩涙祦绋嬨��
+ * 鐢遍粦鐩� jar 鍙嶇紪璇戦�愯淇濈湡杩樺師锛屽嬁鍋�"椤烘墜浼樺寲"銆�
+ */
+public class JumpCmd implements Command<Void> {
+
+ private final String processInstanceId;
+ private final List<String> sourceTaskDefIdList;
+ private final List<String> targetFlowNodeIdList;
+ private final String deleteReason;
+ private final BpmnModel bpmnModel;
+ private final RuntimeService runtimeService;
+ private final Map<String, List<VariableInstanceEntity>> varMap = new ConcurrentHashMap<>();
+
+ public JumpCmd(String processInstanceId, List<String> sourceTaskDefIdList, List<String> targetFlowNodeIdList,
+ String deleteReason, BpmnModel bpmnModel, RuntimeService runtimeService) {
+ this.processInstanceId = processInstanceId;
+ this.sourceTaskDefIdList = sourceTaskDefIdList;
+ this.deleteReason = deleteReason;
+ this.targetFlowNodeIdList = targetFlowNodeIdList;
+ this.bpmnModel = bpmnModel;
+ this.runtimeService = runtimeService;
+ }
+
+ @Override
+ public Void execute(CommandContext commandContext) {
+ ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
+ handleExecution(commandContext);
+ handleActInst(commandContext);
+ targetFlowNodeIdList.forEach(targetId -> {
+ FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(targetId);
+ ExecutionEntity processExecution = executionEntityManager.findById(processInstanceId);
+ ExecutionEntity childExecution = executionEntityManager.createChildExecution(processExecution);
+ childExecution.setCurrentFlowElement(flowNode);
+ VariableService variableService = CommandContextUtil.getVariableService();
+ List<VariableInstanceEntity> variableInstanceEntities = varMap.get(flowNode.getId());
+ if (CollectionUtil.isNotEmpty(variableInstanceEntities)) {
+ variableInstanceEntities.forEach(var -> {
+ var.setExecutionId(childExecution.getId());
+ variableService.insertVariableInstance(var);
+ });
+ }
+ executionEntityManager.insert(childExecution);
+ CommandContextUtil.getAgenda().planContinueProcessOperation(childExecution);
+ });
+ return null;
+ }
+
+ private void handleActInst(CommandContext commandContext) {
+ for (String str : sourceTaskDefIdList) {
+ HistoricActivityInstanceQueryImpl query = (HistoricActivityInstanceQueryImpl) new HistoricActivityInstanceQueryImpl()
+ .activityId(str).processInstanceId(processInstanceId).unfinished();
+ List<HistoricActivityInstance> activityInstances =
+ CommandContextUtil.getHistoricActivityInstanceEntityManager().findHistoricActivityInstancesByQueryCriteria(query);
+ for (HistoricActivityInstance activity : activityInstances) {
+ HistoricActivityInstanceEntity activityEntity = (HistoricActivityInstanceEntity) activity;
+ activityEntity.setDeleted(true);
+ activityEntity.setDeleteReason(deleteReason);
+ CommandContextUtil.getHistoricActivityInstanceEntityManager().update(activityEntity);
+ }
+ }
+ }
+
+ private void handleExecution(CommandContext commandContext) {
+ ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
+ HistoricTaskService historicTaskService = CommandContextUtil.getHistoricTaskService();
+ VariableService variableService = CommandContextUtil.getVariableService();
+ for (String str : sourceTaskDefIdList) {
+ List<Execution> executionEntities = runtimeService.createExecutionQuery()
+ .processInstanceId(processInstanceId).activityId(str).list();
+ for (Execution parentExecution : executionEntities) {
+ List<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(parentExecution.getId());
+ for (ExecutionEntity childExecution : childExecutions) {
+ List<VariableInstanceEntity> variableInstances = variableService.findVariableInstancesByExecutionId(childExecution.getId());
+ varMap.put(parentExecution.getActivityId(), variableInstances);
+ variableInstances.forEach(variableService::deleteVariableInstance);
+ executionEntityManager.deleteExecutionAndRelatedData(childExecution, deleteReason, false);
+ HistoricTaskInstanceQueryImpl query = (HistoricTaskInstanceQueryImpl) new HistoricTaskInstanceQueryImpl()
+ .executionId(childExecution.getId()).processInstanceId(processInstanceId);
+ List<HistoricTaskInstance> historicTaskInstances = historicTaskService.findHistoricTaskInstancesByQueryCriteria(query);
+ if (!CollectionUtil.isNotEmpty(historicTaskInstances)) {
+ continue;
+ }
+ for (HistoricTaskInstance historicTaskInstance : historicTaskInstances) {
+ HistoricTaskInstanceEntity entity = (HistoricTaskInstanceEntity) historicTaskInstance;
+ entity.setDeleteReason(deleteReason);
+ historicTaskService.updateHistoricTask(entity, true);
+ }
+ }
+ List<VariableInstanceEntity> variableInstances = variableService.findVariableInstancesByExecutionId(parentExecution.getId());
+ varMap.put(parentExecution.getActivityId(), variableInstances);
+ variableInstances.forEach(variableService::deleteVariableInstance);
+ ExecutionEntity parentExecutionEntity = (ExecutionEntity) parentExecution;
+ executionEntityManager.deleteExecutionAndRelatedData(parentExecutionEntity, deleteReason, false);
+ }
+ }
+ }
+}
--
Gitblit v1.8.0