From c9e9cd3df7f76aa164e83280680945bca5250451 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期日, 02 三月 2025 17:20:46 +0800
Subject: [PATCH] 流程详情、办理时展示任务的特殊操作日志

---
 flowable/src/main/java/com/ycl/domain/vo/FormDetailVO.java                 |    2 
 business/src/main/resources/mapper/HiddenAdminMapper.xml                   |    3 
 business/src/main/java/com/ycl/event/event/TaskLogEvent.java               |    9 ++
 business/src/main/java/com/ycl/event/listener/ProcessLogEventListener.java |    1 
 business/src/main/java/com/ycl/service/impl/ProjectProcessServiceImpl.java |   55 ++++++++++++++---
 business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java       |   65 ++++++++++++++++++++-
 flowable/src/main/java/com/ycl/domain/vo/DoFormDetailVO.java               |   26 ++++++++
 flowable/src/main/java/com/ycl/domain/entity/ProcessLog.java               |    4 +
 8 files changed, 146 insertions(+), 19 deletions(-)

diff --git a/business/src/main/java/com/ycl/event/event/TaskLogEvent.java b/business/src/main/java/com/ycl/event/event/TaskLogEvent.java
index 0a72952..85f8581 100644
--- a/business/src/main/java/com/ycl/event/event/TaskLogEvent.java
+++ b/business/src/main/java/com/ycl/event/event/TaskLogEvent.java
@@ -37,6 +37,12 @@
      * 浠诲姟id
      */
     private String taskId;
+
+    /**
+     * 浠诲姟key
+     */
+    private String taskDefKey;
+
     /**
      * 浠诲姟鍚�
      */
@@ -62,7 +68,7 @@
      * @param taskId 浠诲姟id
      * @param otherData 鍏跺畠鏁版嵁
      */
-    public TaskLogEvent(Object source,Long id,Long userId, Long projectId, String processInsId, String taskId, String taskName,ProcessLogEventTypeEnum eventType, Object otherData) {
+    public TaskLogEvent(Object source,Long id,Long userId, Long projectId, String processInsId, String taskId, String taskDefKey, String taskName,ProcessLogEventTypeEnum eventType, Object otherData) {
         super(source);
         this.id = id;
         this.userId = userId;
@@ -70,6 +76,7 @@
         this.processInsId = processInsId;
         this.eventType = eventType;
         this.taskId = taskId;
+        this.taskDefKey = taskDefKey;
         this.taskName = taskName;
         this.otherData = otherData;
     }
diff --git a/business/src/main/java/com/ycl/event/listener/ProcessLogEventListener.java b/business/src/main/java/com/ycl/event/listener/ProcessLogEventListener.java
index c044cd8..bc228bd 100644
--- a/business/src/main/java/com/ycl/event/listener/ProcessLogEventListener.java
+++ b/business/src/main/java/com/ycl/event/listener/ProcessLogEventListener.java
@@ -34,6 +34,7 @@
         log.setProcessInsId(event.getProcessInsId());
         log.setProjectId(event.getProjectId());
         log.setTaskId(event.getTaskId());
+        log.setTaskDefKey(event.getTaskDefKey());
         log.setTaskName(event.getTaskName());
         log.setUserId(SecurityUtils.getUserId());
         if (Objects.nonNull(event.getOtherData())) {
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 ed9e5f5..8c3ec5f 100644
--- a/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java
+++ b/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java
@@ -23,9 +23,11 @@
 import com.ycl.domain.dto.FlowTaskDto;
 import com.ycl.domain.dto.FlowViewerDto;
 import com.ycl.domain.entity.ProcessCoding;
+import com.ycl.domain.entity.ProcessLog;
 import com.ycl.domain.entity.ProjectProcess;
 import com.ycl.domain.entity.SysForm;
 import com.ycl.domain.json.RejectData;
+import com.ycl.domain.vo.DoFormDetailVO;
 import com.ycl.domain.vo.FlowQueryVo;
 import com.ycl.domain.vo.FlowTaskVo;
 import com.ycl.domain.vo.FormDetailVO;
@@ -68,6 +70,7 @@
 import org.flowable.task.api.TaskQuery;
 import org.flowable.task.api.history.HistoricTaskInstance;
 import org.flowable.task.api.history.HistoricTaskInstanceQuery;
+import org.springframework.beans.BeanUtils;
 import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -188,6 +191,7 @@
                 projectProcess.getProjectId(),
                 projectProcess.getProcessInsId(),
                 taskId,
+                task.getTaskDefinitionKey(),
                 task.getName(),
                 ProcessLogEventTypeEnum.FINISHED,
                 null));
