From 9b507f06c4a7ff9ad39d25b45bb11982bc814e5d Mon Sep 17 00:00:00 2001
From: gssong <1742057357@qq.com>
Date: 星期日, 02 六月 2024 10:19:18 +0800
Subject: [PATCH] update 增加通用接口 降低耦合

---
 ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessInstanceServiceImpl.java |  191 +++++++++++++++++------------------------------
 1 files changed, 68 insertions(+), 123 deletions(-)

diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessInstanceServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessInstanceServiceImpl.java
index 9af37f6..f7a3db8 100644
--- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessInstanceServiceImpl.java
+++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessInstanceServiceImpl.java
@@ -3,11 +3,12 @@
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.codec.Base64;
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.convert.Convert;
+import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.ObjectUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.IOUtils;
 import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.utils.StreamUtils;
 import org.dromara.common.core.utils.StringUtils;
@@ -52,7 +53,6 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import java.awt.*;
-import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
@@ -76,8 +76,8 @@
     private final IActHiProcinstService actHiProcinstService;
     private final ManagementService managementService;
     private final FlowEventStrategy flowEventStrategy;
-    private final IWfTaskBackNodeService iWfTaskBackNodeService;
-    private final IWfNodeConfigService iWfNodeConfigService;
+    private final IWfTaskBackNodeService wfTaskBackNodeService;
+    private final IWfNodeConfigService wfNodeConfigService;
 
     @Value("${flowable.activity-font-name}")
     private String activityFontName;
