guoshilong
2023-05-12 586019ba7ccb6088ae8bc5f4bfa78cdede1e3e7e
skjcmanager/skjcmanager-ops/skjcmanager-flow/src/main/java/cn/gistack/flow/business/service/impl/FlowBusinessServiceImpl.java
@@ -20,6 +20,7 @@
import cn.gistack.flow.core.constant.ProcessConstant;
import cn.gistack.flow.core.entity.BladeFlow;
import cn.gistack.flow.core.utils.TaskUtil;
import cn.gistack.flow.core.vo.BladeFlowVO;
import cn.gistack.flow.engine.constant.FlowEngineConstant;
import cn.gistack.flow.engine.entity.FlowProcess;
import cn.gistack.flow.engine.utils.FlowCache;
@@ -275,6 +276,72 @@
   }
   @Override
   public IPage<BladeFlowVO> selectDonePage(IPage<BladeFlowVO> page, BladeFlow bladeFlow,String currentUserId) {
      String taskUser = StringUtil.format("{}{}", TASK_USR_PREFIX, currentUserId);
      List<BladeFlowVO> flowList = new LinkedList<>();
      HistoricTaskInstanceQuery doneQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(taskUser).finished()
         .includeProcessVariables().orderByHistoricTaskInstanceEndTime().desc();
      if (bladeFlow.getCategory() != null) {
         doneQuery.processCategoryIn(Func.toStrList(bladeFlow.getCategory()));
      }
      if (bladeFlow.getProcessDefinitionName() != null) {
         doneQuery.processDefinitionName(bladeFlow.getProcessDefinitionName());
      }
      if (bladeFlow.getBeginDate() != null) {
         doneQuery.taskCompletedAfter(bladeFlow.getBeginDate());
      }
      if (bladeFlow.getEndDate() != null) {
         doneQuery.taskCompletedBefore(bladeFlow.getEndDate());
      }
      // 查询列表
      List<HistoricTaskInstance> doneList = doneQuery.listPage(Func.toInt((page.getCurrent() - 1) * page.getSize()), Func.toInt(page.getSize()));
      doneList.forEach(historicTaskInstance -> {
         BladeFlowVO flow = new BladeFlowVO();
         flow.setTaskId(historicTaskInstance.getId());
         flow.setTaskDefinitionKey(historicTaskInstance.getTaskDefinitionKey());
         flow.setTaskName(historicTaskInstance.getName());
         flow.setAssignee(historicTaskInstance.getAssignee());
         flow.setCreateTime(historicTaskInstance.getCreateTime());
         flow.setExecutionId(historicTaskInstance.getExecutionId());
         flow.setHistoryTaskEndTime(historicTaskInstance.getEndTime());
         flow.setVariables(historicTaskInstance.getProcessVariables());
         FlowProcess processDefinition = FlowCache.getProcessDefinition(historicTaskInstance.getProcessDefinitionId());
         flow.setProcessDefinitionId(processDefinition.getId());
         flow.setProcessDefinitionName(processDefinition.getName());
         flow.setProcessDefinitionKey(processDefinition.getKey());
         flow.setProcessDefinitionVersion(processDefinition.getVersion());
         flow.setCategory(processDefinition.getCategory());
         flow.setCategoryName(FlowCache.getCategoryName(processDefinition.getCategory()));
         flow.setProcessInstanceId(historicTaskInstance.getProcessInstanceId());
         flow.setHistoryProcessInstanceId(historicTaskInstance.getProcessInstanceId());
         HistoricProcessInstance historicProcessInstance = getHistoricProcessInstance((historicTaskInstance.getProcessInstanceId()));
         if (Func.isNotEmpty(historicProcessInstance)) {
            String[] businessKey = Func.toStrArray(StringPool.COLON, historicProcessInstance.getBusinessKey());
            flow.setBusinessTable(businessKey[0]);
            flow.setBusinessId(businessKey[1]);
            if (historicProcessInstance.getEndActivityId() != null) {
               flow.setProcessIsFinished(FlowEngineConstant.STATUS_FINISHED);
            } else {
               flow.setProcessIsFinished(FlowEngineConstant.STATUS_UNFINISHED);
            }
         }
         flow.setStatus(FlowEngineConstant.STATUS_FINISH);
         flowList.add(flow);
      });
      // 计算总数
      long count = doneQuery.count();
      // 设置总数
      page.setTotal(count);
      page.setRecords(flowList);
      return page;
   }
   @Override
   public boolean completeTask(BladeFlow flow) {
      String taskId = flow.getTaskId();
      String processInstanceId = flow.getProcessInstanceId();