From e85cd3fe826efe0baaa3fc09ea371467127c370c Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期二, 15 七月 2025 18:11:31 +0800
Subject: [PATCH] Merge branch 'dev'

---
 business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java |  109 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 81 insertions(+), 28 deletions(-)

diff --git a/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java b/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java
index bf9dcf8..12c67d7 100644
--- a/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java
+++ b/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java
@@ -20,6 +20,7 @@
 import com.ycl.common.enums.business.TaskStatusEnum;
 import com.ycl.common.exception.CustomException;
 import com.ycl.common.utils.SecurityUtils;
+import com.ycl.constant.ProjectConstant;
 import com.ycl.domain.dto.FlowCommentDto;
 import com.ycl.domain.dto.FlowNextDto;
 import com.ycl.domain.dto.FlowTaskDto;
@@ -73,6 +74,7 @@
 import org.flowable.task.api.history.HistoricTaskInstance;
 import org.flowable.task.api.history.HistoricTaskInstanceQuery;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -109,6 +111,9 @@
     private final ProcessLogService processLogService;
     private final ApplicationEventPublisher publisher;
     private final ProjectProcessMapper projectProcessMapper;
+
+    @Value("${targetIp}")
+    private String targetIp;
 
     /**
      * 瀹屾垚瀹℃牳浠诲姟
@@ -1445,7 +1450,6 @@
     public AjaxResult currentFlowTaskForm(String taskId) {
         // 娴佺▼鍙橀噺
         List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery()
-                .includeProcessVariables()
                 .finished()
                 .taskId(taskId)
                 .orderByHistoricTaskInstanceStartTime()
@@ -1455,7 +1459,19 @@
             return AjaxResult.error("鏈壘鍒拌浠诲姟淇℃伅");
         }
         HistoricTaskInstance historicTaskInstance = hisTaskList.get(0);
-        Map<String, Object> parameters = historicTaskInstance.getProcessVariables();
+        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().processInstanceId(historicTaskInstance.getProcessInstanceId()).singleResult();
+        Map<String, Object> parameters = new HashMap<>();
+        if (Objects.nonNull(processInstance)) {
+            parameters = processInstance.getProcessVariables();
+        } else {
+            // 濡傛灉涓虹┖锛岃〃鏄庢祦绋嬪凡缁忕粨鏉�
+            HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processInstanceId(historicTaskInstance.getProcessInstanceId()).singleResult();
+            if (Objects.isNull(historicProcessInstance)) {
+                throw new RuntimeException("娴佺▼涓嶅瓨鍦�");
+            }
+            parameters = historicProcessInstance.getProcessVariables();
+        }
+
         String processInsId = historicTaskInstance.getProcessInstanceId();
         List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters,
                 historicTaskInstance.getFormKey(),
@@ -1504,36 +1520,55 @@
     @Override
     public AjaxResult flowTaskForm(String taskId) throws Exception {
         Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
-        // 娴佺▼鍙橀噺
-        Map<String, Object> parameters = new HashMap<>();
-        List<FormDetailVO> beforeNodes = new ArrayList<>();
+        // 1. 鑾峰彇鍒板彉閲忎俊鎭紝鍥犱负浠诲姟鍙兘鏄繍琛屼腑鐨勪篃鍙兘鏄巻鍙蹭换鍔�
         String processInsId = "";
-        List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery()
-                .includeProcessVariables()
-                .finished()
-                .taskId(taskId)
-                .orderByHistoricTaskInstanceStartTime()
-                .desc()
-                .list();
-        if (CollectionUtils.isNotEmpty(hisTaskList) && Objects.nonNull(hisTaskList.get(0))) {
-            parameters = hisTaskList.get(0).getProcessVariables();
-            processInsId = hisTaskList.get(0).getProcessInstanceId();
-            beforeNodes = this.getBeforeNodeForm(parameters,
-                    hisTaskList.get(0).getFormKey(),
-                    hisTaskList.get(0).getName(),
-                    hisTaskList.get(0).getProcessDefinitionId(),
-                    hisTaskList.get(0).getTaskDefinitionKey(),
-                    Boolean.FALSE, Boolean.TRUE);
+        String processDefId = "";
+        String formKey = "";
+        String taskName = "";
+        String taskDefKey = "";
+        if (Objects.isNull(task)) {
+            List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery()
+                    .finished()
+                    .taskId(taskId)
+                    .orderByHistoricTaskInstanceStartTime()
+                    .desc()
+                    .list();
+            if (CollectionUtils.isEmpty(hisTaskList) || Objects.isNull(hisTaskList.get(0))) {
+                return AjaxResult.error("浠诲姟涓嶅瓨鍦�");
+            }
+            HistoricTaskInstance hisTask = hisTaskList.get(0);
+            processInsId = hisTask.getProcessInstanceId();
+            processDefId = hisTask.getProcessDefinitionId();
+            formKey = hisTask.getFormKey();
+            taskName = hisTask.getName();
+            taskDefKey = hisTask.getTaskDefinitionKey();
         } else {
-            parameters = taskService.getVariables(taskId);
             processInsId = task.getProcessInstanceId();
-            beforeNodes = this.getBeforeNodeForm(parameters,
-                    task.getFormKey(),
-                    task.getName(),
-                    task.getProcessDefinitionId(),
-                    task.getTaskDefinitionKey(),
-                    Boolean.FALSE, Boolean.TRUE);
+            processDefId = task.getProcessDefinitionId();
+            formKey = task.getFormKey();
+            taskName = task.getName();
+            taskDefKey = task.getTaskDefinitionKey();
         }
+        // 2. 鑾峰彇娴佺▼鍙橀噺
+        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().processInstanceId(processInsId).singleResult();
+        Map<String, Object> parameters = new HashMap<>();
+        if (Objects.nonNull(processInstance)) {
+            parameters = processInstance.getProcessVariables();
+        } else {
+            // 濡傛灉涓虹┖锛岃〃鏄庢祦绋嬪凡缁忕粨鏉�
+            HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processInstanceId(processInsId).singleResult();
+            if (Objects.isNull(historicProcessInstance)) {
+                throw new RuntimeException("娴佺▼涓嶅瓨鍦�");
+            }
+            parameters = historicProcessInstance.getProcessVariables();
+        }
+        List<FormDetailVO> beforeNodes = new ArrayList<>();
+        beforeNodes = this.getBeforeNodeForm(parameters,
+                formKey,
+                taskName,
+                processDefId,
+                taskDefKey,
+                Boolean.TRUE, Boolean.FALSE);
         // 鍒ゆ柇鍓嶇疆浠诲姟鏄笉鏄拰褰撳墠浠诲姟涓哄悓涓�涓猠xecuteId
         // 鍒ゆ柇褰撳墠浠诲姟鏄惁琚寕璧蜂腑
         String finalProcessInsId = processInsId;
@@ -1811,11 +1846,29 @@
                         for (JSONObject oldField : oldFields) {
                             JSONObject options = oldField.getJSONObject("options");
                             options.put("disabled", true);
+                            // 澶勭悊鏂囦欢涓婁紶ip闂
+                            if ("file-upload".equals(oldField.get("type"))) {
+                                options.put("uploadURL", String.format("http://%s:10076/common/upload", this.targetIp));
+                            }
                         }
                     }
                     formJson.put(ProcessConstants.WIDGET_LIST, oldFields);
                     newP.put(ProcessConstants.TASK_FORM_KEY, formJson);
                     newP.remove(formDetailVO.getBeforeNodeDefId() + "&" + ProcessConstants.TASK_FORM_KEY);
+                    // 澶勭悊宸茬粡涓婁紶鐨勬枃浠剁殑ip鍦板潃
+                    for (String s : newP.keySet()) {
+                        if (ProcessConstants.TASK_FORM_KEY.equals(s)) {
+                            continue;
+                        }
+                        if (s.startsWith("fileupload")) {
+                            List files = (List) newP.get(s);
+                            for (Object file : files) {
+                                LinkedHashMap<String, String> fileMap = (LinkedHashMap<String, String>) file;
+                                String url = fileMap.get("url");
+                                fileMap.put("url", url.replace("42.193.1.25", this.targetIp));
+                            }
+                        }
+                    }
                     formDetailVO.setFormJsonObj(newP);
                 }
                 // TODO 鏆傛椂鍙鐞嗙敤鎴蜂换鍔′笂鐨勮〃鍗�

--
Gitblit v1.8.0