From a0e8d1bbff7a02f538be76e852aa233324bd8810 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期五, 03 一月 2025 13:31:51 +0800
Subject: [PATCH] 赋码

---
 flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java |  233 +++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 189 insertions(+), 44 deletions(-)

diff --git a/flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java b/flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java
index d2d5a45..26a400d 100644
--- a/flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java
+++ b/flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java
@@ -4,9 +4,11 @@
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.alibaba.fastjson2.TypeReference;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ycl.common.constant.ProcessConstants;
 import com.ycl.common.core.domain.AjaxResult;
+import com.ycl.common.core.domain.entity.SysDept;
 import com.ycl.common.core.domain.entity.SysRole;
 import com.ycl.common.core.domain.entity.SysUser;
 import com.ycl.common.enums.FlowComment;
@@ -16,16 +18,21 @@
 import com.ycl.domain.dto.FlowNextDto;
 import com.ycl.domain.dto.FlowTaskDto;
 import com.ycl.domain.dto.FlowViewerDto;
+import com.ycl.domain.entity.ProcessCoding;
 import com.ycl.domain.entity.SysForm;
 import com.ycl.domain.vo.FlowQueryVo;
 import com.ycl.domain.vo.FlowTaskVo;
+import com.ycl.domain.vo.FormDetailVO;
 import com.ycl.factory.FlowServiceFactory;
 import com.ycl.flow.CustomProcessDiagramGenerator;
 import com.ycl.flow.FindNextNodeUtil;
 import com.ycl.flow.FlowableUtils;
+import com.ycl.mapper.ProcessCodingMapper;
 import com.ycl.service.IFlowTaskService;
 import com.ycl.service.ISysDeployFormService;
 import com.ycl.service.ISysFormService;
+import com.ycl.service.common.TaskCommonService;
+import com.ycl.system.service.ISysDeptService;
 import com.ycl.system.service.ISysRoleService;
 import com.ycl.system.service.ISysUserService;
 import lombok.RequiredArgsConstructor;
@@ -67,6 +74,9 @@
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
+import static com.ycl.common.constant.ProcessOverTimeConstants.RED;
+import static com.ycl.common.constant.ProcessOverTimeConstants.YELLOW;
+
 /**
  * @author Tony
  * @date 2021-04-03
@@ -78,8 +88,11 @@
 
     private final ISysUserService sysUserService;
     private final ISysRoleService sysRoleService;
+    private final ISysDeptService sysDeptService;
     private final ISysDeployFormService sysInstanceFormService;
     private final ISysFormService sysFormService;
+    private final TaskCommonService taskCommonService;
+    private final ProcessCodingMapper processCodingMapper;
 
     /**
      * 瀹屾垚瀹℃牳浠诲姟
@@ -108,8 +121,8 @@
     /**
      * 瀹屾垚琛ㄥ崟鎻愪氦浠诲姟/鏅�氫换鍔�
      *
-     * @param taskId  浠诲姟id
-     * @param variables  琛ㄥ崟鏁版嵁
+     * @param taskId    浠诲姟id
+     * @param variables 琛ㄥ崟鏁版嵁
      * @return
      */
     @Override
@@ -119,10 +132,21 @@
         if (Objects.isNull(task)) {
             return AjaxResult.error("浠诲姟涓嶅瓨鍦�");
         }
+        Map<String, Object> newV = new HashMap<>(2);
+        if (!org.springframework.util.CollectionUtils.isEmpty(variables)) {
+            for (String key : variables.keySet()) {
+                newV.put(task.getTaskDefinitionKey() + "&" + key, variables.get(key));
+//                if (ProcessConstants.TASK_FORM_KEY.equals(key)) {
+//                    newV.put(task.getTaskDefinitionKey() + "_" + ProcessConstants.TASK_FORM_KEY, variables.get(key));
+//                } else if (ProcessConstants.WIDGET_LIST.equals(key)){
+//                    newV.put(task.getTaskDefinitionKey() + "_" + ProcessConstants.WIDGET_LIST, variables.get(key));
+//                }
+            }
+        }
         // 鍏堣褰撳墠鐢ㄦ埛璁ら杩欎釜浠诲姟
         taskService.claim(taskId, SecurityUtils.getUserId() + "");
         taskService.addComment(taskId, task.getProcessInstanceId(), FlowComment.SUBMIT.getType(), "瀹屾垚鎻愪氦");
-        taskService.complete(taskId, variables);
+        taskService.complete(taskId, newV);
         return AjaxResult.success("鎻愪氦鎴愬姛");
     }
 
