Kaynağa Gözat

流程引擎更新

yzc 1 yıl önce
ebeveyn
işleme
6f68c12dcb

+ 30 - 21
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowExampleServiceImpl.java

@@ -12,7 +12,10 @@ import com.fjhx.flow.entity.flow.dto.SetStartDataDto;
 import com.fjhx.flow.entity.flow.po.*;
 import com.fjhx.flow.entity.flow.vo.ApprovalRecordVo;
 import com.fjhx.flow.entity.flow.vo.FlowExampleVo;
-import com.fjhx.flow.enums.*;
+import com.fjhx.flow.enums.FlowStatusEnum;
+import com.fjhx.flow.enums.HandleTypeEnum;
+import com.fjhx.flow.enums.NodeHandleTypeEnum;
+import com.fjhx.flow.enums.NodeTypeEnum;
 import com.fjhx.flow.mapper.flow.FlowExampleMapper;
 import com.fjhx.flow.service.flow.*;
 import com.ruoyi.common.constant.BaseSourceConstant;
@@ -267,7 +270,7 @@ public class FlowExampleServiceImpl extends ServiceImpl<FlowExampleMapper, FlowE
                 .set(BasePo::getUpdateTime, new Date())
         );
 
-        flowExampleCurrentService.remove(q->q.eq(FlowExampleCurrent::getFlowExampleId,id));
+        flowExampleCurrentService.remove(q -> q.eq(FlowExampleCurrent::getFlowExampleId, id));
     }
 
     private List<ApprovalRecordVo.ButtonInfo> getButtonInfoList(FlowExample flowExample,
@@ -281,7 +284,7 @@ public class FlowExampleServiceImpl extends ServiceImpl<FlowExampleMapper, FlowE
                 .eq(FlowExampleCurrent::getFlowExampleId, flowExample.getId())
         );
 
-        if(!handleUserIds.contains(SecurityUtils.getUserId())) {
+        if (!handleUserIds.contains(SecurityUtils.getUserId())) {
             if (FlowStatusEnum.PASS.getKey().equals(status)
                     || FlowStatusEnum.REJECT.getKey().equals(status)
                     || !handleUserIds.contains(SecurityUtils.getUserId())
@@ -305,7 +308,7 @@ public class FlowExampleServiceImpl extends ServiceImpl<FlowExampleMapper, FlowE
         }
 
         //如果节点是抄送节点
-        if(NodeHandleTypeEnum.CARBON_COPY.equals(NodeHandleTypeEnum.getEnum(flowDefinitionNode.getNodeHandleType()))){
+        if (NodeHandleTypeEnum.CARBON_COPY.equals(NodeHandleTypeEnum.getEnum(flowDefinitionNode.getNodeHandleType()))) {
             ApprovalRecordVo.ButtonInfo buttonInfo = new ApprovalRecordVo.ButtonInfo();
             buttonInfo.setType(HandleTypeEnum.SKIP_TO_NEXT.getKey());
             buttonInfo.setName("已读");
@@ -371,28 +374,34 @@ public class FlowExampleServiceImpl extends ServiceImpl<FlowExampleMapper, FlowE
                 .eq(FlowDefinitionLine::getFlowDefinitionId, definitionId)
         );
 
-        // 节点Map
-        Map<Long, FlowDefinitionNode> flowDefinitionNodeMap = flowDefinitionNodeList.stream()
-                .collect(Collectors.toMap(FlowDefinitionNode::getId, Function.identity(), (t1, t2) -> t2));
-
         List<FlowDefinitionLine> flowDefinitionLineList = flowLineMap.get(definitionNodeId);
         while (flowDefinitionLineList != null) {
-            Long targetId = flowDefinitionLineList.get(0).getTargetId();
-            FlowDefinitionNode nextNode = flowDefinitionNodeMap.get(targetId);
-
-            Integer nodeType = nextNode.getNodeType();
-
-            ApprovalRecordVo.Record record = new ApprovalRecordVo.Record();
-            record.setStatus(3);
-            record.setNodeId(nextNode.getId());
-            record.setNodeType(nodeType);
-            record.setNodeName(nextNode.getNodeName());
-            recordList.add(record);
+            List<Long> targetIds = flowDefinitionLineList.stream()
+                    .map(FlowDefinitionLine::getTargetId).collect(Collectors.toList());
+            List<FlowDefinitionNode> nextNodeList = flowDefinitionNodeList.stream()
+                    .filter(item -> targetIds.contains(item.getId())).collect(Collectors.toList());
+
+            FlowDefinitionNode endNode = null;
+
+            for (FlowDefinitionNode nextNode : nextNodeList) {
+                Integer nodeType = nextNode.getNodeType();
+
+                ApprovalRecordVo.Record record = new ApprovalRecordVo.Record();
+                record.setStatus(3);
+                record.setNodeId(nextNode.getId());
+                record.setNodeType(nodeType);
+                record.setNodeName(nextNode.getNodeName());
+                recordList.add(record);
+
+                if (NodeTypeEnum.END.getKey().equals(nodeType)) {
+                    endNode = nextNode;
+                }
+            }
 
-            if (NodeTypeEnum.END.getKey().equals(nodeType)) {
+            if (endNode!=null ||  flowDefinitionLineList.size()!=1) {
                 break;
             } else {
-                flowDefinitionLineList = flowLineMap.get(nextNode.getId());
+                flowDefinitionLineList = flowLineMap.get(nextNodeList.get(0).getId());
             }
         }
     }