ソースを参照

update 优化获取流程记录

gssong 6 ヶ月 前
コミット
845e95bd07

+ 3 - 1
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/controller/ActProcessInstanceController.java

@@ -14,12 +14,14 @@ import org.dromara.common.web.core.BaseController;
 import org.dromara.workflow.domain.bo.ProcessInstanceBo;
 import org.dromara.workflow.domain.bo.ProcessInvalidBo;
 import org.dromara.workflow.domain.bo.TaskUrgingBo;
+import org.dromara.workflow.domain.vo.ActHistoryInfoVo;
 import org.dromara.workflow.domain.vo.ProcessInstanceVo;
 import org.dromara.workflow.service.IActProcessInstanceService;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -81,7 +83,7 @@ public class ActProcessInstanceController extends BaseController {
      * @param processInstanceId 流程实例id
      */
     @GetMapping("/getHistoryRecord/{processInstanceId}")
-    public R<Map<String, Object>> getHistoryRecord(@NotBlank(message = "流程实例id不能为空") @PathVariable String processInstanceId) {
+    public R<List<ActHistoryInfoVo>> getHistoryRecord(@NotBlank(message = "流程实例id不能为空") @PathVariable String processInstanceId) {
         return R.ok(actProcessInstanceService.getHistoryRecord(processInstanceId));
     }
 

+ 2 - 1
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/IActProcessInstanceService.java

@@ -5,6 +5,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.workflow.domain.bo.ProcessInstanceBo;
 import org.dromara.workflow.domain.bo.ProcessInvalidBo;
 import org.dromara.workflow.domain.bo.TaskUrgingBo;
+import org.dromara.workflow.domain.vo.ActHistoryInfoVo;
 import org.dromara.workflow.domain.vo.ProcessInstanceVo;
 
 import java.util.List;
@@ -56,7 +57,7 @@ public interface IActProcessInstanceService {
      * @param processInstanceId 流程实例id
      * @return 结果
      */
-    Map<String, Object> getHistoryRecord(String processInstanceId);
+    List<ActHistoryInfoVo> getHistoryRecord(String processInstanceId);
 
     /**
      * 作废流程实例,不会删除历史记录(删除运行中的实例)

+ 8 - 43
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessInstanceServiceImpl.java

@@ -336,8 +336,7 @@ public class ActProcessInstanceServiceImpl implements IActProcessInstanceService
      * @param processInstanceId 流程实例id
      */
     @Override
-    public Map<String, Object> getHistoryRecord(String processInstanceId) {
-        Map<String, Object> map = new HashMap<>();
+    public List<ActHistoryInfoVo> getHistoryRecord(String processInstanceId) {
         // 查询任务办理记录
         List<HistoricTaskInstance> list = QueryUtils.hisTaskInstanceQuery(processInstanceId).orderByHistoricTaskInstanceEndTime().desc().list();
         list = StreamUtils.sorted(list, Comparator.comparing(HistoricTaskInstance::getEndTime, Comparator.nullsFirst(Date::compareTo)).reversed());
@@ -378,16 +377,7 @@ public class ActProcessInstanceServiceImpl implements IActProcessInstanceService
             }
             actHistoryInfoVoList.add(actHistoryInfoVo);
         }
-        List<ActHistoryInfoVo> collect = new ArrayList<>();
-        // 待办理
-        List<ActHistoryInfoVo> waitingTask = StreamUtils.filter(actHistoryInfoVoList, e -> e.getEndTime() == null);
-        // 已办理
-        List<ActHistoryInfoVo> finishTask = StreamUtils.filter(actHistoryInfoVoList, e -> e.getEndTime() != null);
-        collect.addAll(waitingTask);
-        collect.addAll(finishTask);
         // 审批记录
-        map.put("historyRecordList", collect);
-        List<ActHistoryInfoVo> nodeInfoList = new ArrayList<>();
         Map<String, List<ActHistoryInfoVo>> groupByKey = StreamUtils.groupByKey(actHistoryInfoVoList, ActHistoryInfoVo::getTaskDefinitionKey);
         for (Map.Entry<String, List<ActHistoryInfoVo>> entry : groupByKey.entrySet()) {
             ActHistoryInfoVo actHistoryInfoVo = BeanUtil.toBean(entry.getValue().get(0), ActHistoryInfoVo.class);
@@ -403,39 +393,14 @@ public class ActProcessInstanceServiceImpl implements IActProcessInstanceService
                     actHistoryInfoVo.setEndTime(null);
                     actHistoryInfoVo.setRunDuration(null);
                 });
-            nodeInfoList.add(actHistoryInfoVo);
-        }
-        // 节点信息
-        map.put("nodeListInfo", nodeInfoList);
-        BpmnModel bpmnModel = repositoryService.getBpmnModel(list.get(0).getProcessDefinitionId());
-        List<GraphicInfoVo> graphicInfoVos = new ArrayList<>();
-        Collection<FlowElement> flowElements = bpmnModel.getMainProcess().getFlowElements();
-        //节点图形信息
-        buildGraphicInfo(flowElements, graphicInfoVos, bpmnModel);
-        map.put("graphicInfoVos", graphicInfoVos);
-        return map;
-    }
-
-    /**
-     * 构建节点图形信息
-     *
-     * @param flowElements 节点
-     */
-    private static void buildGraphicInfo(Collection<FlowElement> flowElements, List<GraphicInfoVo> graphicInfoVos, BpmnModel bpmnModel) {
-        for (FlowElement flowElement : flowElements) {
-            if (flowElement instanceof SubProcess) {
-                Collection<FlowElement> subFlowElements = ((SubProcess) flowElement).getFlowElements();
-                buildGraphicInfo(subFlowElements, graphicInfoVos, bpmnModel);
-            } else {
-                if (flowElement instanceof UserTask) {
-                    GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowElement.getId());
-                    GraphicInfoVo graphicInfoVo = BeanUtil.toBean(graphicInfo, GraphicInfoVo.class);
-                    graphicInfoVo.setNodeId(flowElement.getId());
-                    graphicInfoVo.setNodeName(flowElement.getName());
-                    graphicInfoVos.add(graphicInfoVo);
-                }
-            }
         }
+        List<ActHistoryInfoVo> recordList = new ArrayList<>();
+        // 待办理
+        recordList.addAll(StreamUtils.filter(actHistoryInfoVoList, e -> e.getEndTime() == null));
+        // 已办理
+        recordList.addAll(StreamUtils.filter(actHistoryInfoVoList, e -> e.getEndTime() != null));
+
+        return recordList;
     }
 
     /**