From b24e024f386e7f25a071b58e9267a2c19f20ba1e Mon Sep 17 00:00:00 2001
From: luohairen <3399054449@qq.com>
Date: 星期二, 10 十二月 2024 18:11:47 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 flowable/src/main/java/com/ycl/service/common/TaskCommonService.java |  111 +++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 87 insertions(+), 24 deletions(-)

diff --git a/flowable/src/main/java/com/ycl/service/common/TaskCommonService.java b/flowable/src/main/java/com/ycl/service/common/TaskCommonService.java
index f95cdaf..af2d729 100644
--- a/flowable/src/main/java/com/ycl/service/common/TaskCommonService.java
+++ b/flowable/src/main/java/com/ycl/service/common/TaskCommonService.java
@@ -17,6 +17,7 @@
 import org.springframework.util.StringUtils;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author锛歺p
@@ -30,13 +31,15 @@
     private final RepositoryService repositoryService;
 
     /**
-     * 閫氳繃褰撳墠鑺傜偣瀹氫箟key锛岃幏鍙栧叾涓婁竴涓妭鐐圭殑瀹氫箟id锛屽鏋滃墠闈㈡槸骞惰鐨勪細杩斿洖澶氫釜
+     * 閫氳繃褰撳墠鑺傜偣瀹氫箟key锛岃幏鍙栧叾涓婁竴涓妭鐐逛互鍙婂綋鍓嶈妭鐐圭殑淇℃伅锛屽鏋滃墠闈㈡槸骞惰鐨勪細杩斿洖澶氫釜
      *
      * @param processDefId 娴佺▼瀹氫箟id
-     * @param currentNodeDefId
+     * @param currentNodeDefId 褰撳墠鑺傜偣瀹氫箟id
+     * @param sysFormService 琛ㄥ崟鏈嶅姟灞�
+     * @param needInitCurrentForm 鏄惁闇�瑕佸垵濮嬪寲褰撳墠鑺傜偣鐨勮〃鍗曟暟鎹紝涓�鑸煡璇㈠凡瀹屾垚鐨勪换鍔¤鎯呴渶瑕�
      * @return
      */
-    public List<FormDetailVO> getBeforeNodeDefId(String processDefId, String currentNodeDefId, ISysFormService sysFormService, Boolean needInitCurrentForm) {
+    public List<FormDetailVO> getBeforeNodeDefInfo(String processDefId, String currentNodeDefId, ISysFormService sysFormService, Boolean needInitCurrentForm) {
         // 鑾峰彇娴佺▼瀹氫箟
         ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                 .processDefinitionId(processDefId)
@@ -64,7 +67,7 @@
             }
         }
         if (Objects.isNull(currentElement)) {
-            throw new RuntimeException("鏈壘鍒版敼浠诲姟鐨勬祦绋嬪畾涔夎妭鐐�");
+            throw new RuntimeException("鏈壘鍒拌浠诲姟鐨勬祦绋嬪畾涔夎妭鐐�");
         }
 
         // 鑾峰彇褰撳墠鑺傜偣鐨勮緭鍏�
@@ -88,18 +91,18 @@
 
             defKeys.add(formDetailVO);
         }
-        this.before(currentElement, defKeys);
+        this.beforeNodeInfo(currentElement, defKeys);
 
         return defKeys;
     }
 
     /**
-     * 閫掑綊鑾峰彇褰撳墠鑺傜偣鐨勫墠涓�涓换鍔¤妭鐐筴ey
+     * 閫掑綊鑾峰彇褰撳墠鑺傜偣鐨勫墠涓�涓换鍔¤妭鐐逛俊鎭�
      *
      * @param currentElement
      * @param defKeys
      */
-    private void before(FlowElement currentElement, List<FormDetailVO> defKeys) {
+    private void beforeNodeInfo(FlowElement currentElement, List<FormDetailVO> defKeys) {
         if (currentElement instanceof UserTask) {
             UserTask userTask = (UserTask) currentElement;
             if (! CollectionUtils.isEmpty(userTask.getIncomingFlows())) {
@@ -108,9 +111,10 @@
                         FormDetailVO formDetailVO = new FormDetailVO();
                         formDetailVO.setBeforeNodeDefId(incomingFlow.getSourceFlowElement().getId());
                         formDetailVO.setBeforeNodeName(incomingFlow.getSourceFlowElement().getName());
+                        formDetailVO.setBeforeNodeName(((UserTask) incomingFlow.getSourceFlowElement()).getOwner());
                         defKeys.add(formDetailVO);
                     } else {
-                        before(incomingFlow.getSourceFlowElement(), defKeys);
+                        beforeNodeInfo(incomingFlow.getSourceFlowElement(), defKeys);
                     }
                 }
             }
@@ -124,26 +128,85 @@
                         formDetailVO.setBeforeNodeName(incomingFlow.getSourceFlowElement().getName());
                         defKeys.add(formDetailVO);
                     } else {
-                        before(incomingFlow.getSourceFlowElement(), defKeys);
+                        beforeNodeInfo(incomingFlow.getSourceFlowElement(), defKeys);
                     }
                 }
             }
         }
