|
@@ -26,10 +26,13 @@ import org.activiti.bpmn.model.FlowNode;
|
|
|
import org.activiti.bpmn.model.SequenceFlow;
|
|
import org.activiti.bpmn.model.SequenceFlow;
|
|
|
import org.activiti.engine.*;
|
|
import org.activiti.engine.*;
|
|
|
import org.activiti.engine.delegate.DelegateExecution;
|
|
import org.activiti.engine.delegate.DelegateExecution;
|
|
|
|
|
+import org.activiti.engine.delegate.event.impl.ActivitiEntityWithVariablesEventImpl;
|
|
|
import org.activiti.engine.history.*;
|
|
import org.activiti.engine.history.*;
|
|
|
import org.activiti.engine.impl.RepositoryServiceImpl;
|
|
import org.activiti.engine.impl.RepositoryServiceImpl;
|
|
|
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
|
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
|
|
|
|
+import org.activiti.engine.impl.identity.Authentication;
|
|
|
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
|
|
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
|
|
|
|
|
+import org.activiti.engine.runtime.Execution;
|
|
|
import org.activiti.engine.runtime.ProcessInstance;
|
|
import org.activiti.engine.runtime.ProcessInstance;
|
|
|
import org.activiti.engine.task.Task;
|
|
import org.activiti.engine.task.Task;
|
|
|
import org.activiti.engine.task.TaskQuery;
|
|
import org.activiti.engine.task.TaskQuery;
|
|
@@ -794,5 +797,90 @@ public class ActivitiService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void returnAssignNode(String processKey, String businessKey, String proInstanceId, String curUserId, String createUserId) {
|
|
|
|
|
+
|
|
|
|
|
+ Task task = taskService.createTaskQuery()
|
|
|
|
|
+ .processDefinitionKey(processKey)
|
|
|
|
|
+ .processVariableValueEquals("businessKey", businessKey)
|
|
|
|
|
+ .singleResult();
|
|
|
|
|
+ if(null==task) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery()
|
|
|
|
|
+ .processInstanceId(proInstanceId)
|
|
|
|
|
+ .list();
|
|
|
|
|
+
|
|
|
|
|
+ String myTaskId = null;
|
|
|
|
|
+ HistoricTaskInstance myTask = null;
|
|
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
|
|
+ for(HistoricTaskInstance hti : list) {
|
|
|
|
|
+ if(curUserId.equals(hti.getAssignee())) {
|
|
|
|
|
+ myTaskId = hti.getId();
|
|
|
|
|
+ myTask = hti;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(null==myTaskId) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String processDefinitionId = myTask.getProcessDefinitionId();
|
|
|
|
|
+ // ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
|
|
|
|
|
+ BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
|
|
|
|
|
+
|
|
|
|
|
+ //变量
|
|
|
|
|
+ // Map<String, VariableInstance> variables = runtimeService.getVariableInstances(currentTask.getExecutionId());
|
|
|
|
|
+ String myActivityId = null;
|
|
|
|
|
+ List<HistoricActivityInstance> haiList = historyService.createHistoricActivityInstanceQuery()
|
|
|
|
|
+ .executionId(myTask.getExecutionId()).finished().list();
|
|
|
|
|
+ for(HistoricActivityInstance hai : haiList) {
|
|
|
|
|
+ if(myTaskId.equals(hai.getTaskId())) {
|
|
|
|
|
+ myActivityId = hai.getActivityId();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ FlowNode myFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(myActivityId);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Execution execution = runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult();
|
|
|
|
|
+ String activityId = execution.getActivityId();
|
|
|
|
|
+ logger.warn("------->> 撤回的activityId:" + activityId);
|
|
|
|
|
+ FlowNode flowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(activityId);
|
|
|
|
|
+
|
|
|
|
|
+ //记录原活动方向
|
|
|
|
|
+ List<SequenceFlow> oriSequenceFlows = new ArrayList<SequenceFlow>();
|
|
|
|
|
+ oriSequenceFlows.addAll(flowNode.getOutgoingFlows());
|
|
|
|
|
+
|
|
|
|
|
+ //清理活动方向
|
|
|
|
|
+ flowNode.getOutgoingFlows().clear();
|
|
|
|
|
+ //建立新方向
|
|
|
|
|
+ List<SequenceFlow> newSequenceFlowList = new ArrayList<SequenceFlow>();
|
|
|
|
|
+ SequenceFlow newSequenceFlow = new SequenceFlow();
|
|
|
|
|
+ newSequenceFlow.setId("newSequenceFlowId");
|
|
|
|
|
+ newSequenceFlow.setSourceFlowElement(flowNode);
|
|
|
|
|
+ newSequenceFlow.setTargetFlowElement(myFlowNode);
|
|
|
|
|
+ newSequenceFlowList.add(newSequenceFlow);
|
|
|
|
|
+ flowNode.setOutgoingFlows(newSequenceFlowList);
|
|
|
|
|
+
|
|
|
|
|
+ Authentication.setAuthenticatedUserId(curUserId);
|
|
|
|
|
+ taskService.addComment(task.getId(), task.getProcessInstanceId(), "上级单位撤回");
|
|
|
|
|
+ taskService.setAssignee(task.getId(), createUserId);
|
|
|
|
|
+ taskService.setVariable(task.getId(),"remarks", "上级单位撤回");
|
|
|
|
|
+ taskService.setVariableLocal(task.getId(), "remarks", "上级单位撤回");
|
|
|
|
|
+
|
|
|
|
|
+ Map<String,Object> currentVariables = new HashMap<String,Object>();
|
|
|
|
|
+ currentVariables.put("applier", curUserId);
|
|
|
|
|
+ currentVariables.put("businessKey", businessKey);
|
|
|
|
|
+ currentVariables.put("users", curUserId);
|
|
|
|
|
+ currentVariables.put("remarks", "上级单位撤回");
|
|
|
|
|
+
|
|
|
|
|
+ //完成任务
|
|
|
|
|
+ taskService.complete(task.getId(),currentVariables);
|
|
|
|
|
+ //恢复原方向
|
|
|
|
|
+ flowNode.setOutgoingFlows(oriSequenceFlows);
|
|
|
|
|
+ logger.info("回滚完成:businessKey " + businessKey);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|