| | |
| | | package com.ycl.service.impl; |
| | | |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | 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.common.constant.ProcessConstants; |
| | | import com.ycl.common.core.domain.AjaxResult; |
| | | import com.ycl.common.constant.ProcessOverTimeConstants; |
| | | import com.ycl.common.core.domain.entity.SysDept; |
| | | import com.ycl.common.core.domain.entity.SysRole; |
| | | import com.ycl.common.core.domain.entity.SysUser; |
| | | import com.ycl.common.enums.FlowComment; |
| | | import com.ycl.common.enums.business.FlowLogEventTypeEnum; |
| | | import com.ycl.common.enums.business.HandlerTypeEnum; |
| | | import com.ycl.common.enums.business.ProcessLogEventTypeEnum; |
| | | import com.ycl.common.enums.business.TaskStatusEnum; |
| | | import com.ycl.common.utils.SecurityUtils; |
| | | import com.ycl.constant.TaskTypeConstant; |
| | | import com.ycl.domain.dto.FlowTaskDto; |
| | | import com.ycl.domain.entity.FlowLog; |
| | | import com.ycl.domain.entity.ProcessCoding; |
| | | import com.ycl.domain.entity.ProjectInfo; |
| | | import com.ycl.domain.entity.ProjectProcess; |
| | | import com.ycl.domain.form.RejectTaskForm; |
| | | import com.ycl.domain.entity.SysForm; |
| | | import com.ycl.domain.form.TaskDelegationForm; |
| | | import com.ycl.domain.json.TaskDelegateData; |
| | | import com.ycl.domain.form.TaskJumpForm; |
| | | import com.ycl.domain.json.DelegateData; |
| | | import com.ycl.domain.vo.CustomerTaskVO; |
| | | import com.ycl.domain.vo.IndexCustomerTaskVO; |
| | | import com.ycl.domain.vo.ProjectProcessDetailVO; |
| | | import com.ycl.event.event.TaskLogEvent; |
| | | import com.ycl.mapper.ProjectInfoMapper; |
| | | import com.ycl.mapper.ProjectProcessMapper; |
| | | import com.ycl.service.FlowLogService; |
| | | import com.ycl.service.IFlowTaskService; |
| | | import com.ycl.service.ISysFormService; |
| | | import com.ycl.service.ProcessCodingService; |
| | | import com.ycl.service.ProjectProcessService; |
| | | import com.ycl.common.base.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.flowable.identitylink.api.IdentityLink; |
| | | import org.flowable.identitylink.api.IdentityLinkInfo; |
| | | import org.flowable.identitylink.api.IdentityLinkType; |
| | | import org.flowable.identitylink.api.history.HistoricIdentityLink; |
| | | import org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntityImpl; |
| | | 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; |
| | | import com.ycl.framework.utils.PageUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.*; |
| | |
| | | private final ISysRoleService sysRoleService; |
| | | private final ISysDeptService sysDeptService; |
| | | private final TaskCommonService taskCommonService; |
| | | private final FlowLogService flowLogService; |
| | | private final IFlowTaskService flowTaskService; |
| | | private final ISysFormService formService; |
| | | private final ProcessCodingService processCodingService; |
| | | private final ApplicationEventPublisher publisher; |
| | | |
| | | /** |
| | | * 分页查询 |
| | |
| | | @Override |
| | | public Result page(ProjectProcessQuery query) { |
| | | IPage<ProjectProcessVO> page = PageUtil.getPage(query, ProjectProcessVO.class); |
| | | baseMapper.getPage(page, query); |
| | | baseMapper.getPage(query, page); |
| | | for (ProjectProcessVO vo : page.getRecords()) { |
| | | if (Objects.nonNull(vo.getProcessDefId())) { |
| | | ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(vo.getProcessDefId()).singleResult(); |
| | | if (Objects.nonNull(processDefinition)) { |
| | | vo.setSuspended(processDefinition.isSuspended()); |
| | | vo.setFlowableProcessName(processDefinition.getName() + "(v" + processDefinition.getVersion() + ")"); |
| | | vo.setDeployId(processDefinition.getDeploymentId()); |
| | | } |
| | | } |
| | | } |
| | |
| | | taskStatistics.setTotalTaskNum(this.getTotalTaskNum(processDefId)); |
| | | taskStatistics.setTodoTaskNum(this.getTodoTaskNum(projectProcess.getProcessInsId())); |
| | | taskStatistics.setRemainingTaskNum(this.getRemainingTaskNum(processDefId, projectProcess.getProcessInsId(), taskStatistics.getTotalTaskNum())); |
| | | taskStatistics.setTimelyFinishedTaskNum(this.getTimelyTaskNum(projectProcess.getProcessInsId())); |
| | | taskStatistics.setOvertimeTaskNum(this.getOvertimeTaskNum(projectProcess.getProcessInsId())); |
| | | taskStatistics.setWillOvertimeTaskNum(this.getWillOvertimeTaskNum(projectProcess.getProcessInsId())); |
| | | // taskStatistics.setCurrentTask(this.getCurrentNodeTaskList(projectProcess.getProcessInstanceId())); |
| | | detail.setStatistics(taskStatistics); |
| | | |
| | |
| | | case TaskTypeConstant.REMAINING: |
| | | this.getRemainingTask(query.getProcessDefId(), projectProcess.getProcessInsId(), query.getTaskName(), (int) query.getCurrentPage(), (int) query.getPageSize(), ok); |
| | | break; |
| | | case TaskTypeConstant.TIMELY: |
| | | this.getTimelyTask(query.getProcessDefId(), projectProcess.getProcessInsId(), query.getTaskName(), (int) query.getCurrentPage(), (int) query.getPageSize(), ok); |
| | | break; |
| | | case TaskTypeConstant.OVERTIME: |
| | | this.getOvertimeTask(query.getProcessDefId(), projectProcess.getProcessInsId(), query.getTaskName(), (int) query.getCurrentPage(), (int) query.getPageSize(), ok); |
| | | break; |
| | | case TaskTypeConstant.WILL_OVER_TIME: |
| | | this.getWillOvertimeTask(query.getProcessDefId(), projectProcess.getProcessInsId(), query.getTaskName(), (int) query.getCurrentPage(), (int) query.getPageSize(), ok); |
| | | break; |
| | | default: |
| | | break; |
| | | |
| | |
| | | |
| | | if (StringUtils.isNotBlank(taskName)) { |
| | | taskQuery.processDefinitionNameLike(taskName); |
| | | } |
| | | if (! SecurityUtils.getLoginUser().getUser().isAdmin()) { |
| | | taskQuery |
| | | .or() |
| | | .taskCandidateGroupIn(taskCommonService.getCurrentUserGroups()) |
| | | .taskCandidateUser(SecurityUtils.getUserId() + "") |
| | | .taskAssignee(SecurityUtils.getUserId() + "") |
| | | .endOr(); |
| | | } |
| | | result.total(taskQuery.count()); |
| | | List<Task> taskList = taskQuery.listPage(pageSize * (pageNum - 1), pageSize); |
| | |
| | | if (Objects.nonNull(project)) { |
| | | taskVO.setProjectId(project.getId()); |
| | | taskVO.setProjectName(project.getProjectName()); |
| | | } else { |
| | | continue; |
| | | } |
| | | |
| | | // 流程发起人信息 |
| | |
| | | |
| | | // 流程处理人信息 |
| | | List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId()); |
| | | // Boolean aboutMe = taskCommonService.taskAboutMe(identityLinks); |
| | | // if (! aboutMe) { |
| | | // continue; |
| | | // } |
| | | for (IdentityLinkInfo identityLink : identityLinks) { |
| | | // 绑定的是用户,查出用户姓名、部门 |
| | | if (StringUtils.isNotBlank(identityLink.getUserId())) { |
| | |
| | | taskVO.setHandlerUnitId(handlerUnitIds); |
| | | taskVO.setHandlerUnitName(handlerUnitNames); |
| | | vos.add(taskVO); |
| | | } |
| | | if (vos.size() < pageSize) { |
| | | result.total(vos.size()); |
| | | } |
| | | result.put("taskList", vos); |
| | | } |
| | |
| | | for (FlowElement flowElement : flowElements) { |
| | | if (flowElement instanceof UserTask && flowElement.getId().equals(task.getTaskDefinitionKey())) { |
| | | UserTask userTask = (UserTask) flowElement; |
| | | needAuditing = taskCommonService.checkTaskNeedAuditing(userTask.getExtensionElements().get("properties")); |
| | | needAuditing = taskCommonService.checkHasExeProperty(userTask.getExtensionElements().get("properties"), ProcessConstants.EXTENSION_PROPERTY_NEED_AUDITING_TEXT); |
| | | break; |
| | | } |
| | | |
| | |
| | | taskService.deleteCandidateGroup(task.getId(), identityLink.getGroupId()); |
| | | } |
| | | } |
| | | TaskDelegateData jsonData = new TaskDelegateData(); |
| | | DelegateData jsonData = new DelegateData(); |
| | | jsonData.setBeforeHandlerIds(beforeHandlerIds); |
| | | jsonData.setBeforeHandlerType(beforeHandlerType); |
| | | |
| | |
| | | } |
| | | jsonData.setAfterHandlerIds(afterHandlerIds); |
| | | jsonData.setAfterHandlerType(form.getPeopleType()); |
| | | // 添加日志 |
| | | flowLogService.add(task.getId(), task.getProcessInstanceId(), FlowLogEventTypeEnum.DELEGATE, form.getProjectId(), JSON.toJSONString(jsonData)); |
| | | // 发布转办事件 |
| | | publisher.publishEvent(new TaskLogEvent(this, form.getProjectId(), form.getProcessInsId(), task.getId(), ProcessLogEventTypeEnum.DELEGATE, jsonData)); |
| | | |
| | | return Result.ok("转办成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result taskJump(TaskJumpForm form) { |
| | | Task task = taskService.createTaskQuery().taskId(form.getTaskId()).processInstanceId(form.getProcessInsId()).singleResult(); |
| | | if (Objects.nonNull(task)) { |
| | | // 添加跳过日志 |
| | | publisher.publishEvent(new TaskLogEvent(this, form.getProjectId(), form.getProcessInsId(), form.getTaskId(), ProcessLogEventTypeEnum.JUMP, null)); |
| | | // 查出该任务绑定的表单 |
| | | |
| | | 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); |
| | | } |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | /** |
| | |
| | | // 未开始的任务,其关联的用户组这些都可以从UserTask中拿到,因为本身未开始的任务是没有task的,所以这里直接查 |
| | | if (StringUtils.isNotBlank(userTask.getAssignee())) { |
| | | vo.setHandlerType(HandlerTypeEnum.USER); |
| | | SysUser sysUser = sysUserService.selectUserById(Long.parseLong(userTask.getAssignee())); |
| | | if (Objects.nonNull(sysUser)) { |
| | | handlerIds.add(sysUser.getUserId()); |
| | | handlerNames.add(sysUser.getNickName()); |
| | | if (Objects.nonNull(sysUser.getDept())) { |
| | | handlerUnitIds.add(sysUser.getDept().getDeptId()); |
| | | handlerUnitNames.add(sysUser.getDept().getDeptName()); |
| | | // 处理变量表达式 |
| | | if (userTask.getAssignee().contains(ProcessConstants.DATA_LAUNCH)) { |
| | | handlerNames.add(userTask.getAssignee()); |
| | | } else { |
| | | SysUser sysUser = sysUserService.selectUserById(Long.parseLong(userTask.getAssignee())); |
| | | if (Objects.nonNull(sysUser)) { |
| | | handlerIds.add(sysUser.getUserId()); |
| | | handlerNames.add(sysUser.getNickName()); |
| | | if (Objects.nonNull(sysUser.getDept())) { |
| | | handlerUnitIds.add(sysUser.getDept().getDeptId()); |
| | | handlerUnitNames.add(sysUser.getDept().getDeptName()); |
| | | } |
| | | } |
| | | } |
| | | } else if (CollectionUtil.isNotEmpty(userTask.getCandidateGroups())) { |
| | |
| | | taskVO.setTaskName(task.getName()); |
| | | taskVO.setTaskStatus(TaskStatusEnum.TODO); |
| | | // 流程定义信息 |
| | | ProcessDefinition pd = repositoryService.createProcessDefinitionQuery() |
| | | .processDefinitionId(task.getProcessDefinitionId()) |
| | | .singleResult(); |
| | | taskVO.setDeployId(pd.getDeploymentId()); |
| | | taskVO.setProcessName(pd.getName()); |
| | | ProcessInstance process = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); |
| | | String deployId = ""; |
| | | String processName = ""; |
| | | if (Objects.nonNull(process)) { |
| | | deployId = process.getDeploymentId(); |
| | | processName = process.getProcessDefinitionName(); |
| | | } else { |
| | | HistoricProcessInstance hisProcess = historyService.createHistoricProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); |
| | | deployId = hisProcess.getDeploymentId(); |
| | | processName = hisProcess.getProcessDefinitionName(); |
| | | } |
| | | taskVO.setDeployId(deployId); |
| | | taskVO.setProcessName(processName); |
| | | taskVO.setProcessInsId(task.getProcessInstanceId()); |
| | | taskVO.setTaskDefinitionKey(task.getTaskDefinitionKey()); |
| | | |
| | |
| | | taskVO.setHandlerUnitId(handlerUnitIds); |
| | | taskVO.setHandlerUnitName(handlerUnitNames); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 统计按时完成的任务 |
| | | * |
| | | * @param processInsId 流程实例id |
| | | * @return |
| | | */ |
| | | private Long getTimelyTaskNum(String processInsId) { |
| | | // 查出时间正常的任务id |
| | | List<String> taskKeyList = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | .select(ProcessCoding::getTaskDefKey) |
| | | .eq(ProcessCoding::getProcessInsId, processInsId) |
| | | .eq(ProcessCoding::getOvertimeStatus, ProcessOverTimeConstants.NORMAL) |
| | | .list() |
| | | .stream() |
| | | .map(ProcessCoding::getTaskDefKey) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(taskKeyList)) { |
| | | return 0L; |
| | | } |
| | | // 查出所有已完成的任务 |
| | | return historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(processInsId) |
| | | .finished() |
| | | .caseDefinitionKeyIn(taskKeyList) |
| | | .count(); |
| | | } |
| | | |
| | | /** |
| | | * 查询按时完成的任务 |
| | | * |
| | | * @param processDefinitionId 流程定义id |
| | | * @param processInsId 流程实例id |
| | | * @param taskName 任务名称--搜索条件 |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @param result |
| | | * @return |
| | | */ |
| | | private List<CustomerTaskVO> getTimelyTask(String processDefinitionId, String processInsId, String taskName, Integer pageNum, Integer pageSize, Result result) { |
| | | int startNum = pageSize * (pageNum - 1); |
| | | int endNum = startNum + pageSize; |
| | | |
| | | // 查出时间正常的任务id |
| | | List<String> taskKeyList = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | .select(ProcessCoding::getTaskDefKey) |
| | | .eq(ProcessCoding::getProcessInsId, processInsId) |
| | | .eq(ProcessCoding::getOvertimeStatus, ProcessOverTimeConstants.NORMAL) |
| | | .list() |
| | | .stream() |
| | | .map(ProcessCoding::getTaskDefKey) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<HistoricTaskInstance> finishedTaskList = new ArrayList<>(); |
| | | if (! CollectionUtils.isEmpty(taskKeyList)) { |
| | | // 查出所有已完成的任务 |
| | | finishedTaskList = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(processInsId) |
| | | .finished() |
| | | .taskNameLike(taskName) |
| | | .caseDefinitionKeyIn(taskKeyList) |
| | | .includeIdentityLinks() |
| | | .list(); |
| | | } |
| | | |
| | | if (startNum >= finishedTaskList.size()) { |
| | | // 如果起始索引超出了列表的大小,返回一个空列表 |
| | | return new ArrayList<>(); |
| | | } |
| | | result.total(finishedTaskList.size()); |
| | | int end = Math.min(endNum, finishedTaskList.size()); |
| | | List<HistoricTaskInstance> pageFinishedTaskList = finishedTaskList.subList(startNum, end); |
| | | List<String> taskDefs = pageFinishedTaskList.stream().map(HistoricTaskInstance::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | Map<String, HistoricTaskInstance> keyMap = pageFinishedTaskList.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); |
| | | |
| | | HistoricTaskInstance hisTask = keyMap.get(userTask.getId()); |
| | | if (Objects.nonNull(hisTask)) { |
| | | vo.setTaskStatus(TaskStatusEnum.FINISHED); |
| | | // 如果是已完成的,信息需要单独赋值 |
| | | 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)) { |
| | | handlerIds.add(handlerUserId); |
| | | handlerNames.add(handlerUser.getNickName()); |
| | | vo.setActualHandlerUserId(hisTask.getAssignee()); |
| | | vo.setActualHandlerUserName(handlerUser.getNickName()); |
| | | } |
| | | vo.setTaskDefinitionKey(hisTask.getTaskDefinitionKey()); |
| | | this.setPromoterAndHandler(vo, hisTask.getIdentityLinks()); |
| | | } |
| | | vo.setHandlerId(handlerIds); |
| | | vo.setHandlerName(handlerNames); |
| | | vo.setHandlerUnitId(handlerUnitIds); |
| | | vo.setHandlerUnitName(handlerUnitNames); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | result.data(vos); |
| | | return vos; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 统计超时的任务数 |
| | | * |
| | | * @param processInsId 流程实例id |
| | | * @return |
| | | */ |
| | | private Long getOvertimeTaskNum(String processInsId) { |
| | | // 查出时间正常的任务id |
| | | List<String> taskKeyList = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | .select(ProcessCoding::getTaskDefKey) |
| | | .eq(ProcessCoding::getProcessInsId, processInsId) |
| | | .eq(ProcessCoding::getOvertimeStatus, ProcessOverTimeConstants.OVERTIME) |
| | | .list() |
| | | .stream() |
| | | .map(ProcessCoding::getTaskDefKey) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(taskKeyList)) { |
| | | return 0L; |
| | | } |
| | | // 查出所有已完成的任务 |
| | | return taskService.createTaskQuery() |
| | | .processInstanceId(processInsId) |
| | | .caseDefinitionKeyIn(taskKeyList) |
| | | .count(); |
| | | } |
| | | |
| | | /** |
| | | * 查询超时的任务 |
| | | * |
| | | * @param processDefinitionId 流程定义id |
| | | * @param processInsId 流程实例id |
| | | * @param taskName 任务名称--搜索条件 |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @param result |
| | | * @return |
| | | */ |
| | | private List<CustomerTaskVO> getOvertimeTask(String processDefinitionId, String processInsId, String taskName, Integer pageNum, Integer pageSize, Result result) { |
| | | int startNum = pageSize * (pageNum - 1); |
| | | int endNum = startNum + pageSize; |
| | | |
| | | // 查出即将超时的任务 |
| | | List<String> taskKeyList = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | .select(ProcessCoding::getTaskDefKey) |
| | | .eq(ProcessCoding::getProcessInsId, processInsId) |
| | | .eq(ProcessCoding::getOvertimeStatus, ProcessOverTimeConstants.OVERTIME) |
| | | .list() |
| | | .stream() |
| | | .map(ProcessCoding::getTaskDefKey) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<Task> taskList = new ArrayList<>(); |
| | | // 查出所有正在处理(运行时)的任务 |
| | | if (! CollectionUtils.isEmpty(taskKeyList)) { |
| | | taskList = taskService.createTaskQuery() |
| | | .processInstanceId(processInsId) |
| | | .taskNameLike(taskName) |
| | | .caseDefinitionKeyIn(taskKeyList) |
| | | .list(); |
| | | } |
| | | |
| | | if (startNum >= taskList.size()) { |
| | | // 如果起始索引超出了列表的大小,返回一个空列表 |
| | | return new ArrayList<>(); |
| | | } |
| | | result.total(taskList.size()); |
| | | int end = Math.min(endNum, taskList.size()); |
| | | List<Task> pageTaskList = taskList.subList(startNum, end); |
| | | List<String> taskDefs = pageTaskList.stream().map(Task::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | Map<String, Task> keyMap = pageTaskList.stream().collect(Collectors.toMap(Task::getTaskDefinitionKey, his -> his)); |
| | | |
| | | // 得到目标任务对应的定义 |
| | | List<UserTask> finishedUserTaskElement = this.getAllUserTaskElement(processDefinitionId).stream().filter(el -> taskDefs.contains(el.getId())).collect(Collectors.toList()); |
| | | |
| | | // 查询任务相关信息 |
| | | List<CustomerTaskVO> vos = finishedUserTaskElement.stream().map(userTask -> { |
| | | Task task = keyMap.get(userTask.getId()); |
| | | CustomerTaskVO vo = new CustomerTaskVO(); |
| | | this.setRuntimeTaskInfo(task, vo); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | result.data(vos); |
| | | return vos; |
| | | } |
| | | |
| | | /** |
| | | * 统计即将超时的任务数 |
| | | * |
| | | * @param processInsId 流程实例id |
| | | * @return |
| | | */ |
| | | private Long getWillOvertimeTaskNum(String processInsId) { |
| | | // 查出时间正常的任务id |
| | | List<String> taskKeyList = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | .select(ProcessCoding::getTaskDefKey) |
| | | .eq(ProcessCoding::getProcessInsId, processInsId) |
| | | .eq(ProcessCoding::getOvertimeStatus, ProcessOverTimeConstants.WILLOVERTIME) |
| | | .list() |
| | | .stream() |
| | | .map(ProcessCoding::getTaskDefKey) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(taskKeyList)) { |
| | | return 0L; |
| | | } |
| | | // 查出所有已完成的任务 |
| | | return taskService.createTaskQuery() |
| | | .processInstanceId(processInsId) |
| | | .caseDefinitionKeyIn(taskKeyList) |
| | | .count(); |
| | | } |
| | | |
| | | /** |
| | | * 查询即将超时的任务 |
| | | * |
| | | * @param processDefinitionId 流程定义id |
| | | * @param processInsId 流程实例id |
| | | * @param taskName 任务名称--搜索条件 |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @param result |
| | | * @return |
| | | */ |
| | | private List<CustomerTaskVO> getWillOvertimeTask(String processDefinitionId, String processInsId, String taskName, Integer pageNum, Integer pageSize, Result result) { |
| | | int startNum = pageSize * (pageNum - 1); |
| | | int endNum = startNum + pageSize; |
| | | |
| | | // 查出即将超时的任务 |
| | | List<String> taskKeyList = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | .select(ProcessCoding::getTaskDefKey) |
| | | .eq(ProcessCoding::getProcessInsId, processInsId) |
| | | .eq(ProcessCoding::getOvertimeStatus, ProcessOverTimeConstants.WILLOVERTIME) |
| | | .list() |
| | | .stream() |
| | | .map(ProcessCoding::getTaskDefKey) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<Task> taskList = new ArrayList<>(); |
| | | // 查出所有正在处理(运行时)的任务 |
| | | if (! CollectionUtils.isEmpty(taskKeyList)) { |
| | | taskList = taskService.createTaskQuery() |
| | | .processInstanceId(processInsId) |
| | | .taskNameLike(taskName) |
| | | .caseDefinitionKeyIn(taskKeyList) |
| | | .list(); |
| | | } |
| | | |
| | | if (startNum >= taskList.size()) { |
| | | // 如果起始索引超出了列表的大小,返回一个空列表 |
| | | return new ArrayList<>(); |
| | | } |
| | | result.total(taskList.size()); |
| | | int end = Math.min(endNum, taskList.size()); |
| | | List<Task> pageTaskList = taskList.subList(startNum, end); |
| | | List<String> taskDefs = pageTaskList.stream().map(Task::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | Map<String, Task> keyMap = pageTaskList.stream().collect(Collectors.toMap(Task::getTaskDefinitionKey, his -> his)); |
| | | |
| | | // 得到目标任务对应的定义 |
| | | List<UserTask> finishedUserTaskElement = this.getAllUserTaskElement(processDefinitionId).stream().filter(el -> taskDefs.contains(el.getId())).collect(Collectors.toList()); |
| | | |
| | | // 查询任务相关信息 |
| | | List<CustomerTaskVO> vos = finishedUserTaskElement.stream().map(userTask -> { |
| | | Task task = keyMap.get(userTask.getId()); |
| | | CustomerTaskVO vo = new CustomerTaskVO(); |
| | | this.setRuntimeTaskInfo(task, vo); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | result.data(vos); |
| | | return vos; |
| | | } |
| | | |
| | | /** |
| | |
| | | // 未开始的任务,其关联的用户组这些都可以从UserTask中拿到,因为本身未开始的任务是没有task的,所以这里直接查 |
| | | if (StringUtils.isNotBlank(userTask.getAssignee())) { |
| | | vo.setHandlerType(HandlerTypeEnum.USER); |
| | | // 处理变量表达式 |
| | | if (userTask.getAssignee().contains(ProcessConstants.DATA_LAUNCH)) { |
| | | handlerNames.add(userTask.getAssignee()); |
| | | continue; |
| | | } |
| | | SysUser sysUser = sysUserService.selectUserById(Long.parseLong(userTask.getAssignee())); |
| | | if (Objects.nonNull(sysUser)) { |
| | | handlerIds.add(sysUser.getUserId()); |
| | |
| | | .processInstanceId(process.getProcessInstanceId()) |
| | | .finished() |
| | | .list(); |
| | | long num = list.stream().map(HistoricTaskInstance::getTaskDefinitionId).distinct().count(); |
| | | long num = list.stream().map(HistoricTaskInstance::getTaskDefinitionKey).distinct().count(); |
| | | |
| | | return totalNum - num; |
| | | } |