@@ -293,7 +317,6 @@
         if (!isSequential) {
             throw new CustomException("褰撳墠鑺傜偣鐩稿浜庣洰鏍囪妭鐐癸紝涓嶅睘浜庝覆琛屽叧绯伙紝鏃犳硶鍥為��");
         }
-
 
         // 鑾峰彇鎵�鏈夋甯歌繘琛岀殑浠诲姟鑺傜偣 Key锛岃繖浜涗换鍔′笉鑳界洿鎺ヤ娇鐢紝闇�瑕佹壘鍑哄叾涓渶瑕佹挙鍥炵殑浠诲姟
         List<Task> runTaskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).list();
@@ -775,6 +798,11 @@
                     .processInstanceId(procInsId)
                     .orderByHistoricActivityInstanceStartTime()
                     .desc().list();
+            Date now = new Date();
+            //鎵╁睍 鑾峰彇杩欎釜娴佺▼瀹炰緥鐨勭洃鎺т俊鎭� key:TaskId value:瀹炰綋绫�
+            Map<String, ProcessCoding> processCodingMap = processCodingMapper.selectList(new QueryWrapper<ProcessCoding>().eq("process_ins_id", procInsId))
+                    .stream()
+                    .collect(Collectors.toMap(ProcessCoding::getTaskId, Function.identity()));
             List<FlowTaskDto> hisFlowList = new ArrayList<>();
             for (HistoricActivityInstance histIns : list) {
                 // 灞曠ず寮�濮嬭妭鐐�
@@ -817,8 +845,14 @@
                                 stringBuilder.append(sysUser.getNickName()).append(",");
                             }
                             if (StringUtils.isNotBlank(identityLink.getGroupId())) {
-                                SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId()));
-                                stringBuilder.append(sysRole.getRoleName()).append(",");
+                                if (identityLink.getGroupId().contains("dept")) {
+                                    SysDept sysDept = sysDeptService.selectDeptById(Long.parseLong(identityLink.getGroupId().split(":")[1]));
+                                    stringBuilder.append(sysDept.getDeptName()).append(",");
+                                } else {
+                                    SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId()));
+                                    stringBuilder.append(sysRole.getRoleName()).append(",");
+                                }
+
                             }
                         }
                     }
@@ -827,6 +861,21 @@
                     }
 
                     flowTask.setDuration(histIns.getDurationInMillis() == null || histIns.getDurationInMillis() == 0 ? null : getDate(histIns.getDurationInMillis()));
+                    //鎵╁睍 鍒ゆ柇鏄惁瓒呮椂
+                    ProcessCoding processCoding = processCodingMap.get(histIns.getTaskId());
+                    if(processCoding!=null){
+                        //濡傛灉浠诲姟鏄唬鍔炶妭鐐�
+                        if (flowTask.getDuration() == null) {
+                            if(RED.equals(processCoding.getStatus()) || YELLOW.equals(processCoding.getStatus())){
+                                flowTask.setOvertime(processCoding.getStatus());
+                            }
+                        }else {
+                            //濡傛灉浠诲姟鑺傜偣灞炰簬鍘嗗彶鑺傜偣
+                            if(RED.equals(processCoding.getStatus())){
+                                flowTask.setOvertime(processCoding.getStatus());
+                            };
+                        }
+                    }
                     // 鑾峰彇鎰忚璇勮鍐呭
                     List<Comment> commentList = taskService.getProcessInstanceComments(histIns.getProcessInstanceId());
                     commentList.forEach(comment -> {
@@ -839,14 +888,14 @@
             }
             map.put("flowList", hisFlowList);
         }
-        // 绗竴娆$敵璇疯幏鍙栧垵濮嬪寲琛ㄥ崟
-        if (StringUtils.isNotBlank(deployId)) {
-            SysForm sysForm = sysInstanceFormService.selectSysDeployFormByDeployId(deployId);
-            if (Objects.isNull(sysForm)) {
-                return AjaxResult.error("璇峰厛閰嶇疆娴佺▼琛ㄥ崟");
-            }
-            map.put("formData", JSONObject.parseObject(sysForm.getFormContent()));
-        }
+//        // 绗竴娆$敵璇疯幏鍙栧垵濮嬪寲琛ㄥ崟
+//        if (StringUtils.isNotBlank(deployId)) {
+//            SysForm sysForm = sysInstanceFormService.selectSysDeployFormByDeployId(deployId);
+//            if (Objects.isNull(sysForm)) {
+//                return AjaxResult.error("璇峰厛閰嶇疆娴佺▼琛ㄥ崟");
+//            }
+//            map.put("formData", JSONObject.parseObject(sysForm.getFormContent()));
+//        }
         return AjaxResult.success(map);
     }
 
