From 1b9936ba920d65df09ab8dba79c6252568ee26e4 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期三, 26 三月 2025 12:16:02 +0800
Subject: [PATCH] 任务统计bug

---
 flowable/src/main/java/com/ycl/service/common/TaskCommonService.java |   91 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 79 insertions(+), 12 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 e5abf8c..a789590 100644
--- a/flowable/src/main/java/com/ycl/service/common/TaskCommonService.java
+++ b/flowable/src/main/java/com/ycl/service/common/TaskCommonService.java
@@ -2,13 +2,19 @@
 
 import com.alibaba.fastjson2.JSONObject;
 import com.ycl.common.constant.ProcessConstants;
+import com.ycl.common.core.domain.entity.SysDictData;
 import com.ycl.common.core.domain.entity.SysUser;
 import com.ycl.common.enums.FlowComment;
 import com.ycl.common.enums.business.TaskStatusEnum;
+import com.ycl.common.utils.SecurityUtils;
 import com.ycl.domain.entity.SysForm;
 import com.ycl.domain.vo.FormDetailVO;
 import com.ycl.flow.FindNextNodeUtil;
 import com.ycl.service.ISysFormService;
+import com.ycl.system.service.ISysDeptService;
+import com.ycl.system.service.ISysDictDataService;
+import com.ycl.system.service.ISysDictTypeService;
+import com.ycl.system.service.ISysUserService;
 import lombok.RequiredArgsConstructor;
 import org.flowable.bpmn.model.*;
 import org.flowable.bpmn.model.Process;
@@ -18,6 +24,8 @@
 import org.flowable.engine.TaskService;
 import org.flowable.engine.history.HistoricProcessInstance;
 import org.flowable.engine.repository.ProcessDefinition;
+import org.flowable.identitylink.api.IdentityLink;
+import org.flowable.identitylink.api.IdentityLinkType;
 import org.flowable.task.api.Task;
 import org.flowable.task.api.history.HistoricTaskInstance;
 import org.springframework.stereotype.Service;
@@ -39,6 +47,9 @@
     private final RepositoryService repositoryService;
     private final TaskService taskService;
     private final HistoryService historyService;
+    private final ISysUserService sysUserService;
+    private final ISysDeptService deptService;
+    private final ISysDictTypeService sysDictDService;
 
     /**
      * 閫氳繃褰撳墠鑺傜偣瀹氫箟key锛岃幏鍙栧叾涓婁竴涓妭鐐圭殑淇℃伅锛屽鏋滃墠闈㈡槸骞惰鐨勪細杩斿洖澶氫釜(鍖呭惈褰撳墠鑺傜偣)
@@ -80,7 +91,7 @@
             throw new RuntimeException("鏈壘鍒拌浠诲姟鐨勬祦绋嬪畾涔夎妭鐐�");
         }
 
-        // 鑾峰彇褰撳墠鑺傜偣鐨勮緭鍏�
+        // 鑾峰彇褰撳墠鑺傜偣鐨勪俊鎭�
         List<FormDetailVO> defKeys = new ArrayList<>(2);
         FormDetailVO formDetailVO = new FormDetailVO();
         formDetailVO.setCurrent(Boolean.TRUE);
@@ -98,6 +109,10 @@
                 formDetailVO.setFormJsonObj(data);
             }
         }
+        formDetailVO.setCanJump(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_JUMP_TEXT));
+        formDetailVO.setCanWait(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_WAIT_TEXT));
+        formDetailVO.setCanHangup(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_HANGUP_TEXT));
+        formDetailVO.setUserTask(currentElement);
         defKeys.add(formDetailVO);
         this.beforeNodeInfo(currentElement, defKeys);
 
@@ -165,7 +180,11 @@
                         FormDetailVO formDetailVO = new FormDetailVO();
                         formDetailVO.setBeforeNodeDefId(incomingFlow.getSourceFlowElement().getId());
                         formDetailVO.setBeforeNodeName(incomingFlow.getSourceFlowElement().getName());
+                        formDetailVO.setCanJump(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_JUMP_TEXT));
+                        formDetailVO.setCanWait(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_WAIT_TEXT));
+                        formDetailVO.setUserTask((UserTask) incomingFlow.getSourceFlowElement());
                         defKeys.add(formDetailVO);
+                        continue;
                     } else {
                         beforeNodeInfo(incomingFlow.getSourceFlowElement(), defKeys);
                     }
@@ -179,7 +198,11 @@
                         FormDetailVO formDetailVO = new FormDetailVO();
                         formDetailVO.setBeforeNodeDefId(incomingFlow.getSourceFlowElement().getId());
                         formDetailVO.setBeforeNodeName(incomingFlow.getSourceFlowElement().getName());
+                        formDetailVO.setCanJump(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_JUMP_TEXT));
+                        formDetailVO.setCanWait(this.checkHasExeProperty(currentElement.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_CAN_WAIT_TEXT));
+                        formDetailVO.setUserTask((UserTask) incomingFlow.getSourceFlowElement());
                         defKeys.add(formDetailVO);
+                        continue;
                     } else {
                         beforeNodeInfo(incomingFlow.getSourceFlowElement(), defKeys);
                     }
@@ -190,7 +213,7 @@
 
 
     /**
-     * 鑾峰彇褰撳墠鑺傜偣鐨勪笂涓�鑺傜偣id锛屼笉鍙嶆倲褰撳墠鑺傜偣淇℃伅锛屽鏋滃墠闈㈡槸骞惰锛岄偅涔堜細杩斿洖澶氫釜
+     * 鑾峰彇褰撳墠鑺傜偣鐨勪笂涓�鑺傜偣id锛屼笉杩斿洖褰撳墠鑺傜偣淇℃伅锛屽鏋滃墠闈㈡槸骞惰锛岄偅涔堜細杩斿洖澶氫釜
      *
      * @param processDefId     娴佺▼瀹氫箟id
      * @param currentNodeDefId 褰撳墠鑺傜偣瀹氫箟id
@@ -236,30 +259,29 @@
 
 
     /**
-     * 妫�鏌ヤ换鍔¤妭鐐规槸鍚﹂厤缃簡锛氶渶瑕佸鏍�  鐨勬墿灞曞睘鎬�
+     * 妫�鏌ヤ换鍔¤妭鐐规槸鍚﹂厤缃簡鏌愪釜鐨勬墿灞曞睘鎬�
      *
      * @param extensionElements 鎵╁睍鍒楄〃
      * @return
      */