-//        if (! CollectionUtils.isEmpty(currentElement.getIncomingFlows())) {
-//            for (SequenceFlow incomingFlow : currentElement.getIncomingFlows()) {
-//                if (! (incomingFlow.getSourceFlowElement() instanceof UserTask)) {
-//                    // 涓嶅寘鍚紑濮嬭妭鐐广�佸苟琛岀綉鍏炽�佷簰鏂ョ綉鍏筹紝// TODO 杩橀渶瑕佹帓闄ゅ叾瀹冪壒娈婄被鍨�
-//                    if (! (incomingFlow.getSourceFlowElement() instanceof StartEvent) && ! (incomingFlow.getSourceFlowElement() instanceof ParallelGateway) && ! (incomingFlow.getSourceFlowElement() instanceof ExclusiveGateway)) {
-//                        before((UserTask) (incomingFlow.getSourceFlowElement()), defKeys);
-//                    }
-//                } else {
-//                    FormDetailVO formDetailVO = new FormDetailVO();
-//                    formDetailVO.setBeforeNodeDefId(incomingFlow.getSourceFlowElement().getId());
-//                    formDetailVO.setBeforeNodeName(incomingFlow.getSourceFlowElement().getName());
-//                    defKeys.add(formDetailVO);
-//                }
-//            }
-//        }
+    }
+
+
+    /**
+     * 鑾峰彇褰撳墠鑺傜偣鐨勪笂涓�鑺傜偣id锛屼笉鍙嶆倲褰撳墠鑺傜偣淇℃伅锛屽鏋滃墠闈㈡槸骞惰锛岄偅涔堜細杩斿洖澶氫釜
+     *
+     * @param processDefId 娴佺▼瀹氫箟id
+     * @param currentNodeDefId 褰撳墠鑺傜偣瀹氫箟id
+     * @return
+     */
+    public List<String> getBeforeNodeInfo(String processDefId, String currentNodeDefId) {
+        // 鑾峰彇娴佺▼瀹氫箟
+        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
+                .processDefinitionId(processDefId)
+                .singleResult();
+
+        // 鑾峰彇娴佺▼妯″瀷
+        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefId);
+        if (bpmnModel == null) {
+            throw new RuntimeException("BpmnModel not found for processDefinitionId: " + processDefId);
+        }
+
+        // 鑾峰彇娴佺▼瀵硅薄
+        Process process = bpmnModel.getProcessById(processDefinition.getKey());
+        if (process == null) {
+            throw new RuntimeException("Process not found for processDefinitionId: " + processDefId);
+        }
+
+        // 閬嶅巻娴佺▼鍏冪礌锛屾壘鍒板搴旂殑浠诲姟鑺傜偣
+        Collection<FlowElement> flowElements = process.getFlowElements();
+        UserTask currentElement = null;
+        for (FlowElement flowElement : flowElements) {
+            if (flowElement instanceof UserTask && flowElement.getId().equals(currentNodeDefId)) {
+                currentElement = (UserTask) flowElement;
+                break;
+            }
+        }
+        if (Objects.isNull(currentElement)) {
+            throw new RuntimeException("鏈壘鍒拌浠诲姟鐨勬祦绋嬪畾涔夎妭鐐�");
+        }
+
+        // 鑾峰彇褰撳墠鑺傜偣鐨勮緭鍏�
+        List<FormDetailVO> defKeys = new ArrayList<>(2);
+        this.beforeNodeInfo(currentElement, defKeys);
+
+        return defKeys.stream().map(FormDetailVO::getBeforeNodeDefId).collect(Collectors.toList());
+    }
+
+
+    /**
+     * 妫�鏌ヤ换鍔¤妭鐐规槸鍚﹂厤缃簡锛氶渶瑕佸鏍�  鐨勬墿灞曞睘鎬�
+     *
+     * @param extensionElements 鎵╁睍鍒楄〃
+     * @return
+     */
+    public Boolean checkTaskNeedAuditing(List<ExtensionElement> extensionElements) {
+        if (CollectionUtils.isEmpty(extensionElements)) {
+            return Boolean.FALSE;
+        }
+        for (ExtensionElement extensionElement : extensionElements) {
+            if (CollectionUtils.isEmpty(extensionElement.getAttributes())) { // 濡傛灉鏈韩娌℃湁灞炴�э紝鍒欓�掑綊child
+                return checkTaskNeedAuditing(extensionElement.getChildElements().get("property"));
+            } else {
+                // 鍚﹀垯鍏堟煡鏈韩鐨勫睘鎬ф湁涓嶆湁锛氶渶瑕佸鏍� 鐨勫睘鎬э紝娌℃湁涔熸槸閫掑綊child
+                if (extensionElement.getAttributes().get("name").stream().anyMatch(attribute -> ProcessConstants.EXTENSION_PROPERTY_NEED_AUDITING_TEXT.equals(attribute.getValue()))
+                    && extensionElement.getAttributes().get("value").stream().anyMatch(attribute -> ProcessConstants.EXTENSION_PROPERTY_NEED_AUDITING_VALUE.equals(attribute.getValue()))
+                ) {
+                    return Boolean.TRUE;
+                } else {
+                    return checkTaskNeedAuditing(extensionElement.getChildElements().get("property"));
+                }
+            }
+        }
+        return Boolean.FALSE;
     }
 
 }

--
Gitblit v1.8.0