@@ -122,7 +122,7 @@
         }
         if (CollUtil.isNotEmpty(list)) {
             List<String> processDefinitionIds = StreamUtils.toList(list, ProcessInstanceVo::getProcessDefinitionId);
-            List<WfNodeConfigVo> wfNodeConfigVoList = iWfNodeConfigService.selectByDefIds(processDefinitionIds);
+            List<WfNodeConfigVo> wfNodeConfigVoList = wfNodeConfigService.selectByDefIds(processDefinitionIds);
             for (ProcessInstanceVo processInstanceVo : list) {
                 if (CollUtil.isNotEmpty(wfNodeConfigVoList)) {
                     wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(processInstanceVo.getProcessDefinitionId()) && FlowConstant.TRUE.equals(e.getApplyUserTask())).findFirst().ifPresent(processInstanceVo::setWfNodeConfigVo);
@@ -169,7 +169,7 @@
         }
         if (CollUtil.isNotEmpty(list)) {
             List<String> processDefinitionIds = StreamUtils.toList(list, ProcessInstanceVo::getProcessDefinitionId);
-            List<WfNodeConfigVo> wfNodeConfigVoList = iWfNodeConfigService.selectByDefIds(processDefinitionIds);
+            List<WfNodeConfigVo> wfNodeConfigVoList = wfNodeConfigService.selectByDefIds(processDefinitionIds);
             for (ProcessInstanceVo processInstanceVo : list) {
                 if (CollUtil.isNotEmpty(wfNodeConfigVoList)) {
                     wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(processInstanceVo.getProcessDefinitionId()) && FlowConstant.TRUE.equals(e.getApplyUserTask())).findFirst().ifPresent(processInstanceVo::setWfNodeConfigVo);
@@ -184,28 +184,28 @@
     }
 
     /**
-     * 閫氳繃娴佺▼瀹炰緥id鑾峰彇鍘嗗彶娴佺▼鍥�
+     * 閫氳繃涓氬姟id鑾峰彇鍘嗗彶娴佺▼鍥�
      *
-     * @param processInstanceId 娴佺▼瀹炰緥id
+     * @param businessKey 涓氬姟id
      */
     @SneakyThrows
     @Override
-    public String getHistoryImage(String processInstanceId) {
+    public String getHistoryImage(String businessKey) {
         String processDefinitionId;
         // 鑾峰彇褰撳墠鐨勬祦绋嬪疄渚�
-        ProcessInstance processInstance = QueryUtils.instanceQuery(processInstanceId).singleResult();
+        ProcessInstance processInstance = QueryUtils.businessKeyQuery(businessKey).singleResult();
         // 濡傛灉娴佺▼宸茬粡缁撴潫锛屽垯寰楀埌缁撴潫鑺傜偣
         if (Objects.isNull(processInstance)) {
-            HistoricProcessInstance pi = QueryUtils.hisInstanceQuery(processInstanceId).singleResult();
+            HistoricProcessInstance pi = QueryUtils.hisInstanceQuery().processInstanceBusinessKey(businessKey).singleResult();
             processDefinitionId = pi.getProcessDefinitionId();
         } else {
             // 鏍规嵁娴佺▼瀹炰緥ID鑾峰緱褰撳墠澶勪簬娲诲姩鐘舵�佺殑ActivityId鍚堥泦
-            ProcessInstance pi = QueryUtils.instanceQuery(processInstanceId).singleResult();
+            ProcessInstance pi = QueryUtils.instanceQuery(processInstance.getProcessInstanceId()).singleResult();
             processDefinitionId = pi.getProcessDefinitionId();
         }
 
         // 鑾峰緱娲诲姩鐨勮妭鐐�
-        List<HistoricActivityInstance> highLightedFlowList = QueryUtils.hisActivityInstanceQuery(processInstanceId).orderByHistoricActivityInstanceStartTime().asc().list();
+        List<HistoricActivityInstance> highLightedFlowList = QueryUtils.hisActivityInstanceQuery(processInstance.getProcessInstanceId()).orderByHistoricActivityInstanceStartTime().asc().list();
 
         List<String> highLightedFlows = new ArrayList<>();
         List<String> highLightedNodes = new ArrayList<>();
@@ -236,19 +236,20 @@
         BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
         CustomDefaultProcessDiagramGenerator diagramGenerator = new CustomDefaultProcessDiagramGenerator();
         InputStream inputStream = diagramGenerator.generateDiagram(bpmnModel, "png", highLightedNodeList, highLightedFlows, activityFontName, labelFontName, annotationFontName, null, 1.0, true);
-        return Base64.encode(IOUtils.toByteArray(inputStream));
+        return Base64.encode(IoUtil.readBytes(inputStream));
     }
 
     /**
-     * 閫氳繃娴佺▼瀹炰緥id鑾峰彇鍘嗗彶娴佺▼鍥捐繍琛屼腑锛屽巻鍙茬瓑鑺傜偣
+     * 閫氳繃涓氬姟id鑾峰彇鍘嗗彶娴佺▼鍥捐繍琛屼腑锛屽巻鍙茬瓑鑺傜偣
      *
-     * @param processInstanceId 娴佺▼瀹炰緥id
+     * @param businessKey 涓氬姟id
      */
     @Override
-    public Map<String, Object> getHistoryList(String processInstanceId) {
+    public Map<String, Object> getHistoryList(String businessKey) {
         Map<String, Object> map = new HashMap<>();
         List<Map<String, Object>> taskList = new ArrayList<>();
-        HistoricProcessInstance historicProcessInstance = QueryUtils.hisInstanceQuery(processInstanceId).singleResult();
+        HistoricProcessInstance historicProcessInstance = QueryUtils.hisBusinessKeyQuery(businessKey).singleResult();
+        String processInstanceId = historicProcessInstance.getId();
         StringBuilder xml = new StringBuilder();
         ProcessDefinition processDefinition = repositoryService.getProcessDefinition(historicProcessInstance.getProcessDefinitionId());
         // 鑾峰彇鑺傜偣
@@ -282,14 +283,9 @@
         map.put("taskList", taskList);
         List<ActHistoryInfoVo> historyTaskList = getHistoryTaskList(processInstanceId);
         map.put("historyList", historyTaskList);
-        InputStream inputStream;
-        try {
-            inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
-            xml.append(IOUtils.toString(inputStream, String.valueOf(StandardCharsets.UTF_8)));
-            map.put("xml", xml.toString());
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
+        InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
+        xml.append(IoUtil.read(inputStream, StandardCharsets.UTF_8));
+        map.put("xml", xml.toString());
         return map;
     }
 
@@ -306,7 +302,6 @@
         for (HistoricTaskInstance historicTaskInstance : list) {
             ActHistoryInfoVo actHistoryInfoVo = new ActHistoryInfoVo();
             BeanUtils.copyProperties(historicTaskInstance, actHistoryInfoVo);
-            actHistoryInfoVo.setAssignee(StringUtils.isNotBlank(historicTaskInstance.getAssignee()) ? Long.valueOf(historicTaskInstance.getAssignee()) : null);
             actHistoryInfoVo.setStatus(actHistoryInfoVo.getEndTime() == null ? "寰呭鐞�" : "宸插鐞�");
             if (ObjectUtil.isNotEmpty(historicTaskInstance.getDurationInMillis())) {
                 actHistoryInfoVo.setRunDuration(getDuration(historicTaskInstance.getDurationInMillis()));
@@ -324,6 +319,12 @@
                     historyInfoVo.setStartTime(e.getStartTime());
                     historyInfoVo.setEndTime(null);
                     historyInfoVo.setRunDuration(null);
+                    if (ObjectUtil.isEmpty(e.getAssignee())) {
+                        ParticipantVo participantVo = WorkflowUtils.getCurrentTaskParticipant(e.getId());
+                        if (ObjectUtil.isNotEmpty(participantVo) && CollUtil.isNotEmpty(participantVo.getCandidate())) {
+                            historyInfoVo.setAssignee(StreamUtils.join(participantVo.getCandidate(), Convert::toStr));
+                        }
+                    }
                 });
             historyInfoVoList.add(historyInfoVo);
         }
@@ -333,14 +334,15 @@
     /**
      * 鑾峰彇瀹℃壒璁板綍
      *
-     * @param processInstanceId 娴佺▼瀹炰緥id
+     * @param businessKey 涓氬姟id
      */
     @Override
-    public Map<String, Object> getHistoryRecord(String processInstanceId) {
-        Map<String, Object> map = new HashMap<>();
+    public List<ActHistoryInfoVo> getHistoryRecord(String businessKey) {
         // 鏌ヨ浠诲姟鍔炵悊璁板綍
-        List<HistoricTaskInstance> list = QueryUtils.hisTaskInstanceQuery(processInstanceId).orderByHistoricTaskInstanceEndTime().desc().list();
+        List<HistoricTaskInstance> list = QueryUtils.hisTaskBusinessKeyQuery(businessKey).orderByHistoricTaskInstanceEndTime().desc().list();
         list = StreamUtils.sorted(list, Comparator.comparing(HistoricTaskInstance::getEndTime, Comparator.nullsFirst(Date::compareTo)).reversed());
+        HistoricProcessInstance historicProcessInstance = QueryUtils.hisBusinessKeyQuery(businessKey).singleResult();
+        String processInstanceId = historicProcessInstance.getId();
         List<ActHistoryInfoVo> actHistoryInfoVoList = new ArrayList<>();
         List<Comment> processInstanceComments = taskService.getProcessInstanceComments(processInstanceId);
         //闄勪欢
@@ -362,11 +364,6 @@
             if (ObjectUtil.isNotEmpty(historicTaskInstance.getDurationInMillis())) {
                 actHistoryInfoVo.setRunDuration(getDuration(historicTaskInstance.getDurationInMillis()));
             }
-            try {
-                actHistoryInfoVo.setAssignee(StringUtils.isNotBlank(historicTaskInstance.getAssignee()) ? Long.valueOf(historicTaskInstance.getAssignee()) : null);
-            } catch (NumberFormatException ignored) {
-                log.warn("褰撳墠浠诲姟銆恵}銆�,鍔炵悊浜鸿浆鎹汉鍛業D銆恵}銆戝紓甯革紒", historicTaskInstance.getName(), historicTaskInstance.getAssignee());
-            }
             //闄勪欢
             if (CollUtil.isNotEmpty(attachmentList)) {
                 List<Attachment> attachments = attachmentList.stream().filter(e -> e.getTaskId().equals(historicTaskInstance.getId())).collect(Collectors.toList());
@@ -374,25 +371,19 @@
                     actHistoryInfoVo.setAttachmentList(attachments);
                 }
             }
+            //璁剧疆浜哄憳id
+            if (ObjectUtil.isEmpty(historicTaskInstance.getAssignee())) {
+                ParticipantVo participantVo = WorkflowUtils.getCurrentTaskParticipant(historicTaskInstance.getId());
+                if (ObjectUtil.isNotEmpty(participantVo) && CollUtil.isNotEmpty(participantVo.getCandidate())) {
+                    actHistoryInfoVo.setAssignee(StreamUtils.join(participantVo.getCandidate(), Convert::toStr));
+                }
+            }
             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);
-            String nickName = entry.getValue().stream().filter(e -> StringUtils.isNotBlank(e.getNickName()) && e.getEndTime() == null).map(ActHistoryInfoVo::getNickName).toList().stream().distinct().collect(Collectors.joining(StringUtils.SEPARATOR));
-            if (StringUtils.isNotBlank(nickName)) {
-                actHistoryInfoVo.setNickName(nickName);
-            }
             actHistoryInfoVoList.stream().filter(e -> e.getTaskDefinitionKey().equals(entry.getKey()) && e.getEndTime() != null).findFirst()
                 .ifPresent(e -> {
                     actHistoryInfoVo.setStatus("宸插鐞�");
@@ -405,39 +396,14 @@
                     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;
-    }
+        List<ActHistoryInfoVo> recordList = new ArrayList<>();
+        // 寰呭姙鐞�
+        recordList.addAll(StreamUtils.filter(actHistoryInfoVoList, e -> e.getEndTime() == null));
+        // 宸插姙鐞�
+        recordList.addAll(StreamUtils.filter(actHistoryInfoVoList, e -> e.getEndTime() != null));
 
-    /**
-     * 鏋勫缓鑺傜偣鍥惧舰淇℃伅
-     *
-     * @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);
-                }
-            }
-        }
+        return recordList;
     }
 
     /**
@@ -477,7 +443,8 @@
     @Transactional(rollbackFor = Exception.class)
     public boolean deleteRunInstance(ProcessInvalidBo processInvalidBo) {
         try {
-            List<Task> list = QueryUtils.taskQuery(processInvalidBo.getProcessInstanceId()).list();
+            List<Task> list = QueryUtils.taskQuery().processInstanceBusinessKey(processInvalidBo.getBusinessKey()).list();
+            String processInstanceId = list.get(0).getProcessInstanceId();
             List<Task> subTasks = StreamUtils.filter(list, e -> StringUtils.isNotBlank(e.getParentTaskId()));
             if (CollUtil.isNotEmpty(subTasks)) {
                 subTasks.forEach(e -> taskService.deleteTask(e.getId()));
@@ -489,10 +456,10 @@
             for (Task task : StreamUtils.filter(list, e -> StringUtils.isBlank(e.getParentTaskId()))) {
                 taskService.addComment(task.getId(), task.getProcessInstanceId(), TaskStatusEnum.INVALID.getStatus(), deleteReason);
             }
-            HistoricProcessInstance historicProcessInstance = QueryUtils.hisInstanceQuery(processInvalidBo.getProcessInstanceId()).singleResult();
+            HistoricProcessInstance historicProcessInstance = QueryUtils.hisInstanceQuery(processInstanceId).singleResult();
             BusinessStatusEnum.checkInvalidStatus(historicProcessInstance.getBusinessStatus());
-            runtimeService.updateBusinessStatus(processInvalidBo.getProcessInstanceId(), BusinessStatusEnum.INVALID.getStatus());
-            runtimeService.deleteProcessInstance(processInvalidBo.getProcessInstanceId(), deleteReason);
+            runtimeService.updateBusinessStatus(processInstanceId, BusinessStatusEnum.INVALID.getStatus());
+            runtimeService.deleteProcessInstance(processInstanceId, deleteReason);
             FlowProcessEventHandler processHandler = flowEventStrategy.getProcessHandler(historicProcessInstance.getProcessDefinitionKey());
             if (processHandler != null) {
                 processHandler.handleProcess(historicProcessInstance.getBusinessKey(), BusinessStatusEnum.INVALID.getStatus(), false);
@@ -507,40 +474,11 @@
     /**
      * 杩愯涓殑瀹炰緥 鍒犻櫎绋嬪疄渚嬶紝鍒犻櫎鍘嗗彶璁板綍锛屽垹闄や笟鍔′笌娴佺▼鍏宠仈淇℃伅
      *
-     * @param processInstanceIds 娴佺▼瀹炰緥id
-     */
-    @Override
-    @Transactional(rollbackFor = Exception.class)
-    public boolean deleteRunAndHisInstance(List<String> processInstanceIds) {
-        try {
-            // 1.鍒犻櫎杩愯涓祦绋嬪疄渚�
-            List<Task> list = QueryUtils.taskQuery(processInstanceIds).list();
-            List<Task> subTasks = StreamUtils.filter(list, e -> StringUtils.isNotBlank(e.getParentTaskId()));
-            if (CollUtil.isNotEmpty(subTasks)) {
-                subTasks.forEach(e -> taskService.deleteTask(e.getId()));
-            }
-            runtimeService.bulkDeleteProcessInstances(processInstanceIds, LoginHelper.getUserId() + "鍒犻櫎浜嗗綋鍓嶆祦绋嬬敵璇�");
-            // 2.鍒犻櫎鍘嗗彶璁板綍
-            List<HistoricProcessInstance> historicProcessInstanceList = QueryUtils.hisInstanceQuery(new HashSet<>(processInstanceIds)).list();
-            if (ObjectUtil.isNotEmpty(historicProcessInstanceList)) {
-                historyService.bulkDeleteHistoricProcessInstances(processInstanceIds);
-            }
-            iWfTaskBackNodeService.deleteByInstanceIds(processInstanceIds);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            throw new ServiceException(e.getMessage());
-        }
-    }
-
-    /**
-     * 鎸夌収涓氬姟id鍒犻櫎 杩愯涓殑瀹炰緥 鍒犻櫎绋嬪疄渚嬶紝鍒犻櫎鍘嗗彶璁板綍锛屽垹闄や笟鍔′笌娴佺▼鍏宠仈淇℃伅
-     *
      * @param businessKeys 涓氬姟id
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public boolean deleteRunAndHisInstanceByBusinessKeys(List<String> businessKeys) {
+    public boolean deleteRunAndHisInstance(List<String> businessKeys) {
         try {
             // 1.鍒犻櫎杩愯涓祦绋嬪疄渚�
             List<ActHiProcinst> actHiProcinsts = actHiProcinstService.selectByBusinessKeyIn(businessKeys);
@@ -560,7 +498,7 @@
             if (ObjectUtil.isNotEmpty(historicProcessInstanceList)) {
                 historyService.bulkDeleteHistoricProcessInstances(processInstanceIds);
             }
-            iWfTaskBackNodeService.deleteByInstanceIds(processInstanceIds);
+            wfTaskBackNodeService.deleteByInstanceIds(processInstanceIds);
             return true;
         } catch (Exception e) {
             e.printStackTrace();
@@ -571,14 +509,20 @@
     /**
      * 宸插畬鎴愮殑瀹炰緥 鍒犻櫎绋嬪疄渚嬶紝鍒犻櫎鍘嗗彶璁板綍锛屽垹闄や笟鍔′笌娴佺▼鍏宠仈淇℃伅
      *
-     * @param processInstanceIds 娴佺▼瀹炰緥id
+     * @param businessKeys 涓氬姟id
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public boolean deleteFinishAndHisInstance(List<String> processInstanceIds) {
+    public boolean deleteFinishAndHisInstance(List<String> businessKeys) {
         try {
+            List<ActHiProcinst> actHiProcinsts = actHiProcinstService.selectByBusinessKeyIn(businessKeys);
+            if (CollUtil.isEmpty(actHiProcinsts)) {
+                log.warn("褰撳墠涓氬姟ID:{}鏌ヨ鍒版祦绋嬪疄渚嬩负绌猴紒", businessKeys);
+                return false;
+            }
+            List<String> processInstanceIds = StreamUtils.toList(actHiProcinsts, ActHiProcinst::getId);
             historyService.bulkDeleteHistoricProcessInstances(processInstanceIds);
-            iWfTaskBackNodeService.deleteByInstanceIds(processInstanceIds);
+            wfTaskBackNodeService.deleteByInstanceIds(processInstanceIds);
             return true;
         } catch (Exception e) {
             e.printStackTrace();
@@ -589,13 +533,13 @@
     /**
      * 鎾ら攢娴佺▼鐢宠
      *
-     * @param processInstanceId 娴佺▼瀹炰緥id
+     * @param businessKey 涓氬姟id
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public boolean cancelProcessApply(String processInstanceId) {
+    public boolean cancelProcessApply(String businessKey) {
         try {
-            ProcessInstance processInstance = QueryUtils.instanceQuery(processInstanceId)
+            ProcessInstance processInstance = QueryUtils.businessKeyQuery(businessKey)
                 .startedBy(String.valueOf(LoginHelper.getUserId())).singleResult();
             if (ObjectUtil.isNull(processInstance)) {
                 throw new ServiceException("鎮ㄤ笉鏄祦绋嬪彂璧蜂汉,鎾ら攢澶辫触!");
@@ -603,13 +547,14 @@
             if (processInstance.isSuspended()) {
                 throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED);
             }
+            String processInstanceId = processInstance.getId();
             BusinessStatusEnum.checkCancelStatus(processInstance.getBusinessStatus());
             List<Task> taskList = QueryUtils.taskQuery(processInstanceId).list();
             for (Task task : taskList) {
                 taskService.setAssignee(task.getId(), null);
                 taskService.addComment(task.getId(), processInstanceId, TaskStatusEnum.CANCEL.getStatus(), LoginHelper.getLoginUser().getNickname() + "锛氭挙閿�鐢宠");
             }
-            HistoricTaskInstance historicTaskInstance = QueryUtils.hisTaskInstanceQuery().finished().orderByHistoricTaskInstanceEndTime().asc().list().get(0);
+            HistoricTaskInstance historicTaskInstance = QueryUtils.hisTaskInstanceQuery(processInstanceId).finished().orderByHistoricTaskInstanceEndTime().asc().list().get(0);
             List<String> nodeIds = StreamUtils.toList(taskList, Task::getTaskDefinitionKey);
             runtimeService.createChangeActivityStateBuilder()
                 .processInstanceId(processInstanceId)
@@ -679,7 +624,7 @@
         }
         if (CollUtil.isNotEmpty(list)) {
             List<String> processDefinitionIds = StreamUtils.toList(list, ProcessInstanceVo::getProcessDefinitionId);
-            List<WfNodeConfigVo> wfNodeConfigVoList = iWfNodeConfigService.selectByDefIds(processDefinitionIds);
+            List<WfNodeConfigVo> wfNodeConfigVoList = wfNodeConfigService.selectByDefIds(processDefinitionIds);
             for (ProcessInstanceVo processInstanceVo : list) {
                 if (CollUtil.isNotEmpty(wfNodeConfigVoList)) {
                     wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(processInstanceVo.getProcessDefinitionId()) && FlowConstant.TRUE.equals(e.getApplyUserTask())).findFirst().ifPresent(processInstanceVo::setWfNodeConfigVo);

--
Gitblit v1.9.3