@@ -329,6 +333,7 @@
                 projectProcess.getProjectId(),
                 projectProcess.getProcessInsId(),
                 flowTaskVo.getTaskId(),
+                task.getTaskDefinitionKey(),
                 task.getName(),
                 ProcessLogEventTypeEnum.REJECT,
                 new RejectData(flowTaskVo.getComment())));
@@ -1280,14 +1285,26 @@
             HistoricTaskInstance beforeTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(finalProcessInsId).finished().taskDefinitionKey(node.getBeforeNodeDefId()).singleResult();
             return Objects.nonNull(beforeTask);
         }).collect(Collectors.toList());
-        beforeNodes.forEach(node -> {
+        List<DoFormDetailVO> vos = beforeNodes.stream().map(node -> {
             if (node.getCurrent()) {
                 if (processLogService.taskIsHangup(taskId, finalProcessInsId)) {
                     node.setTaskStatus(TaskStatusEnum.HANGUP);
                 }
             }
-        });
-        return AjaxResult.success(beforeNodes);
+            // 鍒ゆ柇浠诲姟鏄惁瀛樺湪鐗规畩鎿嶄綔(濡傝烦杩囥�佽浆鍔炵瓑)锛岄渶瑕佸湪鍓嶇灞曠ず鍑烘潵
+            List<ProcessLog> logList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper())
+                    .eq(ProcessLog::getTaskDefKey, node.getBeforeNodeDefId())
+                    .eq(ProcessLog::getProcessInsId, finalProcessInsId)
+                    .orderByDesc(ProcessLog::getGmtCreate)
+                    .list();
+            DoFormDetailVO vo = new DoFormDetailVO();
+            BeanUtils.copyProperties(node, vo);
+            if (CollectionUtils.isNotEmpty(logList)) {
+                vo.setEvents(logList);
+            }
+            return vo;
+        }).collect(Collectors.toList());
+        return AjaxResult.success(vos);
     }
 
     @Override
@@ -1310,7 +1327,26 @@
                 HistoricTaskInstance beforeTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(hisTask.getProcessInstanceId()).finished().taskDefinitionKey(node.getBeforeNodeDefId()).singleResult();
                 return Objects.nonNull(beforeTask);
             }).collect(Collectors.toList());
-            return AjaxResult.success(dataList);
+            List<DoFormDetailVO> vos = dataList.stream().map(node -> {
+                if (node.getCurrent()) {
+                    if (processLogService.taskIsHangup(taskId, hisTask.getProcessInstanceId())) {
+                        node.setTaskStatus(TaskStatusEnum.HANGUP);
+                    }
+                }
+                // 鍒ゆ柇浠诲姟鏄惁瀛樺湪鐗规畩鎿嶄綔(濡傝烦杩囥�佽浆鍔炵瓑)锛岄渶瑕佸湪鍓嶇灞曠ず鍑烘潵
+                List<ProcessLog> logList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper())
+                        .eq(ProcessLog::getTaskId, hisTask.getId())
+                        .eq(ProcessLog::getProcessInsId, hisTask.getProcessInstanceId())
+                        .orderByDesc(ProcessLog::getGmtCreate)
+                        .list();
+                DoFormDetailVO vo = new DoFormDetailVO();
+                BeanUtils.copyProperties(node, vo);
+                if (CollectionUtils.isNotEmpty(logList)) {
+                    vo.setEvents(logList);
+                }
+                return vo;
+            }).collect(Collectors.toList());
+            return AjaxResult.success(vos);
         } else {
             parameters = taskService.getVariables(taskId);
             List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.TRUE);
@@ -1321,7 +1357,26 @@
                 HistoricTaskInstance beforeTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(task.getProcessInstanceId()).finished().taskDefinitionKey(node.getBeforeNodeDefId()).singleResult();
                 return Objects.nonNull(beforeTask);
             }).collect(Collectors.toList());
