| | |
| | | import com.vci.ubcs.flow.engine.service.VICFlowService; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.flowable.bpmn.model.*; |
| | | import org.flowable.engine.*; |
| | | import org.flowable.engine.impl.persistence.entity.ExecutionEntity; |
| | | import org.flowable.engine.repository.ProcessDefinition; |
| | | import org.flowable.engine.runtime.ProcessInstance; |
| | | import org.flowable.task.api.Task; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.support.Kv; |
| | |
| | | private final FlowEngineService flowEngineService; |
| | | private final HistoryService historyService; |
| | | |
| | | private static String MODELKEY = "modelKey";//前端传过来的模型key |
| | | @Override |
| | | public R<BladeFlow> startProcess(FlowTaskDTO flowTaskUserC){ |
| | | String modelKey = flowTaskUserC.getModelKey(); |
| | | String templateId = flowTaskUserC.getTemplateId(); |
| | | Map<String, Object> kvv = flowTaskUserC.getVariables(); |
| | | |
| | | Kv kv = Kv.create() |
| | | .set(ProcessConstant.TASK_VARIABLE_CREATE_USER, AuthUtil.getUserName()); |
| | | String modelKey = kvv.get(MODELKEY).toString(); |
| | | |
| | | Kv kv = Kv.create().set(ProcessConstant.TASK_VARIABLE_CREATE_USER, AuthUtil.getUserName()); |
| | | |
| | | // 设置流程启动用户 |
| | | identityService.setAuthenticatedUserId(TaskUtil.getTaskUser()); |
| | |
| | | String processDefinitionId = latesDefinition.getId(); |
| | | |
| | | //查询每一步审核人 |
| | | List<FlowTaskUser> taskUsers = flowTaskUserService.getTaskUserByTemplateAndModelKey(templateId,modelKey); |
| | | Set<String> taskIdSet = new HashSet<>(); |
| | | List<FlowTaskUser> taskUsers = flowTaskUserC.getFlowTaskUsers(); |
| | | // Set<String> taskIdSet = new HashSet<>(); |
| | | for (FlowTaskUser taskUser:taskUsers){ |
| | | kv.put(taskUser.getTaskId(),TaskUtil.getTaskUser(taskUser.getUserId())); |
| | | taskIdSet.add(taskUser.getTaskId()); |
| | | // taskIdSet.add(taskUser.getTaskId()); |
| | | } |
| | | |
| | | //对比配置的审核人员和流程中节点是否一致,可能存在流程节点变更了,多了或者少了节点,但是配置审核人员的节点没有变 |
| | |
| | | // } |
| | | |
| | | //流程中文件、变量等 |
| | | //do.. |
| | | if(kvv!=null&&!kvv.isEmpty()){ |
| | | kv.putAll(kvv); |
| | | } |
| | | |
| | | ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId, modelKey, kv); |
| | | // 组装流程通用类 |
| | | BladeFlow flow = new BladeFlow(); |
| | | flow.setProcessInstanceId(processInstance.getId()); |
| | | |
| | | // //设置下一步审核人 |
| | | // Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).active().singleResult(); |
| | | // String taskId = task.getTaskDefinitionKey(); |
| | | // String assignee = null; |
| | | // for (FlowTaskUser taskUser:taskUsers) { |
| | | // if(taskId.equals(taskUser.getTaskId())){ |
| | | // assignee = taskUser.getUserId(); |
| | | // } |
| | | // } |
| | | // if(StringUtils.isEmpty(assignee)){ |
| | | // throw new ServiceException(taskId+"没有配置审核人!"); |
| | | // } |
| | | // taskService.setAssignee(task.getId(),assignee); |
| | | return R.data(flow); |
| | | } |
| | | |
| | |
| | | //这个实例的所有节点 |
| | | ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); |
| | | Map<String, Object> processVariables = processInstance.getProcessVariables();//所有参数 |
| | | flowTaskDTO.setVars(processVariables); |
| | | flowTaskDTO.setVariables(processVariables); |
| | | |
| | | String modelKey = processInstance.getProcessDefinitionKey(); |
| | | List<FlowTaskDTO> mis = flowEngineService.getNodeByFlowableKey(modelKey); |
| | |
| | | // 下一个审批节点 |
| | | FlowElement targetFlow = sequenceFlow.getTargetFlowElement(); |
| | | if (targetFlow instanceof UserTask) { |
| | | System.out.println("下一节点: id=" + targetFlow.getId() + ",name=" + targetFlow.getName()); |
| | | FlowTaskDTO flowTaskUserCi = new FlowTaskDTO(); |
| | | //flowTaskUserCi.setConditionKey(null); |
| | | //flowTaskUserCi.setConditionValue(null); |
| | | flowTaskUserCi.setToName("同意"); |
| | | flowTaskUserCi.setToTaskId(targetFlow.getId()); |
| | | flowTaskUserCi.setToTaskName(targetFlow.getName()); |
| | | taskList.add(flowTaskUserCi); |
| | | } |
| | | |
| | | //结束 |
| | | if (targetFlow instanceof EndEvent) { |
| | | FlowTaskDTO flowTaskUserCi = new FlowTaskDTO(); |
| | | //flowTaskUserCi.setConditionKey(null); |
| | | //flowTaskUserCi.setConditionValue(null); |
| | | flowTaskUserCi.setToName("同意"); |
| | | flowTaskUserCi.setToTaskId(targetFlow.getId()); |
| | | flowTaskUserCi.setToTaskName(targetFlow.getName()); |
| | | taskList.add(flowTaskUserCi); |
| | | } |
| | | // 如果下个审批节点为排他网关 |
| | | if (targetFlow instanceof ExclusiveGateway) { |
| | |
| | | if(taskId.equals(flowTaskUserCi.getTaskId())){ |
| | | flowTaskUserCi.setCondition(conditionExpression); |
| | | if(conditionExpression.split("=").length>1) { |
| | | flowTaskUserCi.setConditionKey(conditionExpression.split("=")[0]); |
| | | flowTaskUserCi.setConditionValue(conditionExpression.split("=")[1]); |
| | | conditionExpression = conditionExpression.replace("${","").replace("}","").replaceAll("\"",""); |
| | | String[] conditionExpressionStr = conditionExpression.split("=="); |
| | | if(conditionExpression.contains("<")){ |
| | | conditionExpressionStr = conditionExpression.split("<"); |
| | | }else if(conditionExpression.contains("<=")){ |
| | | conditionExpressionStr = conditionExpression.split("<="); |
| | | }else if(conditionExpression.contains(">")){ |
| | | conditionExpressionStr = conditionExpression.split(">"); |
| | | }else if(conditionExpression.contains(">=")){ |
| | | conditionExpressionStr = conditionExpression.split(">="); |
| | | } |
| | | flowTaskUserCi.setConditionKey(conditionExpressionStr.length>0?conditionExpressionStr[0]:null); |
| | | flowTaskUserCi.setConditionValue(conditionExpressionStr.length>1?conditionExpressionStr[1]:null); |
| | | } |
| | | flowTaskUserCi.setToName(name); |
| | | flowTaskUserCi.setToTaskId(taskId); |