@@ -1072,6 +1121,7 @@
     @Override
     public AjaxResult flowXmlAndNode(String procInsId, String deployId) {
         try {
+
             List<FlowViewerDto> flowViewerList = new ArrayList<>();
             // 鑾峰彇宸茬粡瀹屾垚鐨勮妭鐐�
             List<HistoricActivityInstance> listFinished = historyService.createHistoricActivityInstanceQuery()
@@ -1079,11 +1129,21 @@
                     .finished()
                     .list();
 
+            //鑾峰彇杩欎釜娴佺▼瀹炰緥鐨勭洃鎺т俊鎭� key:TaskId value:瀹炰綋绫�
+            Map<String, ProcessCoding> processCodingMap = processCodingMapper.selectList(new QueryWrapper<ProcessCoding>().eq("process_ins_id", procInsId))
+                    .stream()
+                    .collect(Collectors.toMap(ProcessCoding::getTaskId, Function.identity()));
             // 淇濆瓨宸茬粡瀹屾垚鐨勬祦绋嬭妭鐐圭紪鍙�
             listFinished.forEach(s -> {
                 FlowViewerDto flowViewerDto = new FlowViewerDto();
                 flowViewerDto.setKey(s.getActivityId());
                 flowViewerDto.setCompleted(true);
+                //鎵╁睍鍐呭 涓嶅弽overtime鍓嶇榛樿鏄豢鑹�
+                ProcessCoding processCoding = processCodingMap.get(s.getTaskId());
+                //濡傛灉鏈夌洃鎺ф暟鎹�, 鍘嗗彶鑺傜偣鍙垽鏂孩鐮�
+                if (processCoding != null && RED.equals(processCoding.getStatus())) {
+                    flowViewerDto.setOvertime(processCoding.getStatus());
+                }
                 // 閫�鍥炶妭鐐逛笉杩涜灞曠ず
                 if (StringUtils.isBlank(s.getDeleteReason())) {
                     flowViewerList.add(flowViewerDto);
@@ -1095,7 +1155,6 @@
                     .processInstanceId(procInsId)
                     .unfinished()
                     .list();
-
             // 淇濆瓨闇�瑕佷唬鍔炵殑鑺傜偣缂栧彿
             listUnFinished.forEach(s -> {
                 // 鍒犻櫎宸查��鍥炶妭鐐�
@@ -1103,6 +1162,12 @@
                 FlowViewerDto flowViewerDto = new FlowViewerDto();
                 flowViewerDto.setKey(s.getActivityId());
                 flowViewerDto.setCompleted(false);
+                // 鎵╁睍鍐呭 浠e姙鐨勯�氳繃褰撳墠鏃堕棿浣滀负endTime
+                ProcessCoding processCoding = processCodingMap.get(s.getTaskId());
+                //濡傛灉鏈夌洃鎺ф暟鎹� 涓嶅弽鐨勮瘽鍓嶇榛樿鏄繘琛屼腑(钃濊壊)
+                if (processCoding != null && (RED.equals(processCoding.getStatus()) || YELLOW.equals(processCoding.getStatus()))) {
+                    flowViewerDto.setOvertime(processCoding.getStatus());
+                }
                 flowViewerList.add(flowViewerDto);
             });
             Map<String, Object> result = new HashMap();
@@ -1114,6 +1179,7 @@
             result.put("xmlData", xmlData);
             return AjaxResult.success(result);
         } catch (Exception e) {
+            e.printStackTrace();
             return AjaxResult.error("楂樹寒鍘嗗彶浠诲姟澶辫触");
         }
     }
@@ -1135,41 +1201,120 @@
         } else {
             parameters = taskService.getVariables(taskId);
         }
+        List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.FALSE);
+        return AjaxResult.success(beforeNodes);
+    }
 