-            return AjaxResult.success(dataList);
+            List<DoFormDetailVO> vos = dataList.stream().map(node -> {
+                if (node.getCurrent()) {
+                    if (processLogService.taskIsHangup(taskId, task.getProcessInstanceId())) {
+                        node.setTaskStatus(TaskStatusEnum.HANGUP);
+                    }
+                }
+                // 鍒ゆ柇浠诲姟鏄惁瀛樺湪鐗规畩鎿嶄綔(濡傝烦杩囥�佽浆鍔炵瓑)锛岄渶瑕佸湪鍓嶇灞曠ず鍑烘潵
+                List<ProcessLog> logList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper())
+                        .eq(ProcessLog::getTaskId, task.getId())
+                        .eq(ProcessLog::getProcessInsId, task.getProcessInstanceId())
+                        .orderByDesc(ProcessLog::getGmtCreate)
+                        .list();
+                DoFormDetailVO vo = new DoFormDetailVO();
+                BeanUtils.copyProperties(node, vo);
+                if (CollectionUtils.isNotEmpty(logList)) {
+                    vo.setEvents(logList);
+                }
+                return vo;
+            }).collect(Collectors.toList());
+            return AjaxResult.success(vos);
         }
     }
 
diff --git a/business/src/main/java/com/ycl/service/impl/ProjectProcessServiceImpl.java b/business/src/main/java/com/ycl/service/impl/ProjectProcessServiceImpl.java
index ca1ea6f..f6cfa5b 100644
--- a/business/src/main/java/com/ycl/service/impl/ProjectProcessServiceImpl.java
+++ b/business/src/main/java/com/ycl/service/impl/ProjectProcessServiceImpl.java
@@ -647,7 +647,7 @@
         jsonData.setAfterHandlerIds(afterHandlerIds);
         jsonData.setAfterHandlerType(form.getPeopleType());
         // 鍙戝竷杞姙浜嬩欢
-        publisher.publishEvent(new TaskLogEvent(this, null, SecurityUtils.getUserId(), form.getProjectId(), form.getProcessInsId(), task.getId(), task.getName(), ProcessLogEventTypeEnum.DELEGATE, jsonData));
+        publisher.publishEvent(new TaskLogEvent(this, null, SecurityUtils.getUserId(), form.getProjectId(), form.getProcessInsId(), task.getId(), task.getTaskDefinitionKey(), task.getName(), ProcessLogEventTypeEnum.DELEGATE, jsonData));
 
         return Result.ok("杞姙鎴愬姛");
     }
@@ -658,7 +658,7 @@
         Task task = taskService.createTaskQuery().taskId(form.getTaskId()).processInstanceId(form.getProcessInsId()).singleResult();
         if (Objects.nonNull(task)) {
             // 娣诲姞璺宠繃鏃ュ織
-            publisher.publishEvent(new TaskLogEvent(this, null, SecurityUtils.getUserId(), form.getProjectId(), form.getProcessInsId(), form.getTaskId(), task.getName(), ProcessLogEventTypeEnum.JUMP, new JumpData(form.getDesc())));
+            publisher.publishEvent(new TaskLogEvent(this, null, SecurityUtils.getUserId(), form.getProjectId(), form.getProcessInsId(), task.getId(), task.getTaskDefinitionKey(), task.getName(), ProcessLogEventTypeEnum.JUMP, new JumpData(form.getDesc())));
             // 鏌ュ嚭璇ヤ换鍔$粦瀹氱殑琛ㄥ崟
 
             Map<String, Object> data = new HashMap<>(1);
@@ -677,6 +677,9 @@
     @Override
     public Result taskSupervise(TaskSuperviseForm form) {
         Task task = taskService.createTaskQuery().taskId(form.getTaskId()).singleResult();
+        if (Objects.isNull(task)) {
+            throw new RuntimeException("浠诲姟涓嶅瓨鍦�");
+        }
         SuperviseData jsonData = new SuperviseData();
         jsonData.setCreateTime(new Date());
         jsonData.setContent(form.getContent());
@@ -685,12 +688,12 @@
         jsonData.setReceiverIds(form.getReceiverIds());
         jsonData.setReceiverType(form.getReceiverType());
         jsonData.setSuperviseType(form.getSuperviseType());
-        QueryWrapper<ProcessLog> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("task_id", form.getTaskId());
-        queryWrapper.eq("event_type", ProcessLogEventTypeEnum.SUPERVISE);
-        queryWrapper.eq("process_ins_id", form.getProcessInsId());
-        //鏌ヨ鐫e姙鏃ュ織
-        ProcessLog processLog = processLogService.getOne(queryWrapper);
+
+        ProcessLog processLog = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper())
+                .eq(ProcessLog::getTaskId, form.getTaskId())
+                .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.SUPERVISE)
+                .eq(ProcessLog::getProcessInsId, form.getProcessInsId())
+                .one();
         List<SuperviseData> dataList;
         if (processLog != null) {
             String eventDataJson = processLog.getEventDataJson();
@@ -702,7 +705,16 @@
         }
         dataList.add(jsonData);
         //娣诲姞鐫e姙鏃ュ織
