| | |
| | | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | |
| | | import com.ycl.domain.entity.*; |
| | | import com.ycl.domain.form.*; |
| | | import com.ycl.domain.json.*; |
| | | import com.ycl.domain.vo.CustomerTaskVO; |
| | | import com.ycl.domain.vo.IndexCustomerTaskVO; |
| | | import com.ycl.domain.vo.ProjectProcessDetailVO; |
| | | import com.ycl.domain.query.ProcessLogQuery; |
| | | import com.ycl.domain.vo.*; |
| | | import com.ycl.event.event.TaskLogEvent; |
| | | import com.ycl.mapper.ProjectEngineeringMapper; |
| | | import com.ycl.mapper.ProjectInfoMapper; |
| | |
| | | import com.ycl.service.*; |
| | | import com.ycl.common.base.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.domain.vo.ProjectProcessVO; |
| | | import com.ycl.domain.query.ProjectProcessQuery; |
| | | import com.ycl.service.common.TaskCommonService; |
| | | import com.ycl.system.domain.base.AbsQuery; |
| | | import com.ycl.system.service.ISysDeptService; |
| | | import com.ycl.system.service.ISysDictTypeService; |
| | | import com.ycl.system.service.ISysRoleService; |
| | |
| | | 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; |
| | |
| | | IPage<ProjectProcessVO> page = PageUtil.getPage(query, ProjectProcessVO.class); |
| | | baseMapper.getPage(query, page); |
| | | for (ProjectProcessVO vo : page.getRecords()) { |
| | | vo.setChildren(TreeUtil.treeForProjectEng(baseMapper.getEngineeringList(vo.getId()))); |
| | | List<ProjectEngineeringVO> childList = baseMapper.getEngineeringList(vo.getId()); |
| | | childList.stream().forEach(child -> { |
| | | if (StringUtils.isNotBlank(child.getProcessDefId())) { |
| | | ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(child.getProcessDefId()).singleResult(); |
| | | if (Objects.nonNull(processDefinition)) { |
| | | child.setSuspended(processDefinition.isSuspended()); |
| | | child.setFlowableProcessName(processDefinition.getName() + "(v" + processDefinition.getVersion() + ")"); |
| | | child.setDeployId(processDefinition.getDeploymentId()); |
| | | } |
| | | } |
| | | }); |
| | | vo.setChildren(TreeUtil.treeForProjectEng(childList)); |
| | | vo.setStatus(vo.getProjectStatus()); |
| | | if (Objects.nonNull(vo.getProcessDefId())) { |
| | | if (StringUtils.isNotBlank(vo.getProcessDefId())) { |
| | | ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(vo.getProcessDefId()).singleResult(); |
| | | if (Objects.nonNull(processDefinition)) { |
| | | vo.setSuspended(processDefinition.isSuspended()); |
| | |
| | | Long unitId = null; |
| | | if (ProjectProcessTypeEnum.PROJECT.equals(form.getProjectType())) { |
| | | ProjectInfo project = new LambdaQueryChainWrapper<>(projectInfoMapper) |
| | | .select(ProjectInfo::getProjectOwnerUnit) |
| | | .eq(ProjectInfo::getId, form.getProjectId()) |
| | | .one(); |
| | | if (Objects.isNull(project)) { |
| | |
| | | unitId = project.getProjectOwnerUnit(); |
| | | } else if (ProjectProcessTypeEnum.ENGINEERING.equals(form.getProjectType())) { |
| | | ProjectEngineering projectEngineering = new LambdaQueryChainWrapper<>(projectEngineeringMapper) |
| | | .select(ProjectEngineering::getDepartment) |
| | | .eq(ProjectEngineering::getId, form.getProjectId()) |
| | | .one(); |
| | | if (Objects.isNull(projectEngineering)) { |
| | |
| | | Long unitId = null; |
| | | if (ProjectProcessTypeEnum.PROJECT.equals(form.getProjectType())) { |
| | | ProjectInfo project = new LambdaQueryChainWrapper<>(projectInfoMapper) |
| | | .select(ProjectInfo::getProjectOwnerUnit) |
| | | .eq(ProjectInfo::getId, form.getProjectId()) |
| | | .one(); |
| | | if (Objects.isNull(project)) { |
| | |
| | | unitId = project.getProjectOwnerUnit(); |
| | | } else if (ProjectProcessTypeEnum.ENGINEERING.equals(form.getProjectType())) { |
| | | ProjectEngineering projectEngineering = new LambdaQueryChainWrapper<>(projectEngineeringMapper) |
| | | .select(ProjectEngineering::getDepartment) |
| | | .eq(ProjectEngineering::getId, form.getProjectId()) |
| | | .one(); |
| | | if (Objects.isNull(projectEngineering)) { |
| | |
| | | variables.put(ProcessConstants.PROCESS_INITIATOR, sysUser.getUserId()); |
| | | // 将该项目的申请人(业主方)作为流程中某些环节的处理人 |
| | | variables.put(ProcessConstants.DATA_LAUNCH, "dept:" + createBy); |
| | | variables.put("a", 1); |
| | | ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefId, projectId + "", variables); |
| | | return processInstance.getId(); |
| | | } |
| | |
| | | taskStatistics.setTimelyFinishedTaskNum(this.getTimelyTaskNum(projectProcess.getProcessInsId())); |
| | | taskStatistics.setOvertimeTaskNum(this.getOvertimeTaskNum(projectProcess.getProcessInsId())); |
| | | taskStatistics.setWillOvertimeTaskNum(this.getWillOvertimeTaskNum(projectProcess.getProcessInsId())); |
| | | // taskStatistics.setCurrentTask(this.getCurrentNodeTaskList(projectProcess.getProcessInstanceId())); |
| | | taskStatistics.setWaitTaskNum(this.getWaitTaskNum(projectProcess.getProcessInsId())); |
| | | taskStatistics.setJumpTaskNum(this.getJumpTaskNum(projectProcess.getProcessInsId())); |
| | | detail.setStatistics(taskStatistics); |
| | | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 容缺任务计数 |
| | | * @param processInsId |
| | | * @return |
| | | */ |
| | | private Long getWaitTaskNum(String processInsId){ |
| | | // 查出容缺过的任务 |
| | | List<ProcessLog> allWaitTaskList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.WAIT) |
| | | .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)) { |
| | | return 0L; |
| | | } |
| | | return Long.valueOf(waitTaskIds.size()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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.JUMP: |
| | | this.getJumpTask(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); |
| | |
| | | .endOr(); |
| | | } |
| | | result.total(taskQuery.count()); |
| | | List<Task> taskList = taskQuery.listPage(pageSize * (pageNum - 1), pageSize); |
| | | List<Task> allTodoList = taskQuery.list(); |
| | | List<TaskOrderVO> orderList = new ArrayList<>(); |
| | | allTodoList.stream().forEach(task -> { |
| | | TaskOrderVO order = new TaskOrderVO(); |
| | | order.setTaskId(task.getId()); |
| | | // 计算办理时间,超时的排前面,没超时的由低到高排序,没超时时间的排最后 |
| | | ProcessCoding processCoding = processCodingService.getByTaskId(task.getId(), task.getProcessInstanceId()); |
| | | if (Objects.nonNull(processCoding)) { |
| | | if (StringUtils.isNotBlank(processCoding.getRedTime())) { |
| | | Long overtime = getTime(processCoding.getRedTime()); |
| | | long durationTime = 0l; |
| | | if (Objects.nonNull(processCoding.getStartTaskTime())) { |
| | | durationTime = ((new Date()).getTime() - processCoding.getStartTaskTime().getTime()) / 1000; |
| | | } |
| | | if (overtime > durationTime) { |
| | | order.setNum((overtime - durationTime) / 3600); |
| | | } else { |
| | | order.setNum(-2000000L); |
| | | } |
| | | } else { |
| | | order.setNum(2000000L); |
| | | } |
| | | } else { |
| | | order.setNum(2000000L); |
| | | } |
| | | orderList.add(order); |
| | | }); |
| | | // 升序排列 |
| | | Collections.sort(orderList, Comparator.comparingLong(TaskOrderVO::getNum)); |
| | | int startNum = pageSize * (pageNum - 1); |
| | | int endNum = startNum + pageSize; |
| | | if (startNum >= orderList.size()) { |
| | | result.data(new ArrayList<>()).total(0L); |
| | | return; |
| | | } |
| | | int end = Math.min(endNum, orderList.size()); |
| | | List<String> targetTaskIds = orderList.subList(startNum, end).stream().map(TaskOrderVO::getTaskId).collect(Collectors.toList()); |
| | | List<Task> taskList = targetTaskIds.stream().map(taskId -> { |
| | | List<Task> list = allTodoList.stream().filter(task -> task.getId().equals(taskId)).collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return null; |
| | | } |
| | | return list.get(0); |
| | | }).filter(Objects::nonNull).collect(Collectors.toList()); |
| | | List<IndexCustomerTaskVO> vos = new ArrayList<>(); |
| | | for (Task task : taskList) { |
| | | IndexCustomerTaskVO taskVO = new IndexCustomerTaskVO(); |
| | |
| | | taskVO.setTaskDefinitionKey(task.getTaskDefinitionKey()); |
| | | |
| | | // 流程项目信息 |
| | | ProjectInfo project = baseMapper.getProjectInfo(task.getProcessInstanceId()); |
| | | if (Objects.nonNull(project)) { |
| | | taskVO.setProjectId(project.getId()); |
| | | taskVO.setProjectName(project.getProjectName()); |
| | | } else { |
| | | continue; |
| | | ProjectProcess projectProcess = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(ProjectProcess::getProcessInsId, task.getProcessInstanceId()) |
| | | .one(); |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | taskVO.setProjectId(projectId); |
| | | taskVO.setProjectName(projectName); |
| | | |
| | | // 流程发起人信息 |
| | | this.setPromoterInfo(taskVO); |
| | |
| | | } |
| | | |
| | | // 计算办理时间 |
| | | ProcessCoding processCoding = processCodingService.getByTaskId(task.getId()); |
| | | if (processCoding != null) { |
| | | if (StringUtils.isNotBlank(processCoding.getOvertime())) { |
| | | Long overtime = getTime(processCoding.getOvertime()); |
| | | ProcessCoding processCoding = processCodingService.getByTaskId(task.getId(), task.getProcessInstanceId()); |
| | | if (Objects.nonNull(processCoding)) { |
| | | if (StringUtils.isNotBlank(processCoding.getRedTime())) { |
| | | Long overtime = getTime(processCoding.getRedTime()); |
| | | long durationTime = 0l; |
| | | if (Objects.nonNull(processCoding.getStartTaskTime())) { |
| | | durationTime = ((new Date()).getTime() - processCoding.getStartTaskTime().getTime()) / 1000; |
| | | } else { |
| | | taskVO.setRemainingTime("未设置办理时间"); |
| | | } |
| | | if (overtime > durationTime) { |
| | | taskVO.setRemainingTime((overtime - durationTime) / 3600 + "小时"); |
| | |
| | | } else { |
| | | taskVO.setRemainingTime("-"); |
| | | } |
| | | } else { |
| | | taskVO.setRemainingTime("-"); |
| | | } |
| | | this.distinctVo(taskVO); |
| | | vos.add(taskVO); |
| | |
| | | } |
| | | } |
| | | // 完成任务 |
| | | flowTaskService.completeSubmitForm(form.getTaskId(), data); |
| | | flowTaskService.completeSubmitForm(form.getTaskId(), data, Boolean.FALSE); |
| | | } |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result taskWait(TaskWaitForm form) { |
| | | Task task = taskService.createTaskQuery().taskId(form.getTaskId()).processInstanceId(form.getProcessInsId()).singleResult(); |
| | | if (Objects.nonNull(task)) { |
| | | // 添加容缺日志 |
| | | publisher.publishEvent(new TaskLogEvent(this, |
| | | null, |
| | | SecurityUtils.getUserId(), |
| | | form.getProjectId(), |
| | | form.getProcessInsId(), |
| | | task.getId(), |
| | | task.getTaskDefinitionKey(), |
| | | task.getName(), |
| | | ProcessLogEventTypeEnum.WAIT, |
| | | new WaitData(form.getDesc()))); |
| | | // 查出该任务绑定的表单 |
| | | Map<String, Object> data = new HashMap<>(1); |
| | | if (StringUtils.isNotBlank(task.getFormKey())) { |
| | | SysForm sysForm = formService.selectSysFormById(Long.parseLong(task.getFormKey())); |
| | | if (Objects.nonNull(sysForm)) { |
| | | data.put(ProcessConstants.TASK_FORM_KEY, JSONObject.parseObject(sysForm.getFormContent())); |
| | | } |
| | | } |
| | | // 完成任务 |
| | | flowTaskService.completeSubmitForm(form.getTaskId(), data, Boolean.FALSE); |
| | | } |
| | | return Result.ok("操作成功"); |
| | | } |
| | |
| | | ProcessLog processLog = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getTaskId, form.getTaskId()) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.SUPERVISE) |
| | | .eq(ProcessLog::getProcessInsId, form.getProcessInsId()) |
| | | .eq(ProcessLog::getProcessInsId, task.getProcessInstanceId()) |
| | | .one(); |
| | | List<SuperviseData> dataList; |
| | | if (processLog != null) { |
| | |
| | | processLog.getId(), |
| | | processLog.getUserId(), |
| | | form.getProjectId(), |
| | | form.getProcessInsId(), |
| | | task.getProcessInstanceId(), |
| | | form.getTaskId(), |
| | | task.getTaskDefinitionKey(), |
| | | task.getName(), |
| | |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result getProcessMsg(AbsQuery q) { |
| | | // 查自己的日志 |
| | | ProcessLogQuery query = new ProcessLogQuery(); |
| | | if (! SecurityUtils.isAdmin(SecurityUtils.getUserId())) { |
| | | query.setUserId(SecurityUtils.getUserId()); |
| | | } |
| | | query.setEventTypeList(Arrays.asList(ProcessLogEventTypeEnum.DELEGATE.getValue(), |
| | | ProcessLogEventTypeEnum.REJECT.getValue(), |
| | | ProcessLogEventTypeEnum.JUMP.getValue(), |
| | | ProcessLogEventTypeEnum.FINISHED.getValue(), |
| | | ProcessLogEventTypeEnum.WAIT.getValue())); |
| | | query.setCurrentPage(q.getCurrentPage()); |
| | | query.setPageSize(q.getPageSize()); |
| | | Result result = processLogService.projectProcessLogPage(query); |
| | | List<ProcessLogVO> logs = (List<ProcessLogVO>) result.get("data"); |
| | | |
| | | logs.stream().forEach(log -> { |
| | | if (ProcessLogEventTypeEnum.FINISHED.equals(log.getEventType())) { |
| | | log.setContent("您完成了任务:" + log.getTaskName()); |
| | | } else if (ProcessLogEventTypeEnum.REJECT.equals(log.getEventType())) { |
| | | log.setContent("您驳回了任务:" + log.getTaskName()); |
| | | } else if (ProcessLogEventTypeEnum.WAIT.equals(log.getEventType())) { |
| | | log.setContent("您容缺了任务:" + log.getTaskName()); |
| | | } else if (ProcessLogEventTypeEnum.JUMP.equals(log.getEventType())) { |
| | | log.setContent("您跳过了任务:" + log.getTaskName()); |
| | | } |
| | | }); |
| | | return Result.ok().data(logs).total((Long) result.get("total")); |
| | | } |
| | | |
| | | /** |
| | | * 查询待办任务 |
| | | * |
| | |
| | | * @param result |
| | | */ |
| | | public void getTodoTaskList(String projectId, String processInsId, String taskName, int pageSize, int pageNum, Result result) { |
| | | |
| | | TaskQuery taskQuery = taskService.createTaskQuery() |
| | | .active() |
| | | .processInstanceId(processInsId) |
| | |
| | | vo.setHandlerType(HandlerTypeEnum.USER); |
| | | SysUser sysUser = sysUserService.selectUserById(Long.parseLong(userTask.getAssignee())); |
| | | if (Objects.nonNull(sysUser)) { |
| | | handlerIds.add(sysUser.getUserId()); |
| | | handlerNames.add(this.getUserShowName(sysUser)); |
| | | vo.getHandlerId().add(sysUser.getUserId()); |
| | | vo.getHandlerName().add(this.getUserShowName(sysUser)); |
| | | if (Objects.nonNull(sysUser.getDept())) { |
| | | handlerUnitIds.add(sysUser.getDept().getDeptId()); |
| | | handlerUnitNames.add(sysUser.getDept().getDeptName()); |
| | | vo.getHandlerUnitId().add(sysUser.getDept().getDeptId()); |
| | | vo.getHandlerUnitName().add(sysUser.getDept().getDeptName()); |
| | | } |
| | | } |
| | | } else if (CollectionUtil.isNotEmpty(userTask.getCandidateGroups())) { |
| | |
| | | // 部门 |
| | | SysDept dept = sysDeptService.selectDeptById(Long.parseLong(split[1])); |
| | | if (Objects.nonNull(dept)) { |
| | | handlerUnitIds.add(dept.getDeptId()); |
| | | handlerUnitNames.add(dept.getDeptName()); |
| | | handlerNames.add(this.getDeptLeaderShowName(dept)); |
| | | vo.getHandlerUnitId().add(dept.getDeptId()); |
| | | vo.getHandlerUnitName().add(dept.getDeptName()); |
| | | vo.getHandlerName().add(this.getDeptLeaderShowName(dept)); |
| | | } |
| | | } |
| | | } else { |
| | | vo.setHandlerType(HandlerTypeEnum.ROLE); |
| | | SysRole role = sysRoleService.selectRoleById(Long.parseLong(groupId)); |
| | | if (Objects.nonNull(role)) { |
| | | handlerUnitIds.add(role.getRoleId()); |
| | | handlerUnitNames.add(role.getRoleName()); |
| | | vo.getHandlerUnitId().add(role.getRoleId()); |
| | | vo.getHandlerUnitName().add(role.getRoleName()); |
| | | } |
| | | } |
| | | } |
| | |
| | | vo.setCreateTime(historicTasks.get(0).getStartTime()); |
| | | |
| | | // 查询实际处理人 |
| | | long handlerUserId = Long.parseLong(historicTasks.get(0).getAssignee()); |
| | | SysUser handlerUser = sysUserService.selectUserById(handlerUserId); |
| | | if (Objects.nonNull(handlerUser)) { |
| | | handlerIds.add(handlerUserId); |
| | | handlerNames.add(this.getUserShowName(handlerUser)); |
| | | if (Objects.nonNull(handlerUser.getDept())) { |
| | | handlerUnitNames.add(handlerUser.getDept().getDeptName()); |
| | | handlerUnitIds.add(handlerUser.getDept().getDeptId()); |
| | | if (StringUtils.isNotBlank(historicTasks.get(0).getAssignee())) { |
| | | long handlerUserId = Long.parseLong(historicTasks.get(0).getAssignee()); |
| | | SysUser handlerUser = sysUserService.selectUserById(handlerUserId); |
| | | if (Objects.nonNull(handlerUser)) { |
| | | vo.getHandlerId().add(handlerUserId); |
| | | vo.getHandlerName().add(this.getUserShowName(handlerUser)); |
| | | if (Objects.nonNull(handlerUser.getDept())) { |
| | | vo.getHandlerUnitName().add(handlerUser.getDept().getDeptName()); |
| | | vo.getHandlerUnitId().add(handlerUser.getDept().getDeptId()); |
| | | } |
| | | } |
| | | } |
| | | vo.setTaskDefinitionKey(historicTasks.get(0).getTaskDefinitionKey()); |
| | | this.setPromoterAndHandler(vo, historicTasks.get(0).getIdentityLinks()); |
| | | } |
| | | } else { |
| | | vo.setTaskStatus(TaskStatusEnum.TODO); |
| | |
| | | vo.setCreateTime(task.getCreateTime()); |
| | | vo.setTaskDefinitionKey(task.getTaskDefinitionKey()); |
| | | |
| | | this.setPromoterAndHandler(vo, null); |
| | | this.setHandler(vo, null); |
| | | this.setRuntimeTaskInfo(task, vo, projectId); |
| | | } |
| | | this.distinctVo(vo); |
| | |
| | | .orderByHistoricTaskInstanceStartTime() |
| | | .desc() |
| | | .list(); |
| | | |
| | | vo.setTaskStatus(TaskStatusEnum.FINISHED); |
| | | // 如果是已完成的,信息需要单独赋值 |
| | | vo.setTaskId(hisTaskList.get(0).getId()); |
| | | vo.setExecutionId(hisTaskList.get(0).getExecutionId()); |
| | | vo.setCreateTime(hisTaskList.get(0).getStartTime()); |
| | | // 查询实际处理人 |
| | | long handlerUserId = Long.parseLong(hisTaskList.get(0).getAssignee()); |
| | | SysUser handlerUser = sysUserService.selectUserById(handlerUserId); |
| | | if (Objects.nonNull(handlerUser)) { |
| | | |
| | | vo.setActualHandlerUserId(hisTaskList.get(0).getAssignee()); |
| | | vo.setActualHandlerUserName(handlerUser.getNickName()); |
| | | // 如果未找到历史任务,说明这个任务可能处于某个互斥网关下,实际并未执行 |
| | | if (CollectionUtils.isEmpty(hisTaskList)) { |
| | | vo.setTaskStatus(TaskStatusEnum.NOT_START); |
| | | } else { |
| | | vo.setTaskStatus(TaskStatusEnum.FINISHED); |
| | | // 如果是已完成的,信息需要单独赋值 |
| | | vo.setTaskId(hisTaskList.get(0).getId()); |
| | | vo.setExecutionId(hisTaskList.get(0).getExecutionId()); |
| | | vo.setCreateTime(hisTaskList.get(0).getStartTime()); |
| | | // 查询实际处理人 |
| | | if (StringUtils.isNotBlank(hisTaskList.get(0).getAssignee())) { |
| | | long handlerUserId = Long.parseLong(hisTaskList.get(0).getAssignee()); |
| | | SysUser handlerUser = sysUserService.selectUserById(handlerUserId); |
| | | if (Objects.nonNull(handlerUser)) { |
| | | vo.setActualHandlerUserId(hisTaskList.get(0).getAssignee()); |
| | | vo.setActualHandlerUserName(handlerUser.getNickName()); |
| | | } |
| | | } |
| | | vo.setTaskDefinitionKey(hisTaskList.get(0).getTaskDefinitionKey()); |
| | | this.setHandler(vo, hisTaskList.get(0).getIdentityLinks()); |
| | | } |
| | | vo.setTaskDefinitionKey(hisTaskList.get(0).getTaskDefinitionKey()); |
| | | this.setPromoterAndHandler(vo, hisTaskList.get(0).getIdentityLinks()); |
| | | |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | }).filter(Objects::nonNull).collect(Collectors.toList()); |
| | | return vos; |
| | | } |
| | | |
| | |
| | | taskVO.getHandlerUnitId().add(sysUser.getDept().getDeptId()); |
| | | taskVO.getHandlerUnitName().add(sysUser.getDept().getDeptName()); |
| | | taskVO.getPromoterName().add(this.getUserShowName(sysUser)); |
| | | taskVO.getPromoterUnitName().add(sysUser.getDept().getDeptName()); |
| | | // if (sysUser.getDept().getAncestors()) |
| | | String[] str = sysUser.getDept().getAncestors().split(","); |
| | | if (str.length >= 4){ |
| | | taskVO.getPromoterUnitName().add(sysUser.getDept().getParentName() +"-"+sysUser.getDept().getDeptName()); |
| | | }else { |
| | | taskVO.getPromoterUnitName().add(sysUser.getDept().getDeptName()); |
| | | } |
| | | |
| | | } |
| | | } |
| | | // 绑定的是角色或者部门 |
| | |
| | | taskVO.getHandlerUnitId().add(dept.getDeptId()); |
| | | taskVO.getHandlerUnitName().add(dept.getDeptName()); |
| | | taskVO.getPromoterName().add(this.getDeptLeaderShowName(dept)); |
| | | taskVO.getPromoterUnitName().add(dept.getDeptName()); |
| | | taskVO.getPromoterUnitName().add(this.setDeptNameWithParentName(dept)); |
| | | } |
| | | } |
| | | } else { |
| | |
| | | vo.setCreateTime(hisTask.getStartTime()); |
| | | |
| | | // 查询实际处理人 |
| | | long handlerUserId = Long.parseLong(hisTask.getAssignee()); |
| | | SysUser handlerUser = sysUserService.selectUserById(handlerUserId); |
| | | if (Objects.nonNull(handlerUser)) { |
| | | vo.getHandlerId().add(handlerUserId); |
| | | vo.getHandlerName().add(this.getUserShowName(handlerUser)); |
| | | if (StringUtils.isNotBlank(hisTask.getAssignee())) { |
| | | long handlerUserId = Long.parseLong(hisTask.getAssignee()); |
| | | SysUser handlerUser = sysUserService.selectUserById(handlerUserId); |
| | | if (Objects.nonNull(handlerUser)) { |
| | | vo.getHandlerId().add(handlerUserId); |
| | | vo.getHandlerName().add(this.getUserShowName(handlerUser)); |
| | | if (Objects.nonNull(handlerUser.getDept())) { |
| | | vo.getHandlerUnitId().add(handlerUser.getDept().getDeptId()); |
| | | vo.getHandlerUnitName().add(handlerUser.getDept().getDeptName()); |
| | | } |
| | | } |
| | | } |
| | | vo.setTaskDefinitionKey(hisTask.getTaskDefinitionKey()); |
| | | this.setPromoterAndHandler(vo, hisTask.getIdentityLinks()); |
| | | } |
| | | |
| | | this.distinctVo(vo); |
| | |
| | | return Long.valueOf(tList.size()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 查询即将超时的任务 |
| | | * |
| | |
| | | Task task = keyMap.get(userTask.getId()); |
| | | CustomerTaskVO vo = new CustomerTaskVO(); |
| | | this.setRuntimeTaskInfo(task, vo, projectId); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | result.data(vos); |
| | | 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 processInsId |
| | | * @return |
| | | */ |
| | | private Long getJumpTaskNum(String processInsId) { |
| | | // 查出跳过的任务 |
| | | List<ProcessLog> allJumpTaskList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.JUMP) |
| | | .orderByDesc(ProcessLog::getGmtCreate) |
| | | .list(); |
| | | List<String> jumpTaskIds = allJumpTaskList.stream().map(ProcessLog::getTaskId).collect(Collectors.toList()); |
| | | List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(processInsId) |
| | | .taskIds(jumpTaskIds) |
| | | .includeIdentityLinks() |
| | | .orderByHistoricTaskInstanceStartTime() |
| | | .desc() |
| | | .list(); |
| | | hisTaskList = this.distinctHisTask(hisTaskList); |
| | | return Long.valueOf(hisTaskList.size()); |
| | | } |
| | | |
| | | /** |
| | | * 获取跳过任务 |
| | | * |
| | | * @param projectId |
| | | * @param processDefinitionId |
| | | * @param processInsId |
| | | * @param taskName |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @param result |
| | | * @return |
| | | */ |
| | | private List<CustomerTaskVO> getJumpTask(String projectId, |
| | | String processDefinitionId, |
| | | String processInsId, |
| | | String taskName, |
| | | Integer pageNum, |
| | | Integer pageSize, |
| | | Result result) { |
| | | // 查出跳过的任务 |
| | | List<ProcessLog> allJumpTaskList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.JUMP) |
| | | .like(StringUtils.isNotBlank(taskName), ProcessLog::getTaskName, taskName) |
| | | .orderByDesc(ProcessLog::getGmtCreate) |
| | | .list(); |
| | | List<String> jumpTaskIds = allJumpTaskList.stream().map(ProcessLog::getTaskId).collect(Collectors.toList()); |
| | | List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(processInsId) |
| | | .taskIds(jumpTaskIds) |
| | | .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> targetTaskList = hisTaskList.subList(startNum, end); |
| | | |
| | | // 转换成VO |
| | | // 得到目标任务对应的定义 |
| | | List<String> taskDefs = targetTaskList.stream().map(HistoricTaskInstance::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | Map<String, HistoricTaskInstance> keyMap = targetTaskList.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.JUMP); |
| | | // 如果是已完成的,信息需要单独赋值 |
| | | vo.setTaskId(hisTask.getId()); |
| | | vo.setExecutionId(hisTask.getExecutionId()); |
| | | vo.setCreateTime(hisTask.getStartTime()); |
| | | |
| | | // 查询实际处理人 |
| | | if (StringUtils.isNotBlank(hisTask.getAssignee())) { |
| | | long handlerUserId = Long.parseLong(hisTask.getAssignee()); |
| | | SysUser handlerUser = sysUserService.selectUserById(handlerUserId); |
| | | if (Objects.nonNull(handlerUser)) { |
| | | vo.getHandlerId().add(handlerUserId); |
| | | vo.getHandlerName().add(this.getUserShowName(handlerUser)); |
| | | if (Objects.nonNull(handlerUser.getDept())) { |
| | | vo.getHandlerUnitId().add(handlerUser.getDept().getDeptId()); |
| | | vo.getHandlerUnitName().add(handlerUser.getDept().getDeptName()); |
| | | } |
| | | } |
| | | } |
| | | this.setHandler(vo, hisTask.getIdentityLinks()); |
| | | vo.setTaskDefinitionKey(hisTask.getTaskDefinitionKey()); |
| | | } |
| | | this.distinctVo(vo); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | result.data(vos); |
| | | return 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, |
| | | 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()); |
| | | |
| | | // 查询实际处理人 |
| | | if (StringUtils.isNotBlank(hisTask.getAssignee())) { |
| | | 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); |
| | |
| | | */ |
| | | 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())) { |
| | |
| | | // 部门 |
| | | SysDept dept = sysDeptService.selectDeptById(Long.parseLong(split[1])); |
| | | if (Objects.nonNull(dept)) { |
| | | vo.getPromoterUnitName().add(dept.getDeptName()); |
| | | vo.getPromoterUnitName().add(this.setDeptNameWithParentName(dept)); |
| | | vo.getPromoterName().add(this.getDeptLeaderShowName(dept)); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置部门名称时带上上级部门名称 |
| | | * @param dept |
| | | */ |
| | | private String setDeptNameWithParentName(SysDept dept) { |
| | | String[] str = dept.getAncestors().split(","); |
| | | if (str.length >= 4){ |
| | | return dept.getParentName() + " / " + dept.getDeptName(); |
| | | }else { |
| | | return dept.getDeptName(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置任务的发起人&处理人 只有待办任务和已完成任务才会掉这个方法 |
| | | * |
| | | * @param taskVO |
| | | * @param identityLinkInfos 如果是已完成的任务,用这个去取关联的用户/用户组 |
| | | */ |
| | | private void setPromoterAndHandler(CustomerTaskVO taskVO, List<? extends IdentityLinkInfo> identityLinkInfos) { |
| | | // this.setPromoterInfo(taskVO); |
| | | |
| | | // 一个任务可能有多个候选人/组,所以需要使用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); |
| | | taskVO.setHandlerId(handlerIds); |
| | | taskVO.setHandlerName(handlerNames); |
| | | taskVO.setHandlerUnitId(handlerUnitIds); |
| | | taskVO.setHandlerUnitName(handlerUnitNames); |
| | | private void setHandler(CustomerTaskVO taskVO, List<? extends IdentityLinkInfo> identityLinkInfos) { |
| | | |
| | | // 流程处理人信息 |
| | | if (TaskStatusEnum.TODO.equals(taskVO.getTaskStatus())) { |
| | |
| | | SysUser sysUser = sysUserService.selectUserById(Long.parseLong(identityLink.getUserId())); |
| | | if (Objects.nonNull(sysUser)) { |
| | | taskVO.setHandlerType(HandlerTypeEnum.USER); |
| | | handlerIds.add(sysUser.getUserId()); |
| | | handlerNames.add(this.getUserShowName(sysUser)); |
| | | taskVO.getHandlerId().add(sysUser.getUserId()); |
| | | taskVO.getHandlerName().add(this.getUserShowName(sysUser)); |
| | | if (Objects.nonNull(sysUser.getDept())) { |
| | | handlerUnitIds.add(sysUser.getDept().getDeptId()); |
| | | handlerUnitNames.add(sysUser.getDept().getDeptName()); |
| | | taskVO.getHandlerUnitId().add(sysUser.getDept().getDeptId()); |
| | | taskVO.getHandlerUnitName().add(sysUser.getDept().getDeptName()); |
| | | } |
| | | } |
| | | // 绑定的是角色或者是部门,需要根据id判断 |
| | |
| | | // 部门 |
| | | SysDept dept = sysDeptService.selectDeptById(Long.parseLong(split[1])); |
| | | if (Objects.nonNull(dept)) { |
| | | handlerUnitIds.add(dept.getDeptId()); |
| | | handlerUnitNames.add(dept.getDeptName()); |
| | | taskVO.getHandlerUnitId().add(dept.getDeptId()); |
| | | taskVO.getHandlerUnitName().add(dept.getDeptName()); |
| | | } |
| | | } |
| | | } else { |
| | | taskVO.setHandlerType(HandlerTypeEnum.ROLE); |
| | | SysRole role = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId())); |
| | | if (Objects.nonNull(role)) { |
| | | handlerUnitIds.add(role.getRoleId()); |
| | | handlerUnitNames.add(role.getRoleName()); |
| | | taskVO.getHandlerUnitId().add(role.getRoleId()); |
| | | taskVO.getHandlerUnitName().add(role.getRoleName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } 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())) { |
| | | taskVO.setHandlerType(HandlerTypeEnum.USER); |
| | | SysUser sysUser = sysUserService.selectUserById(Long.parseLong(identityLink.getUserId())); |
| | | if (Objects.nonNull(sysUser)) { |
| | | handlerIds.add(sysUser.getUserId()); |
| | | handlerNames.add(this.getUserShowName(sysUser)); |
| | | taskVO.getHandlerId().add(sysUser.getUserId()); |
| | | taskVO.getHandlerName().add(this.getUserShowName(sysUser)); |
| | | if (Objects.nonNull(sysUser.getDept())) { |
| | | handlerUnitIds.add(sysUser.getDept().getDeptId()); |
| | | handlerUnitNames.add(sysUser.getDept().getDeptName()); |
| | | taskVO.getHandlerUnitId().add(sysUser.getDept().getDeptId()); |
| | | taskVO.getHandlerUnitName().add(sysUser.getDept().getDeptName()); |
| | | } |
| | | } |
| | | // 绑定的是角色,查出角色名称 |
| | |
| | | // 部门 |
| | | SysDept dept = sysDeptService.selectDeptById(Long.parseLong(split[1])); |
| | | if (Objects.nonNull(dept)) { |
| | | handlerUnitIds.add(dept.getDeptId()); |
| | | handlerUnitNames.add(dept.getDeptName()); |
| | | taskVO.getHandlerUnitId().add(dept.getDeptId()); |
| | | taskVO.getHandlerUnitName().add(dept.getDeptName()); |
| | | } |
| | | } |
| | | } else { |
| | | taskVO.setHandlerType(HandlerTypeEnum.ROLE); |
| | | SysRole role = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId())); |
| | | if (Objects.nonNull(role)) { |
| | | handlerUnitIds.add(role.getRoleId()); |
| | | handlerUnitNames.add(role.getRoleName()); |
| | | taskVO.getHandlerUnitId().add(role.getRoleId()); |
| | | taskVO.getHandlerUnitName().add(role.getRoleName()); |
| | | } |
| | | } |
| | | } |