-        JSONObject oldVariables = JSONObject.parseObject(JSON.toJSONString(parameters.get("formJson")));
-        if (Objects.isNull(oldVariables)) {
-            // 濡傛灉鏄┖鐨勶紝鐩存帴浣跨敤涓昏〃鍗曪紝鍥犱负杩欎唬琛ㄦ槸娴佺▼涓殑绗竴涓彁浜よ〃鍗曠殑浠诲姟
-            String deploymentId = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult().getDeploymentId();
-            return this.flowFormData(deploymentId);
+    @Override
+    public AjaxResult detail(String taskId) {
+        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
+        // 娴佺▼鍙橀噺
+        Map<String, Object> parameters = new HashMap<>();
+        if (Objects.isNull(task)) {
+            // 濡傛灉涓虹┖锛屽彲鑳芥槸浠诲姟宸茬粡缁撴潫
+            HistoricTaskInstance hisTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).includeProcessVariables().singleResult();
+            if (Objects.isNull(hisTask)) {
+                throw new RuntimeException("璇ヤ换鍔′笉瀛樺湪");
+            }
+            parameters = hisTask.getProcessVariables();
+            List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, hisTask.getFormKey(), hisTask.getName(), hisTask.getProcessDefinitionId(), hisTask.getTaskDefinitionKey(), Boolean.TRUE);
+            return AjaxResult.success(beforeNodes);
+        } else {
+            parameters = taskService.getVariables(taskId);
+            List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.TRUE);
+            return AjaxResult.success(beforeNodes);
         }
-        List<JSONObject> oldFields = JSON.parseObject(JSON.toJSONString(oldVariables.get("widgetList")), new TypeReference<List<JSONObject>>() {
-        });
-        // 璁剧疆宸插~鍐欑殑琛ㄥ崟涓虹鐢ㄧ姸鎬�
-        for (JSONObject oldField : oldFields) {
-            JSONObject options = oldField.getJSONObject("options");
-            options.put("disabled", true);
+    }
+
+    /**
+     * 鑾峰彇褰撳墠鑺傜偣鍜屼笂涓�鑺傜偣鐨勮〃鍗曞唴瀹�
+     *
+     * @param parameters    鏍规嵁浠诲姟鏌ユ壘鍑烘潵鐨勫弬鏁�
+     * @param formKey       task鑷韩鍏宠仈鐨勮〃鍗昳d
+     * @param taskName      task鑷韩鐨勪换鍔″悕
+     * @param processDefId  娴佺▼瀹氫箟id
+     * @param processDefKey 娴佺▼瀹炰緥id
+     * @return
+     */
+    private List<FormDetailVO> getBeforeNodeForm(Map<String, Object> parameters, String formKey, String taskName, String processDefId, String processDefKey, Boolean currentNeedData) {
+        if (!parameters.keySet().stream().anyMatch(key -> key.contains(ProcessConstants.TASK_FORM_KEY))) {
+            // 濡傛灉鏄┖鐨勶紝浣跨敤formId鍘绘煡
+            if (StringUtils.isNotBlank(formKey)) {
+                SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(formKey));
+                if (Objects.isNull(sysForm)) {
+                    throw new RuntimeException("璇ユ祦绋嬬粦瀹氱殑琛ㄥ崟涓嶅瓨鍦ㄦ垨宸茶鍒犻櫎");
+                }
+                FormDetailVO formDetailVO = new FormDetailVO();
+                Map<String, Object> data = new HashMap<>(1);
+                data.put(ProcessConstants.TASK_FORM_KEY, JSONObject.parseObject(sysForm.getFormContent()));
+                formDetailVO.setFormJsonObj(data);
+                formDetailVO.setBeforeNodeName(taskName);
+                formDetailVO.setCurrent(Boolean.TRUE);
+                return Arrays.asList(formDetailVO);
+            } else {
+                return new ArrayList<>(1);
+            }
         }