-        publisher.publishEvent(new TaskLogEvent(this, processLog.getId(), processLog.getUserId(), form.getProjectId(), form.getProcessInsId(), form.getTaskId(), task.getName(), ProcessLogEventTypeEnum.SUPERVISE, dataList));
+        publisher.publishEvent(new TaskLogEvent(this,
+                processLog.getId(),
+                processLog.getUserId(),
+                form.getProjectId(),
+                form.getProcessInsId(),
+                form.getTaskId(),
+                task.getTaskDefinitionKey(),
+                task.getName(),
+                ProcessLogEventTypeEnum.SUPERVISE,
+                dataList));
         return Result.ok("鎿嶄綔鎴愬姛");
     }
 
@@ -729,6 +741,7 @@
                 form.getProjectId(),
                 form.getProcessInsId(),
                 form.getTaskId(),
+                task.getTaskDefinitionKey(),
                 task.getName(),
                 ProcessLogEventTypeEnum.HANGUP,
                 new HangupData(form.getReason())
@@ -758,6 +771,7 @@
                 form.getProjectId(),
                 form.getProcessInsId(),
                 form.getTaskId(),
+                task.getTaskDefinitionKey(),
                 task.getName(),
                 ProcessLogEventTypeEnum.CANCEL_HANGUP,
                 new HangupData(form.getReason())
@@ -803,6 +817,7 @@
                 form.getProjectId(),
                 form.getProcessInsId(),
                 form.getTaskId(),
+                task.getTaskDefinitionKey(),
                 task.getName(),
                 ProcessLogEventTypeEnum.TEAM_WORK,
                 new TeamWorkData(form.getHandlerType(), form.getHandlerIds(), TeamWorkStatusEnum.NOT_FINISHED)
@@ -876,7 +891,7 @@
         ProcessInstance process = runtimeService.createProcessInstanceQuery().processInstanceId(processInsId).singleResult();
         if (Objects.isNull(process)) {
             // 濡傛灉杩愯鏃舵壘涓嶅埌璇存槑鏄凡瀹屾垚鐨勬祦绋嬶紝鐩存帴鏌ュ巻鍙蹭换鍔�
-            List<CustomerTaskVO> vos = this.getFinishedProcessTaskInfo(userTasks, processInsId, processDefinitionId);
+            List<CustomerTaskVO> vos = this.getFinishedProcessTaskInfo(userTasks, projectId, processInsId, processDefinitionId);
             result.data(vos);
             return vos;
         }
@@ -908,6 +923,7 @@
             vo.setPromoterUnitName(promoterUnitNames);
 
             this.setCandidateInfo(userTask, vo, projectId, processInsId);
