| | |
| | | |
| | | import com.java110.core.base.smo.BaseServiceSMO; |
| | | import com.java110.dto.PageDto; |
| | | import com.java110.dto.contract.ContractDto; |
| | | import com.java110.dto.contractChangePlan.ContractChangePlanDto; |
| | | import com.java110.dto.workflow.WorkflowDto; |
| | | import com.java110.entity.audit.AuditUser; |
| | | import com.java110.intf.common.IContractChangeUserInnerServiceSMO; |
| | | import com.java110.intf.common.IWorkflowInnerServiceSMO; |
| | | import com.java110.intf.store.IContractChangePlanInnerServiceSMO; |
| | | import com.java110.po.contract.ContractPo; |
| | | import com.java110.po.contractChangePlan.ContractChangePlanPo; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.utils.util.FlowUtil; |
| | | import com.java110.utils.util.StringUtil; |
| | | import org.activiti.engine.HistoryService; |
| | | import org.activiti.engine.ProcessEngine; |
| | | import org.activiti.engine.RuntimeService; |
| | | import org.activiti.engine.TaskService; |
| | | import org.activiti.bpmn.model.*; |
| | | import org.activiti.engine.*; |
| | | import org.activiti.engine.history.HistoricProcessInstance; |
| | | import org.activiti.engine.history.HistoricTaskInstance; |
| | | import org.activiti.engine.history.HistoricTaskInstanceQuery; |
| | | import org.activiti.engine.impl.identity.Authentication; |
| | | import org.activiti.engine.query.Query; |
| | | import org.activiti.engine.runtime.ProcessInstance; |
| | | import org.activiti.engine.task.Task; |
| | |
| | | |
| | | @Autowired |
| | | private IWorkflowInnerServiceSMO workflowInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private RepositoryService repositoryService; |
| | | |
| | | /** |
| | | * 启动流程 |
| | |
| | | //将信息加入map,以便传入流程中 |
| | | Map<String, Object> variables = new HashMap<String, Object>(); |
| | | variables.put("contractChangePlanDto", contractChangePlanDto); |
| | | |
| | | variables.put("userId", contractChangePlanDto.getCurrentUserId()); |
| | | variables.put("startUserId", contractChangePlanDto.getCurrentUserId()); |
| | | variables.put("nextUserId", contractChangePlanDto.getNextUserId()); |
| | | //开启流程 |
| | | ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(getWorkflowDto(contractChangePlanDto.getStoreId()), variables); |
| | | ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(getWorkflowDto(contractChangePlanDto.getStoreId()),contractChangePlanDto.getPlanId(), variables); |
| | | //将得到的实例流程id值赋给之前设置的变量 |
| | | String processInstanceId = processInstance.getId(); |
| | | // System.out.println("流程开启成功.......实例流程id:" + processInstanceId); |
| | |
| | | String business_key = pi.getBusinessKey(); |
| | | contractIds.add(business_key); |
| | | taskBusinessKeyMap.put(business_key, task.getId()); |
| | | |
| | | //计算是否有 审核按钮 |
| | | BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId()); |
| | | FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(task.getTaskDefinitionKey()); |
| | | //获取当前节点输出连线 |
| | | List<SequenceFlow> outgoingFlows = flowNode.getOutgoingFlows(); |
| | | //计算是否有结束按钮 |
| | | boolean isReturn; |
| | | for (SequenceFlow outgoingFlow : outgoingFlows) { |
| | | //获取输出节点元素 |
| | | FlowElement targetFlowElement = outgoingFlow.getTargetFlowElement(); |
| | | isReturn = false; |
| | | //排除非用户任务接点 |
| | | if (targetFlowElement instanceof UserTask) { |
| | | //判断输出节点的el表达式 |
| | | Map vars = new HashMap(); |
| | | vars.put("flag", "false"); // 1100 |
| | | if (FlowUtil.isCondition(outgoingFlow.getConditionExpression(), vars)) { |
| | | isReturn = true; |
| | | } |
| | | |
| | | if (!isReturn) { |
| | | String assignee = ((UserTask) targetFlowElement).getAssignee(); |
| | | if (!StringUtil.isEmpty(assignee)) { |
| | | taskBusinessKeyMap.put(business_key + "_hasAudit", "1"); |
| | | } |
| | | } |
| | | } |
| | | //如果下一个为 结束节点 |
| | | if (targetFlowElement instanceof EndEvent) { |
| | | //true 获取输出节点名称 |
| | | taskBusinessKeyMap.put(business_key + "_hasEnd", "1"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (contractIds == null || contractIds.size() == 0) { |
| | |
| | | List<ContractChangePlanDto> tmpContractChangePlanDtos = contractChangePlanInnerServiceSMOImpl.queryContractChangePlans(contractChangePlanDto); |
| | | |
| | | for (ContractChangePlanDto tmpContractChangePlanDto : tmpContractChangePlanDtos) { |
| | | tmpContractChangePlanDto.setTaskId(taskBusinessKeyMap.get(tmpContractChangePlanDto.getContractId())); |
| | | tmpContractChangePlanDto.setTaskId(taskBusinessKeyMap.get(tmpContractChangePlanDto.getPlanId())); |
| | | tmpContractChangePlanDto.setHasAudit(taskBusinessKeyMap.get(tmpContractChangePlanDto.getContractId() + "_hasAudit")); |
| | | tmpContractChangePlanDto.setHasEnd(taskBusinessKeyMap.get(tmpContractChangePlanDto.getContractId() + "_hasEnd")); |
| | | } |
| | | return tmpContractChangePlanDtos; |
| | | } |
| | |
| | | List<ContractChangePlanDto> tmpContractChangePlanDtos = contractChangePlanInnerServiceSMOImpl.queryContractChangePlans(contractChangePlanDto); |
| | | |
| | | for (ContractChangePlanDto tmpContractChangePlanDto : tmpContractChangePlanDtos) { |
| | | tmpContractChangePlanDto.setTaskId(taskBusinessKeyMap.get(tmpContractChangePlanDto.getContractId())); |
| | | tmpContractChangePlanDto.setTaskId(taskBusinessKeyMap.get(tmpContractChangePlanDto.getPlanId())); |
| | | } |
| | | return tmpContractChangePlanDtos; |
| | | } |
| | | |
| | | public boolean completeTask(@RequestBody ContractChangePlanDto contractChangePlanDto) { |
| | | TaskService taskService = processEngine.getTaskService(); |
| | | Task task = taskService.createTaskQuery().taskId(contractChangePlanDto.getTaskId()).singleResult(); |
| | | String processInstanceId = task.getProcessInstanceId(); |
| | | Authentication.setAuthenticatedUserId(contractChangePlanDto.getCurrentUserId()); |
| | | taskService.addComment(contractChangePlanDto.getTaskId(), processInstanceId, contractChangePlanDto.getAuditMessage()); |
| | | Map<String, Object> variables = new HashMap<String, Object>(); |
| | | variables.put("auditCode", contractChangePlanDto.getAuditCode()); |
| | | variables.put("currentUserId", contractChangePlanDto.getCurrentUserId()); |
| | | variables.put("flag", "1200".equals(contractChangePlanDto.getAuditCode()) ? "false" : "true"); |
| | | variables.put("startUserId", contractChangePlanDto.getStartUserId()); |
| | | variables.put("nextUserId", contractChangePlanDto.getNextUserId()); |
| | | taskService.complete(contractChangePlanDto.getTaskId(), variables); |
| | | |
| | | ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); |
| | | if (pi == null) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | //删除任务 |
| | | public boolean deleteTask(@RequestBody ContractChangePlanPo contractChangePlanPo) { |
| | | TaskService taskService = processEngine.getTaskService(); |
| | | |
| | | TaskQuery query = taskService.createTaskQuery().processInstanceBusinessKey(contractChangePlanPo.getPlanId()); |
| | | query.orderByTaskCreateTime().desc(); |
| | | List<Task> list = query.list(); |
| | | |
| | | if (list == null || list.size() < 1) { |
| | | return true; |
| | | } |
| | | |
| | | for (Task task : list) { |
| | | String processInstanceId = task.getProcessInstanceId(); |
| | | //3.使用流程实例,查询 |
| | | runtimeService.deleteProcessInstance(processInstanceId, "取消合同"); |
| | | |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | } |