From af73b1917e58e37daaa3e63f5303da1056cedfa3 Mon Sep 17 00:00:00 2001 From: wang1 <844966816@qq.com> Date: 星期四, 13 七月 2023 18:18:26 +0800 Subject: [PATCH] 修复生命周期调试异常,整理流程代码 --- Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/service/impl/VCIFlowserviceImpl.java | 154 +++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 125 insertions(+), 29 deletions(-) diff --git a/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/service/impl/VCIFlowserviceImpl.java b/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/service/impl/VCIFlowserviceImpl.java index 9012c4b..4a1ea85 100644 --- a/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/service/impl/VCIFlowserviceImpl.java +++ b/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/service/impl/VCIFlowserviceImpl.java @@ -16,15 +16,20 @@ */ package com.vci.ubcs.flow.engine.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.vci.ubcs.flow.core.constant.ProcessConstant; +import com.vci.ubcs.flow.core.dto.FlowTaskDTO; import com.vci.ubcs.flow.core.entity.BladeFlow; +import com.vci.ubcs.flow.core.entity.FlowTaskUser; import com.vci.ubcs.flow.core.utils.TaskUtil; import com.vci.ubcs.flow.engine.entity.*; import com.vci.ubcs.flow.engine.service.FlowEngineService; import com.vci.ubcs.flow.engine.service.FlowTaskUserService; +import com.vci.ubcs.flow.engine.service.ProcessStageAttrService; 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; @@ -32,6 +37,7 @@ import org.flowable.engine.runtime.ProcessInstance; import org.flowable.task.api.Task; import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.mp.support.Condition; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.support.Kv; @@ -55,14 +61,18 @@ private final FlowTaskUserService flowTaskUserService; private final FlowEngineService flowEngineService; private final HistoryService historyService; + private final ProcessStageAttrService processStageAttrService; + private static String MODELKEY = "modelKey";//鍓嶇浼犺繃鏉ョ殑妯″瀷key + private static String TASKID = "taskId";//鍓嶇浼犺繃鏉ョ殑妯″瀷key + private static String PROCESSINSTANCEID = "processInstanceId";//鍓嶇浼犺繃鏉ョ殑妯″瀷key @Override - public R<BladeFlow> startProcess(FlowTaskUserC flowTaskUserC){ - String modelKey = flowTaskUserC.getModelKey(); - String templateId = flowTaskUserC.getTemplateId(); + public R<BladeFlow> startProcess(FlowTaskDTO flowTaskUserC){ + 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()); @@ -73,73 +83,159 @@ 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()); } //瀵规瘮閰嶇疆鐨勫鏍镐汉鍛樺拰娴佺▼涓妭鐐规槸鍚︿竴鑷达紝鍙兘瀛樺湪娴佺▼鑺傜偣鍙樻洿浜嗭紝澶氫簡鎴栬�呭皯浜嗚妭鐐癸紝浣嗘槸閰嶇疆瀹℃牳浜哄憳鐨勮妭鐐规病鏈夊彉 - List<Map<String,String>> processTasks = flowEngineService.getNodeByFlowableKey(modelKey); - for (Map<String,String> mi:processTasks){ - String taskId = mi.get(flowEngineService.getTaskIdString()); - if(!taskIdSet.contains(taskId)){ - throw new ServiceException("娴佺▼宸查噸鏂伴儴缃诧紝鑺傜偣宸叉敼鍙橈紝璇疯缃鏍镐汉鍛橈紒"); - } - } - if(taskIdSet.size()!=processTasks.size()){ - throw new ServiceException("娴佺▼宸查噸鏂伴儴缃诧紝鑺傜偣宸叉敼鍙橈紝璇疯缃鏍镐汉鍛橈紒"); - } +// List<Map<String,String>> processTasks = flowEngineService.getNodeByFlowableKey(modelKey); +// for (Map<String,String> mi:processTasks){ +// String taskId = mi.get(flowEngineService.getTaskIdString()); +// if(!taskIdSet.contains(taskId)){ +// throw new ServiceException("娴佺▼宸查噸鏂伴儴缃诧紝鑺傜偣宸叉敼鍙橈紝璇疯缃鏍镐汉鍛橈紒"); +// } +// } +// if(taskIdSet.size()!=processTasks.size()){ +// throw new ServiceException("娴佺▼宸查噸鏂伴儴缃诧紝鑺傜偣宸叉敼鍙橈紝璇疯缃鏍镐汉鍛橈紒"); +// } //娴佺▼涓枃浠躲�佸彉閲忕瓑 - //do.. + if(kvv!=null&&!kvv.isEmpty()){ + kv.putAll(kvv); + } ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId, modelKey, kv); // 缁勮娴佺▼閫氱敤绫� BladeFlow flow = new BladeFlow(); flow.setProcessInstanceId(processInstance.getId()); - nextFlowNode("next","039ac1d8-0c1e-11ee-bebb-5c3a4570456d"); +// //璁剧疆涓嬩竴姝ュ鏍镐汉 +// 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); } + public static String NODE_NOW = "now"; + public static String NODE_NEXT = "next"; /** * 鑾峰彇浠诲姟鑺傜偣 * * @param node 鏌ヨ鑺傜偣閫夋嫨 * @param processInstanceId 娴佺▼瀹炰緥id */ - public void nextFlowNode(String node, String processInstanceId) { + public FlowTaskDTO nextFlowNode(String node, String processInstanceId) { + FlowTaskDTO flowTaskDTO = new FlowTaskDTO(); + List<FlowTaskDTO> taskList = new ArrayList<>();//鑺傜偣鎸夐挳 + flowTaskDTO.setToTasks(taskList); Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).active().singleResult(); - ExecutionEntity ee = (ExecutionEntity) runtimeService.createExecutionQuery() .executionId(task.getExecutionId()).singleResult(); // 褰撳墠瀹℃壒鑺傜偣 String crruentActivityId = ee.getActivityId(); BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId()); FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(crruentActivityId); + + //杩欎釜瀹炰緥鐨勬墍鏈夎妭鐐� + ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); + Map<String, Object> processVariables = processInstance.getProcessVariables();//鎵�鏈夊弬鏁� + flowTaskDTO.setVariables(processVariables); + + String modelKey = processInstance.getProcessDefinitionKey(); + List<FlowTaskDTO> mis = flowEngineService.getNodeByFlowableKey(modelKey); + // 杈撳嚭杩炵嚎 List<SequenceFlow> outFlows = flowNode.getOutgoingFlows(); for (SequenceFlow sequenceFlow : outFlows) { //褰撳墠瀹℃壒鑺傜偣 - if ("now".equals(node)) { + if (NODE_NOW.equals(node)) { FlowElement sourceFlowElement = sequenceFlow.getSourceFlowElement(); System.out.println("褰撳墠鑺傜偣: id=" + sourceFlowElement.getId() + ",name=" + sourceFlowElement.getName()); - } else if ("next".equals(node)) { + } else if (NODE_NEXT.equals(node)) { // 涓嬩竴涓鎵硅妭鐐� 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) { - 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 ExclusiveGateway) { + + ExclusiveGateway exclusiveGateway = (ExclusiveGateway) targetFlow; + List<SequenceFlow> exclusiveGatewayOutgoingFlows = exclusiveGateway.getOutgoingFlows(); + for (SequenceFlow nexti:exclusiveGatewayOutgoingFlows){ + String conditionExpression = nexti.getConditionExpression();//condition + String taskId = nexti.getTargetRef();//taskId + String name = nexti.getName();//toName,椹冲洖銆佸悓鎰� + + for (FlowTaskDTO flowTaskUserCi:mis){ + if(taskId.equals(flowTaskUserCi.getTaskId())){ + flowTaskUserCi.setCondition(conditionExpression); + if(conditionExpression.contains("=")||conditionExpression.contains("<")||conditionExpression.contains(">")) { + 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); + flowTaskUserCi.setToTaskName(flowTaskUserCi.getTaskName()); + taskList.add(flowTaskUserCi); + } + } + } } } - - } + + //娴佺▼甯搁噺 + Map<String,Object> variables = runtimeService.getVariables(processInstanceId); + if(!variables.isEmpty()){ + flowTaskDTO.setVariables(variables); + } + + + //鏀惧叆娴佺▼闃舵銆佹祦绋媘odelkey + variables.put(TASKID,crruentActivityId); + variables.put(PROCESSINSTANCEID,processInstanceId); + return flowTaskDTO; } } -- Gitblit v1.9.3