-    public Boolean checkTaskNeedAuditing(List<ExtensionElement> extensionElements) {
+    public Boolean checkHasExeProperty(List<ExtensionElement> extensionElements, String exePropertyName) {
         if (CollectionUtils.isEmpty(extensionElements)) {
             return Boolean.FALSE;
         }
-        for (ExtensionElement extensionElement : extensionElements) {
+        return extensionElements.stream().anyMatch(extensionElement -> {
             if (CollectionUtils.isEmpty(extensionElement.getAttributes())) { // 濡傛灉鏈韩娌℃湁灞炴�э紝鍒欓�掑綊child
-                return checkTaskNeedAuditing(extensionElement.getChildElements().get("property"));
+                return checkHasExeProperty(extensionElement.getChildElements().get("property"), exePropertyName);
             } 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()))
+                // 鍚﹀垯鍏堟煡鏈韩鐨勫睘鎬ф湁涓嶆湁锛屾病鏈変篃鏄�掑綊child
+                if (extensionElement.getAttributes().get("name").stream().anyMatch(attribute -> exePropertyName.equals(attribute.getValue()))
+                        && extensionElement.getAttributes().get("value").stream().anyMatch(attribute -> ProcessConstants.EXTENSION_PROPERTY_VALUE.equals(attribute.getValue()))
                 ) {
                     return Boolean.TRUE;
                 } else {
-                    return checkTaskNeedAuditing(extensionElement.getChildElements().get("property"));
+                    return checkHasExeProperty(extensionElement.getChildElements().get("property"), exePropertyName);
                 }
             }
-        }
-        return Boolean.FALSE;
+        });
     }
 
 
@@ -272,6 +294,7 @@
      * @param taskId             褰撳墠浠诲姟id
      * @param msg                瀹℃牳鎰忚
      */
+    @Deprecated
     public void reject(String rejectedTaskDefKey, String rejectTaskDefKey, String processInsId, String taskId, String msg) {
         // 椹冲洖鐨勬牳蹇僡pi锛歳untimeService.createChangeActivityStateBuilder().moveXXX 鐨刟pi锛屽彲浠ヨ缃粠褰撳墠鑺傜偣绉诲姩鍒扮洰鏍囪妭鐐�
         // 椹冲洖鐨勬牳蹇冿細闇�瑕佹壘鍒板綋鍓嶈妭鐐广�佷互鍙婅娴佽浆鍒扮殑鐩爣鑺傜偣銆傚叾涓瘮杈冮夯鐑︾殑鏄鐞嗗苟琛岀瓑姣旇緝澶嶆潅鐨勬儏鍐�
@@ -294,4 +317,48 @@
     }
 
 
+    /**
+     * 鑾峰彇褰撳墠鐢ㄦ埛鐨勭粍
+     *
+     * @return
+     */
+    public List<String> getCurrentUserGroups() {
+        List<String> roleIds;
+        if (CollectionUtils.isEmpty(SecurityUtils.getLoginUser().getUser().getRoles())) {
+            roleIds = new ArrayList<>(1);
+        } else {
+            roleIds = SecurityUtils.getLoginUser().getUser().getRoles().stream().map(role -> role.getRoleId() + "").collect(Collectors.toList());
+        }
+        if (Objects.nonNull(SecurityUtils.getLoginUser().getDeptId())) {
+            List<Long> deptIds = deptService.getChildIds(SecurityUtils.getLoginUser().getDeptId());
+            List<String> deptIdList = deptIds.stream().map(id -> "dept:" + id).collect(Collectors.toList());
+            roleIds.addAll(deptIdList);
+        }
+        return roleIds;
+    }
+
+    /**
+     * 澶勭悊娴佺▼涓殑鍙橀噺
+     *
+     * @param variables
+     * @param taskDefKey
+     * @return
+     */
+    public Map<String, Object> handleVar(Map<String, Object> variables, String taskDefKey) {
+        Map<String, Object> processVariables = new HashMap<>();
+        //鏌ュ嚭瀛楀吀涓渶瑕佹敞鍏ョ殑瀛楁淇℃伅
+        List<String> dictList = sysDictDService.selectDictDataByType("flow_variables").stream().map(SysDictData::getDictValue).collect(Collectors.toList());
+        Map<String, Object> newV = new HashMap<>(2);
+        if (!org.springframework.util.CollectionUtils.isEmpty(variables)) {
+            for (String key : variables.keySet()) {
+                newV.put(taskDefKey + "&" + key, variables.get(key));
+                //瀛楀吀閲屾湁灏辨斁鍏ユ祦绋嬪彉閲忎腑
+                if (!org.apache.commons.collections4.CollectionUtils.isEmpty(dictList) && dictList.contains(key)) {
+                    processVariables.put(key,variables.get(key));
+                }
+            }
+        }
+        return processVariables;
+    }
+
 }

--
Gitblit v1.8.0