|
@@ -1,115 +1,115 @@
|
|
|
-package com.qmth.sop.business.activiti;
|
|
|
-
|
|
|
-import com.qmth.sop.common.contant.SpringContextHolder;
|
|
|
-import com.qmth.sop.common.contant.SystemConstant;
|
|
|
-import org.activiti.bpmn.model.BpmnModel;
|
|
|
-import org.activiti.bpmn.model.FlowNode;
|
|
|
-import org.activiti.engine.HistoryService;
|
|
|
-import org.activiti.engine.ManagementService;
|
|
|
-import org.activiti.engine.RepositoryService;
|
|
|
-import org.activiti.engine.history.HistoricTaskInstance;
|
|
|
-import org.activiti.engine.impl.history.HistoryManager;
|
|
|
-import org.activiti.engine.impl.interceptor.Command;
|
|
|
-import org.activiti.engine.impl.interceptor.CommandContext;
|
|
|
-import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
|
|
|
-import org.activiti.engine.impl.persistence.entity.TaskEntity;
|
|
|
-import org.activiti.engine.impl.persistence.entity.TaskEntityManager;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
-
|
|
|
-import java.util.*;
|
|
|
-
|
|
|
-/**
|
|
|
- * @Description: 驳回任意节点
|
|
|
- * @Param:
|
|
|
- * @return:
|
|
|
- * @Author: wangliang
|
|
|
- * @Date: 2023/7/22
|
|
|
- */
|
|
|
-public class ProcessEventRejectCmd implements Command {
|
|
|
-
|
|
|
- /**
|
|
|
- * 任务ID
|
|
|
- */
|
|
|
- private String taskId;
|
|
|
-
|
|
|
- /**
|
|
|
- * 目标任务节点key
|
|
|
- */
|
|
|
- private String destTaskKey;
|
|
|
-
|
|
|
-
|
|
|
- private Map<String, Object> map = new HashMap<>();
|
|
|
-
|
|
|
- /**
|
|
|
- * @param taskId 任务ID
|
|
|
- * @param destTaskKey 目标任务节点key
|
|
|
- */
|
|
|
- public ProcessEventRejectCmd(String taskId, String destTaskKey, Map<String, Object> map) {
|
|
|
- this.taskId = taskId;
|
|
|
- this.destTaskKey = destTaskKey;
|
|
|
- this.map = map;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Object execute(CommandContext commandContext) {
|
|
|
- RepositoryService repositoryService = SpringContextHolder.getBean(RepositoryService.class);
|
|
|
- HistoryService historyService = SpringContextHolder.getBean(HistoryService.class);
|
|
|
- //获取任务实例管理类
|
|
|
- TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();
|
|
|
- //获取当前任务实例
|
|
|
- TaskEntity currentTask = taskEntityManager.findById(taskId);
|
|
|
-
|
|
|
- List<HistoricTaskInstance> historicTaskInstanceList = historyService.createHistoricTaskInstanceQuery()
|
|
|
- .processInstanceId(currentTask.getProcessInstanceId()).orderByHistoricTaskInstanceEndTime().desc().list();
|
|
|
-
|
|
|
- //获取当前节点的执行实例
|
|
|
- List<String> rejectApproveIdList = new ArrayList<>();
|
|
|
- if (!CollectionUtils.isEmpty(historicTaskInstanceList)) {
|
|
|
- Integer index = null;
|
|
|
- for (HistoricTaskInstance historicTaskInstance : historicTaskInstanceList) {
|
|
|
- if (Objects.equals(historicTaskInstance.getTaskDefinitionKey(), destTaskKey)) {
|
|
|
- String formKey = historicTaskInstance.getFormKey();
|
|
|
- if (Objects.nonNull(formKey)) {
|
|
|
- index = Integer.valueOf(formKey.substring(formKey.indexOf(".") - 1, formKey.indexOf(".")));
|
|
|
- }
|
|
|
- rejectApproveIdList.add(historicTaskInstance.getAssignee());
|
|
|
- }
|
|
|
- }
|
|
|
- map.put(SystemConstant.ASSIGNEE + index, rejectApproveIdList);
|
|
|
- map.put(SystemConstant.DEFAULT_ASSIGNEE_LIST + index, rejectApproveIdList);
|
|
|
- }
|
|
|
- //获取当前节点的执行实例
|
|
|
- ExecutionEntity execution = currentTask.getExecution();
|
|
|
- execution.setVariables(map);
|
|
|
-
|
|
|
- //获取流程定义id
|
|
|
- String processDefinitionId = execution.getProcessDefinitionId();
|
|
|
- //获取目标节点
|
|
|
- BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
|
|
|
- FlowNode flowElement = (FlowNode) bpmnModel.getMainProcess().getFlowElement(destTaskKey);
|
|
|
-
|
|
|
- //获取历史管理
|
|
|
- HistoryManager historyManager = commandContext.getHistoryManager();
|
|
|
-
|
|
|
- //通知当前活动结束(更新act_hi_actinst)
|
|
|
- historyManager.recordActivityEnd(execution, "jump to " + taskId);
|
|
|
- //通知任务节点结束(更新act_hi_taskinst)
|
|
|
- historyManager.recordTaskEnd(taskId, "jump to" + destTaskKey);
|
|
|
- //删除正在执行的当前任务
|
|
|
- taskEntityManager.delete(taskId);
|
|
|
- //此时设置执行实例的当前活动节点为目标节点
|
|
|
- execution.setCurrentFlowElement(flowElement);
|
|
|
- //向operations中压入继续流程的操作类
|
|
|
- commandContext.getAgenda().planContinueProcessOperation(execution);
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 跳转任意节点
|
|
|
- *
|
|
|
- * @param managementService
|
|
|
- */
|
|
|
- public void jump(ManagementService managementService) {
|
|
|
- managementService.executeCommand(this);
|
|
|
- }
|
|
|
-}
|
|
|
+//package com.qmth.sop.business.activiti;
|
|
|
+//
|
|
|
+//import com.qmth.sop.common.contant.SpringContextHolder;
|
|
|
+//import com.qmth.sop.common.contant.SystemConstant;
|
|
|
+//import org.activiti.bpmn.model.BpmnModel;
|
|
|
+//import org.activiti.bpmn.model.FlowNode;
|
|
|
+//import org.activiti.engine.HistoryService;
|
|
|
+//import org.activiti.engine.ManagementService;
|
|
|
+//import org.activiti.engine.RepositoryService;
|
|
|
+//import org.activiti.engine.history.HistoricTaskInstance;
|
|
|
+//import org.activiti.engine.impl.history.HistoryManager;
|
|
|
+//import org.activiti.engine.impl.interceptor.Command;
|
|
|
+//import org.activiti.engine.impl.interceptor.CommandContext;
|
|
|
+//import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
|
|
|
+//import org.activiti.engine.impl.persistence.entity.TaskEntity;
|
|
|
+//import org.activiti.engine.impl.persistence.entity.TaskEntityManager;
|
|
|
+//import org.springframework.util.CollectionUtils;
|
|
|
+//
|
|
|
+//import java.util.*;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * @Description: 驳回任意节点
|
|
|
+// * @Param:
|
|
|
+// * @return:
|
|
|
+// * @Author: wangliang
|
|
|
+// * @Date: 2023/7/22
|
|
|
+// */
|
|
|
+//public class ProcessEventRejectCmd implements Command {
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 任务ID
|
|
|
+// */
|
|
|
+// private String taskId;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 目标任务节点key
|
|
|
+// */
|
|
|
+// private String destTaskKey;
|
|
|
+//
|
|
|
+//
|
|
|
+// private Map<String, Object> map = new HashMap<>();
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * @param taskId 任务ID
|
|
|
+// * @param destTaskKey 目标任务节点key
|
|
|
+// */
|
|
|
+// public ProcessEventRejectCmd(String taskId, String destTaskKey, Map<String, Object> map) {
|
|
|
+// this.taskId = taskId;
|
|
|
+// this.destTaskKey = destTaskKey;
|
|
|
+// this.map = map;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Object execute(CommandContext commandContext) {
|
|
|
+// RepositoryService repositoryService = SpringContextHolder.getBean(RepositoryService.class);
|
|
|
+// HistoryService historyService = SpringContextHolder.getBean(HistoryService.class);
|
|
|
+// //获取任务实例管理类
|
|
|
+// TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();
|
|
|
+// //获取当前任务实例
|
|
|
+// TaskEntity currentTask = taskEntityManager.findById(taskId);
|
|
|
+//
|
|
|
+// List<HistoricTaskInstance> historicTaskInstanceList = historyService.createHistoricTaskInstanceQuery()
|
|
|
+// .processInstanceId(currentTask.getProcessInstanceId()).orderByHistoricTaskInstanceEndTime().desc().list();
|
|
|
+//
|
|
|
+// //获取当前节点的执行实例
|
|
|
+// List<String> rejectApproveIdList = new ArrayList<>();
|
|
|
+// if (!CollectionUtils.isEmpty(historicTaskInstanceList)) {
|
|
|
+// Integer index = null;
|
|
|
+// for (HistoricTaskInstance historicTaskInstance : historicTaskInstanceList) {
|
|
|
+// if (Objects.equals(historicTaskInstance.getTaskDefinitionKey(), destTaskKey)) {
|
|
|
+// String formKey = historicTaskInstance.getFormKey();
|
|
|
+// if (Objects.nonNull(formKey)) {
|
|
|
+// index = Integer.valueOf(formKey.substring(formKey.indexOf(".") - 1, formKey.indexOf(".")));
|
|
|
+// }
|
|
|
+// rejectApproveIdList.add(historicTaskInstance.getAssignee());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// map.put(SystemConstant.ASSIGNEE + index, rejectApproveIdList);
|
|
|
+// map.put(SystemConstant.DEFAULT_ASSIGNEE_LIST + index, rejectApproveIdList);
|
|
|
+// }
|
|
|
+// //获取当前节点的执行实例
|
|
|
+// ExecutionEntity execution = currentTask.getExecution();
|
|
|
+// execution.setVariables(map);
|
|
|
+//
|
|
|
+// //获取流程定义id
|
|
|
+// String processDefinitionId = execution.getProcessDefinitionId();
|
|
|
+// //获取目标节点
|
|
|
+// BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
|
|
|
+// FlowNode flowElement = (FlowNode) bpmnModel.getMainProcess().getFlowElement(destTaskKey);
|
|
|
+//
|
|
|
+// //获取历史管理
|
|
|
+// HistoryManager historyManager = commandContext.getHistoryManager();
|
|
|
+//
|
|
|
+// //通知当前活动结束(更新act_hi_actinst)
|
|
|
+// historyManager.recordActivityEnd(execution, "jump to " + taskId);
|
|
|
+// //通知任务节点结束(更新act_hi_taskinst)
|
|
|
+// historyManager.recordTaskEnd(taskId, "jump to" + destTaskKey);
|
|
|
+// //删除正在执行的当前任务
|
|
|
+// taskEntityManager.delete(taskId);
|
|
|
+// //此时设置执行实例的当前活动节点为目标节点
|
|
|
+// execution.setCurrentFlowElement(flowElement);
|
|
|
+// //向operations中压入继续流程的操作类
|
|
|
+// commandContext.getAgenda().planContinueProcessOperation(execution);
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 跳转任意节点
|
|
|
+// *
|
|
|
+// * @param managementService
|
|
|
+// */
|
|
|
+// public void jump(ManagementService managementService) {
|
|
|
+// managementService.executeCommand(this);
|
|
|
+// }
|
|
|
+//}
|