+
             if (Objects.isNull(task)) {
                 // 濡傛灉浠诲姟鍦ㄨ繍琛屾椂娌℃壘鍒帮紝閭d箞鍙兘涓烘湭寮�濮嬫垨鑰呭凡瀹屾垚锛岄渶瑕佷粠鍘嗗彶浠诲姟涓啀鎵句竴涓�
                 List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery()
@@ -1006,7 +1022,7 @@
      * @param processDefId 娴佺▼瀹氫箟id
      * @return
      */
-    private List<CustomerTaskVO> getFinishedProcessTaskInfo(List<UserTask> userTasks, String processInsId, String processDefId) {
+    private List<CustomerTaskVO> getFinishedProcessTaskInfo(List<UserTask> userTasks, Long projectId, String processInsId, String processDefId) {
         HistoricProcessInstance hisProcess = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInsId).singleResult();
         if (Objects.isNull(hisProcess)) {
             return new ArrayList<>();
@@ -1019,6 +1035,23 @@
             vo.setTaskName(userTask.getName());
             vo.setProcessName(hisProcess.getProcessDefinitionName());
 
+            // 涓�涓换鍔″彲鑳芥湁澶氫釜鍊欓�変汉/缁勶紝鎵�浠ラ渶瑕佷娇鐢╨ist
+            List<Long> handlerIds = new ArrayList<>(2);
+            List<String> handlerNames = new ArrayList<>(2);
+            List<Long> handlerUnitIds = new ArrayList<>(2);
+            List<String> handlerUnitNames = new ArrayList<>(2);
+            List<String> promoterNames = new ArrayList<>(2);
+            List<String> promoterUnitNames = new ArrayList<>(2);
+            vo.setHandlerId(handlerIds);
+            vo.setHandlerName(handlerNames);
+            vo.setHandlerUnitId(handlerUnitIds);
+            vo.setHandlerUnitName(handlerUnitNames);
+            vo.setPromoterName(promoterNames);
+            vo.setPromoterUnitName(promoterUnitNames);
+
+
+            this.setCandidateInfo(userTask, vo, projectId, processInsId);
+
             // 鏌ュ涓槸鍥犱负椹冲洖鍚庝細鏌ュ嚭涓ゆ潯鍙婁互涓婏紝鍙栨渶鏂颁竴鏉�
             List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery()
                     .processInstanceId(hisProcess.getId())
diff --git a/business/src/main/resources/mapper/HiddenAdminMapper.xml b/business/src/main/resources/mapper/HiddenAdminMapper.xml
index 0dfd432..dd3d0c7 100644
--- a/business/src/main/resources/mapper/HiddenAdminMapper.xml
+++ b/business/src/main/resources/mapper/HiddenAdminMapper.xml
@@ -46,6 +46,8 @@
         WHERE
             THA.deleted = 0
     </select>
+
+
     <update id="updateList">
         <foreach collection="list" item="item" index="index" separator=";">
             UPDATE t_hidden_admin THA
@@ -60,6 +62,5 @@
             </set>
             where THA.id = #{item.id}
         </foreach>
-
     </update>
 </mapper>
diff --git a/flowable/src/main/java/com/ycl/domain/entity/ProcessLog.java b/flowable/src/main/java/com/ycl/domain/entity/ProcessLog.java
index bf684aa..e1bd568 100644
--- a/flowable/src/main/java/com/ycl/domain/entity/ProcessLog.java
+++ b/flowable/src/main/java/com/ycl/domain/entity/ProcessLog.java
@@ -22,6 +22,10 @@
     /** 浠诲姟id */
     private String taskId;
 
+    @TableField("task_def_key")
+    /** 浠诲姟key */
+    private String taskDefKey;
+
     @TableField("task_name")
     /** 浠诲姟鍚� */
     private String taskName;
diff --git a/flowable/src/main/java/com/ycl/domain/vo/DoFormDetailVO.java b/flowable/src/main/java/com/ycl/domain/vo/DoFormDetailVO.java
new file mode 100644
index 0000000..6059d0d
--- /dev/null
+++ b/flowable/src/main/java/com/ycl/domain/vo/DoFormDetailVO.java
@@ -0,0 +1,26 @@
+package com.ycl.domain.vo;
+
+import com.ycl.common.enums.business.TaskStatusEnum;
+import com.ycl.domain.entity.ProcessLog;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.flowable.bpmn.model.UserTask;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 澶勭悊涓嬩竴涓换鍔℃椂锛屽洖鏄惧墠缃换鍔$殑琛ㄥ崟(鍖呭惈鏈妭鐐圭殑琛ㄥ崟)
+ *
+ * @author锛歺p
+ * @date锛�2024/12/5 0:35
+ */
+@Data
+public class DoFormDetailVO extends FormDetailVO {
+
+    @ApiModelProperty("浠诲姟浜嬩欢")
+    private List<ProcessLog> events = new ArrayList<>();
+
+
+}
diff --git a/flowable/src/main/java/com/ycl/domain/vo/FormDetailVO.java b/flowable/src/main/java/com/ycl/domain/vo/FormDetailVO.java
index f83c194..589c5fc 100644
--- a/flowable/src/main/java/com/ycl/domain/vo/FormDetailVO.java
+++ b/flowable/src/main/java/com/ycl/domain/vo/FormDetailVO.java
@@ -47,7 +47,7 @@
     private TaskStatusEnum taskStatus;
 
     /**
-     * 鍓嶇疆鑺傜偣瀹氫箟id
+     * 鍓嶇疆鑺傜偣瀹氫箟id锛屽嵆浠诲姟key
      *
      */
     private String beforeNodeDefId;

--
Gitblit v1.8.0