-        // TODO 鏆傛椂鍙鐞嗙敤鎴蜂换鍔′笂鐨勮〃鍗�
-        if (StringUtils.isNotBlank(task.getFormKey())) {
-            SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(task.getFormKey()));
-            JSONObject data = JSONObject.parseObject(sysForm.getFormContent());
-            List<JSONObject> newFields = JSON.parseObject(JSON.toJSONString(data.get("widgetList")), new TypeReference<List<JSONObject>>() {
-            });
-            // 琛ㄥ崟鍥炴樉鏃� 鍔犲叆瀛愯〃鍗曚俊鎭埌娴佺▼鍙橀噺涓�
-            for (JSONObject newField : newFields) {
-                String key = newField.getString("id");
-                // 澶勭悊鍥剧墖涓婁紶缁勪欢鍥炴樉闂
-                if ("picture-upload".equals(newField.getString("type"))) {
-                    parameters.put(key, new ArrayList<>());
-                } else {
-                    parameters.put(key, null);
+        // 杩欓噷鍙渶瑕佹煡鑷韩浠ュ強涓婁竴涓妭鐐�(濡傛灉骞惰鐨勬湁澶氫釜)鐨勮〃鍗曟暟鎹�
+        List<FormDetailVO> beforeNodes = taskCommonService.getBeforeNodeDefInfo(processDefId, processDefKey, sysFormService, Boolean.TRUE);
+        List<String> beforeNodeDefIds = beforeNodes.stream().filter(item -> !item.getCurrent() || currentNeedData).map(FormDetailVO::getBeforeNodeDefId).collect(Collectors.toList());
+
+        // 澶勭悊姣忎釜琛ㄥ崟鐨勬暟鎹�
+        for (FormDetailVO formDetailVO : beforeNodes) {
+            if (formDetailVO.getCurrent() && !currentNeedData) {
+                continue;  // 璺宠繃褰撳墠鑺傜偣锛屽洜涓哄綋鍓嶈妭鐐瑰湪鑾峰彇鍓嶇疆鑺傜偣鏃跺凡缁忚缃繃浜�(浣嗚〃鍗曟暟鎹病鏈夌粰)
+            }
+
+            Map<String, Object> newP = new HashMap<>();
+            if (CollectionUtils.isNotEmpty(beforeNodeDefIds)) {
+                for (String key : parameters.keySet()) {
+                    // 杩囨护鎷垮埌鐩爣琛ㄥ崟鏁版嵁锛屽皢鐩爣琛ㄥ崟鏁版嵁鏀惧埌鏂癿ap涓�
+                    if (key.startsWith(formDetailVO.getBeforeNodeDefId())) {
+                        if (key.contains(ProcessConstants.TASK_FORM_KEY)) {
+                            newP.put(key, parameters.get(key));
+                        } else {
+                            newP.put(key.split("&")[1], parameters.get(key));
+                        }
+                    }
                 }
             }
-            oldFields.addAll(newFields);
+
+            Object form = newP.get(formDetailVO.getBeforeNodeDefId() + "&" + ProcessConstants.TASK_FORM_KEY);
+            if (Objects.nonNull(form)) {
+                JSONObject formJson = JSONObject.parseObject(JSON.toJSONString(form));
+                List<JSONObject> oldFields = JSON.parseObject(JSON.toJSONString(formJson.get(ProcessConstants.WIDGET_LIST)), new TypeReference<List<JSONObject>>() {
+                });
+
+                // 璁剧疆宸插~鍐欑殑琛ㄥ崟涓虹鐢ㄧ姸鎬�
+                for (JSONObject oldField : oldFields) {
+                    JSONObject options = oldField.getJSONObject("options");
+                    options.put("disabled", true);
+                }
+                // TODO 鏆傛椂鍙鐞嗙敤鎴蜂换鍔′笂鐨勮〃鍗�
+//                if (StringUtils.isNotBlank(task.getFormKey())) {
+//                    SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(task.getFormKey()));
+//                    JSONObject data = JSONObject.parseObject(sysForm.getFormContent());
+//                    List<JSONObject> newFields = JSON.parseObject(JSON.toJSONString(data.get(ProcessConstants.WIDGET_LIST)), new TypeReference<List<JSONObject>>() {
+//                    });
+//                    // 琛ㄥ崟鍥炴樉鏃� 鍔犲叆瀛愯〃鍗曚俊鎭埌娴佺▼鍙橀噺涓�
+//                    for (JSONObject newField : newFields) {
+//                        String key = newField.getString("id");
+//                        // 澶勭悊鍥剧墖涓婁紶缁勪欢鍥炴樉闂
+//                        if ("picture-upload".equals(newField.getString("type"))) {
+//                            parameters.put(key, new ArrayList<>());
+//                        } else {
+//                            parameters.put(key, null);
+//                        }
+//                    }
+//                    oldFields.addAll(newFields);
+//                }
+                formJson.put(ProcessConstants.WIDGET_LIST, oldFields);
+                newP.put(ProcessConstants.TASK_FORM_KEY, formJson);
+                newP.remove(formDetailVO.getBeforeNodeDefId() + "&" + ProcessConstants.TASK_FORM_KEY);
+                formDetailVO.setFormJsonObj(newP);
+            }
         }
-        oldVariables.put("widgetList", oldFields);
-        parameters.put("formJson", oldVariables);
-        return AjaxResult.success(parameters);
+        return beforeNodes;
     }
 
     /**

--
Gitblit v1.8.0