xiangpei
2025-03-19 1e133de871164bfd3f6c90f844a88165d986eab5
business/src/main/java/com/ycl/service/impl/ProjectProcessServiceImpl.java
@@ -331,7 +331,8 @@
                this.getTodoTaskList(query.getProjectId(), projectProcess.getProcessInsId(), query.getTaskName(), (int) query.getPageSize(), (int) query.getCurrentPage(), ok);
                ok.data(ok.get("taskList"));
                break;
            case TaskTypeConstant.CURRENT:
            case TaskTypeConstant.WAIT:
                this.getWaitTask(query.getProjectId(), query.getProcessDefId(), projectProcess.getProcessInsId(), query.getTaskName(), (int) query.getCurrentPage(), (int) query.getPageSize(), ok);
                break;
            case TaskTypeConstant.REMAINING:
                this.getRemainingTask(query.getProjectId(), query.getProcessDefId(), projectProcess.getProcessInsId(), query.getTaskName(), (int) query.getCurrentPage(), (int) query.getPageSize(), ok);
@@ -1102,7 +1103,7 @@
                vo.setCreateTime(task.getCreateTime());
                vo.setTaskDefinitionKey(task.getTaskDefinitionKey());
                this.setPromoterAndHandler(vo, null);
                this.setHandler(vo, null);
                this.setRuntimeTaskInfo(task, vo, projectId);
            }
            this.distinctVo(vo);
@@ -1174,7 +1175,7 @@
                    vo.setActualHandlerUserName(handlerUser.getNickName());
                }
                vo.setTaskDefinitionKey(hisTaskList.get(0).getTaskDefinitionKey());
                this.setPromoterAndHandler(vo, hisTaskList.get(0).getIdentityLinks());
                this.setHandler(vo, hisTaskList.get(0).getIdentityLinks());
            }
            return vo;
        }).filter(Objects::nonNull).collect(Collectors.toList());
