| | |
| | | import org.flowable.task.api.Task; |
| | | import org.flowable.task.api.TaskQuery; |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.flowable.task.api.history.HistoricTaskInstanceQuery; |
| | | import org.springframework.context.ApplicationEventPublisher; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | |
| | | Result result = Result.ok(); |
| | | |
| | | // 代办任务 |
| | | this.getTodoTaskList(projectProcess.getProjectId(), projectProcess.getProcessInsId(), "", 5, 1, result); |
| | | // // 代办任务 |
| | | // this.getTodoTaskList(projectProcess.getProjectId(), projectProcess.getProcessInsId(), "", 5, 1, result); |
| | | return result.data(detail); |
| | | } |
| | | |
| | |
| | | return vos; |
| | | } |
| | | |
| | | @Override |
| | | public void getIndexWaitTask(String s, int pageSize, int pageNum, Result result) { |
| | | // 查出容缺过的任务 |
| | | List<ProcessLog> allWaitTaskList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.WAIT) |
| | | .orderByDesc(ProcessLog::getGmtCreate) |
| | | .list(); |
| | | // 排除容缺后又完成的任务 |
| | | List<ProcessLog> finishedTaskList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .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); |
| | | result.data(new ArrayList<>()); |
| | | return; |
| | | } |
| | | List<HistoricTaskInstance> hisTasks = waitTaskIds.stream().map(waitTaskId -> { |
| | | List<ProcessLog> logs = allWaitTaskList.stream().filter(item -> item.getTaskId().equals(waitTaskId)).collect(Collectors.toList()); |
| | | HistoricTaskInstance hisTask = null; |
| | | if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(logs)) { |
| | | // 容缺的任务都属于历史任务,只是需要补表单数据 |
| | | HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(logs.get(0).getProcessInsId()) |
| | | .taskId(waitTaskId) |
| | | .includeIdentityLinks() |
| | | .orderByHistoricTaskInstanceStartTime() |
| | | .desc(); |
| | | if (!SecurityUtils.getLoginUser().getUser().isAdmin()) { |
| | | query |
| | | .or() |
| | | .taskCandidateGroupIn(taskCommonService.getCurrentUserGroups()) |
| | | .taskCandidateUser(SecurityUtils.getUserId() + "") |
| | | .taskAssignee(SecurityUtils.getUserId() + "") |
| | | .endOr(); |
| | | } |
| | | List<HistoricTaskInstance> hisTaskList = query.list(); |
| | | hisTaskList = this.distinctHisTask(hisTaskList); |
| | | if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(hisTaskList)) { |
| | | hisTask = hisTaskList.get(0); |
| | | } |
| | | } |
| | | return hisTask; |
| | | }).filter(Objects::nonNull).collect(Collectors.toList()); |
| | | |
| | | if (CollectionUtils.isEmpty(hisTasks)) { |
| | | result.total(0l); |
| | | result.data(new ArrayList<>()); |
| | | return; |
| | | } |
| | | int startNum = pageSize * (pageNum - 1); |
| | | int endNum = startNum + pageSize; |
| | | if (startNum >= hisTasks.size()) { |
| | | result.total(0l); |
| | | // 如果起始索引超出了列表的大小,返回一个空列表 |
| | | result.data(new ArrayList<>()); |
| | | return; |
| | | } |
| | | result.total(hisTasks.size()); |
| | | int end = Math.min(endNum, hisTasks.size()); |
| | | List<HistoricTaskInstance> targetTask = hisTasks.subList(startNum, end); |
| | | |
| | | // 转换成VO |
| | | List<IndexCustomerTaskVO> vos = targetTask.stream().map(userTask -> { |
| | | IndexCustomerTaskVO vo = new IndexCustomerTaskVO(); |
| | | vo.setProcessInsId(userTask.getProcessInstanceId()); |
| | | vo.setProcessDefId(userTask.getProcessDefinitionId()); |
| | | |
| | | // 查出流程 |
| | | ProcessInstance process = runtimeService.createProcessInstanceQuery().processInstanceId(userTask.getProcessInstanceId()).singleResult(); |
| | | String deployId = ""; |
| | | String processName = ""; |
| | | if (Objects.nonNull(process)) { |
| | | deployId = process.getDeploymentId(); |
| | | processName = process.getProcessDefinitionName(); |
| | | } else { |
| | | HistoricProcessInstance hisProcess = historyService.createHistoricProcessInstanceQuery().processInstanceId(userTask.getProcessInstanceId()).singleResult(); |
| | | deployId = hisProcess.getDeploymentId(); |
| | | processName = hisProcess.getProcessDefinitionName(); |
| | | } |
| | | |
| | | String finalDeployId = deployId; |
| | | String finalProcessName = processName; |
| | | |
| | | 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); |
| | | |
| | | ProjectProcess projectProcess = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(ProjectProcess::getProcessInsId, userTask.getProcessInstanceId()) |
| | | .one(); |
| | | if (Objects.isNull(projectProcess)) { |
| | | throw new RuntimeException("项目流程未启动"); |
| | | } |
| | | String projectId = ""; |
| | | String projectName = ""; |
| | | if (Objects.nonNull(projectProcess)) { |
| | | if (projectProcess.getProjectType().equals(ProjectProcessTypeEnum.PROJECT)) { |
| | | ProjectInfo project = projectInfoMapper.selectById(projectProcess.getProjectId()); |
| | | if (Objects.nonNull(project)) { |
| | | projectId = projectProcess.getProjectId(); |
| | | projectName = project.getProjectName(); |
| | | } |
| | | } else if (projectProcess.getProjectType().equals(ProjectProcessTypeEnum.ENGINEERING)) { |
| | | ProjectEngineering engineering = projectEngineeringMapper.selectById(projectProcess.getProjectId()); |
| | | if (Objects.nonNull(engineering)) { |
| | | projectId = projectProcess.getProjectId(); |
| | | projectName = engineering.getProjectName(); |
| | | } |
| | | } |
| | | } |
| | | vo.setProjectId(projectId); |
| | | vo.setProjectName(projectName); |
| | | List<UserTask> uTaskList = this.getAllUserTaskElement(userTask.getProcessDefinitionId()).stream().filter(item -> item.getId().equals(userTask.getTaskDefinitionKey())).collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(uTaskList)) { |
| | | throw new RuntimeException("未找到流程任务设计"); |
| | | } |
| | | this.setCandidateInfo(uTaskList.get(0), vo, projectProcess.getProjectId(), userTask.getProcessInstanceId()); |
| | | |
| | | vo.setTaskStatus(TaskStatusEnum.WAIT); |
| | | // 如果是已完成的,信息需要单独赋值 |
| | | vo.setTaskId(userTask.getId()); |
| | | vo.setExecutionId(userTask.getExecutionId()); |
| | | vo.setCreateTime(userTask.getStartTime()); |
| | | |
| | | vo.setTaskDefinitionKey(userTask.getTaskDefinitionKey()); |
| | | |
| | | this.distinctVo(vo); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | result.data(vos); |
| | | } |
| | | |
| | | /** |
| | | * 容缺任务分页 |
| | | * |
| | | * @param projectId |
| | | * @param processDefinitionId |
| | | * @param processInsId |
| | | * @param taskName |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @param result |
| | | * @return |
| | | */ |
| | | private List<CustomerTaskVO> getWaitTask(String projectId, |
| | | String processDefinitionId, |
| | | String processInsId, |
| | |
| | | */ |
| | | private void setCandidateInfo(UserTask userTask, CustomerTaskVO vo, String projectId, String processInsId) { |
| | | if (StringUtils.isNotBlank(userTask.getAssignee())) { |
| | | vo.setHandlerType(HandlerTypeEnum.USER); |
| | | SysUser sysUser = sysUserService.selectUserById(Long.parseLong(userTask.getAssignee())); |
| | | if (Objects.nonNull(sysUser)) { |
| | | if (Objects.nonNull(sysUser.getDept())) { |