@@ -1722,6 +1723,127 @@
        return vos;
    }
    private List<CustomerTaskVO> getWaitTask(String projectId,
                                             String processDefinitionId,
                                             String processInsId,
                                             String taskName,
                                             Integer pageNum,
                                             Integer pageSize,
                                             Result result) {
        // 查出容缺过的任务
        List<ProcessLog> allWaitTaskList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper())
                .eq(ProcessLog::getProcessInsId, processInsId)
                .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.WAIT)
                .like(StringUtils.isNotBlank(taskName), ProcessLog::getTaskName, taskName)
                .orderByDesc(ProcessLog::getGmtCreate)
                .list();
        // 排除容缺后又完成的任务
        List<ProcessLog> finishedTaskList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper())
                .eq(ProcessLog::getProcessInsId, processInsId)
                .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.FINISHED)
                .list();
        List<String> finishedTaskIds = finishedTaskList.stream().map(ProcessLog::getTaskId).distinct().collect(Collectors.toList());
        // 得到未完成的容缺任务
        List<String> waitTaskIds = allWaitTaskList.stream().filter(log -> !finishedTaskIds.contains(log.getTaskId())).map(ProcessLog::getTaskId).collect(Collectors.toList());
        if (CollectionUtils.isEmpty(waitTaskIds)) {
            result.total(0l);
            return new ArrayList<>();
        }
        // 容缺的任务都属于历史任务,只是需要补表单数据
        List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery()
                .processInstanceId(processInsId)
                .taskIds(waitTaskIds)
                .includeIdentityLinks()
                .orderByHistoricTaskInstanceStartTime()
                .desc()
                .list();
        hisTaskList = this.distinctHisTask(hisTaskList);
        if (CollectionUtils.isEmpty(hisTaskList)) {
            result.total(0l);
            return new ArrayList<>();
        }
        int startNum = pageSize * (pageNum - 1);
        int endNum = startNum + pageSize;
        if (startNum >= hisTaskList.size()) {
            result.total(0l);
            // 如果起始索引超出了列表的大小,返回一个空列表
            return new ArrayList<>();
        }
        result.total(hisTaskList.size());
        int end = Math.min(endNum, hisTaskList.size());
        List<HistoricTaskInstance> targetTask = hisTaskList.subList(startNum, end);
        // 转换成VO
        // 得到目标任务对应的定义
        List<String> taskDefs = targetTask.stream().map(HistoricTaskInstance::getTaskDefinitionKey).collect(Collectors.toList());
        Map<String, HistoricTaskInstance> keyMap = targetTask.stream().collect(Collectors.toMap(HistoricTaskInstance::getTaskDefinitionKey, his -> his));
        List<UserTask> finishedUserTaskElement = this.getAllUserTaskElement(processDefinitionId).stream().filter(el -> taskDefs.contains(el.getId())).collect(Collectors.toList());
        // 查出流程
        ProcessInstance process = runtimeService.createProcessInstanceQuery().processInstanceId(processInsId).singleResult();
        String deployId = "";
        String processName = "";
        if (Objects.nonNull(process)) {
            deployId = process.getDeploymentId();
            processName = process.getProcessDefinitionName();
        } else {
            HistoricProcessInstance hisProcess = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInsId).singleResult();
            deployId = hisProcess.getDeploymentId();
            processName = hisProcess.getProcessDefinitionName();
        }
        String finalDeployId = deployId;
        String finalProcessName = processName;
        List<CustomerTaskVO> vos = finishedUserTaskElement.stream().map(userTask -> {
            CustomerTaskVO vo = new CustomerTaskVO();
            vo.setProcessInsId(processInsId);
            vo.setProcessDefId(processDefinitionId);
            vo.setDeployId(finalDeployId);
            vo.setTaskName(userTask.getName());
            vo.setProcessName(finalProcessName);
            // 一个任务可能有多个候选人/组,所以需要使用list
            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);
            HistoricTaskInstance hisTask = keyMap.get(userTask.getId());
            if (Objects.nonNull(hisTask)) {
                vo.setTaskStatus(TaskStatusEnum.WAIT);
                // 如果是已完成的,信息需要单独赋值
                vo.setTaskId(hisTask.getId());
                vo.setExecutionId(hisTask.getExecutionId());
                vo.setCreateTime(hisTask.getStartTime());
                // 查询实际处理人
                long handlerUserId = Long.parseLong(hisTask.getAssignee());
                SysUser handlerUser = sysUserService.selectUserById(handlerUserId);
                if (Objects.nonNull(handlerUser)) {
                    vo.getHandlerId().add(handlerUserId);
                    if (Objects.nonNull(handlerUser.getDept())) {
                        vo.getHandlerUnitId().add(handlerUser.getDept().getDeptId());
                    }
                }
                this.setHandler(vo, hisTask.getIdentityLinks());
                vo.setTaskDefinitionKey(hisTask.getTaskDefinitionKey());
            }
            this.distinctVo(vo);
            return vo;
        }).collect(Collectors.toList());
        result.data(vos);
        return vos;
    }
    /**
     * 查询剩余事项(未开始的任务)
     *
@@ -1977,7 +2099,7 @@
     * @param taskVO
     * @param identityLinkInfos 如果是已完成的任务,用这个去取关联的用户/用户组
     */
    private void setPromoterAndHandler(CustomerTaskVO taskVO, List<? extends IdentityLinkInfo> identityLinkInfos) {
    private void setHandler(CustomerTaskVO taskVO, List<? extends IdentityLinkInfo> identityLinkInfos) {
        // 流程处理人信息
        if (TaskStatusEnum.TODO.equals(taskVO.getTaskStatus())) {
@@ -2021,7 +2143,7 @@
                    }
                }
            }
        } else if (TaskStatusEnum.FINISHED.equals(taskVO.getTaskStatus())) {
        } else if (TaskStatusEnum.FINISHED.equals(taskVO.getTaskStatus()) || TaskStatusEnum.WAIT.equals(taskVO.getTaskStatus())) {
            for (IdentityLinkInfo identityLink : identityLinkInfos) {
                // 绑定的是用户,查出用户姓名、部门
                if (StringUtils.isNotBlank(identityLink.getUserId())) {