| | |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.ycl.common.constant.ProcessConstants; |
| | | import com.ycl.common.constant.ProcessOverTimeConstants; |
| | | import com.ycl.common.core.domain.AjaxResult; |
| | | import com.ycl.common.core.domain.entity.SysDept; |
| | | import com.ycl.common.core.domain.entity.SysDictData; |
| | | import com.ycl.common.core.domain.entity.SysRole; |
| | | import com.ycl.common.core.domain.entity.SysUser; |
| | | import com.ycl.common.enums.business.*; |
| | | import com.ycl.common.utils.DateUtils; |
| | | import com.ycl.common.utils.SecurityUtils; |
| | | import com.ycl.constant.TaskTypeConstant; |
| | | import com.ycl.domain.entity.*; |
| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.flowable.bpmn.model.*; |
| | | import org.flowable.bpmn.model.Process; |
| | | import org.flowable.common.engine.impl.persistence.StrongUuidGenerator; |
| | | import org.flowable.common.engine.impl.util.CollectionUtil; |
| | | import org.flowable.engine.*; |
| | | import org.flowable.engine.history.HistoricProcessInstance; |
| | |
| | | import org.flowable.task.api.TaskQuery; |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.flowable.task.api.history.HistoricTaskInstanceQuery; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.context.ApplicationEventPublisher; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | taskStatistics.setTimelyFinishedTaskNum(this.getTimelyTaskNum(projectProcess.getProcessInsId())); |
| | | taskStatistics.setOvertimeTaskNum(this.getOvertimeTaskNum(projectProcess.getProcessInsId())); |
| | | taskStatistics.setWillOvertimeTaskNum(this.getWillOvertimeTaskNum(projectProcess.getProcessInsId())); |
| | | taskStatistics.setToleranceNum(this.getToleranceTask(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(); |
| | |
| | | * @param processInsId |
| | | * @return |
| | | */ |
| | | private Long getToleranceTask(String processInsId){ |
| | | private Long getWaitTaskNum(String processInsId){ |
| | | // 查出容缺过的任务 |
| | | List<ProcessLog> allWaitTaskList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | |
| | | // 排除容缺后又完成的任务 |
| | | List<ProcessLog> finishedTaskList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.FINISHED) |
| | | .in(ProcessLog::getEventType, ProcessLogEventTypeEnum.FINISHED, ProcessLogEventTypeEnum.REJECT) |
| | | .list(); |
| | | List<String> finishedTaskIds = finishedTaskList.stream().map(ProcessLog::getTaskId).distinct().collect(Collectors.toList()); |
| | | // 得到未完成的容缺任务 |
| | |
| | | if (CollectionUtils.isEmpty(waitTaskIds)) { |
| | | return 0L; |
| | | } |
| | | return Long.valueOf(waitTaskIds.size()); |
| | | // 容缺的任务都属于历史任务,只是需要补表单数据 |
| | | List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(processInsId) |
| | | .taskIds(waitTaskIds) |
| | | .includeIdentityLinks() |
| | | .orderByHistoricTaskInstanceStartTime() |
| | | .desc() |
| | | .list(); |
| | | hisTaskList = this.distinctHisTask(hisTaskList); |
| | | // 排除运行时任务 |
| | | List<String> runTaskKeys = taskService.createTaskQuery().processInstanceId(processInsId).list().stream().map(Task::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | hisTaskList = hisTaskList.stream().filter(his -> !runTaskKeys.contains(his.getTaskDefinitionKey())).collect(Collectors.toList()); |
| | | return Long.valueOf(hisTaskList.size()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | break; |
| | | 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); |
| | |
| | | Long overtime = getTime(processCoding.getRedTime()); |
| | | long durationTime = 0l; |
| | | if (Objects.nonNull(processCoding.getStartTaskTime())) { |
| | | durationTime = ((new Date()).getTime() - processCoding.getStartTaskTime().getTime()) / 1000; |
| | | durationTime = DateUtils.getWorkingSed(processCoding.getStartTaskTime(), new Date()); |
| | | } |
| | | if (overtime > durationTime) { |
| | | order.setNum((overtime - durationTime) / 3600); |
| | |
| | | */ |
| | | private Long getTimelyTaskNum(String processInsId) { |
| | | // 查出已完成的任务key |
| | | List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery() |
| | | HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(processInsId) |
| | | .finished() |
| | | .list(); |
| | | hisTaskList = this.distinctHisTask(hisTaskList); |
| | | .includeIdentityLinks() |
| | | .orderByTaskCreateTime() |
| | | .desc(); |
| | | List<HistoricTaskInstance> hisTaskList = query.list(); |
| | | if (CollectionUtils.isEmpty(hisTaskList)) { |
| | | return 0L; |
| | | } |
| | | |
| | | hisTaskList = this.distinctHisTask(hisTaskList); |
| | | // 排除跳过、容缺的任务,因为这两个操作都会完成任务而产生历史任务 |
| | | List<String> jumpAndWaitTaskKeys = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .in(ProcessLog::getEventType, ProcessLogEventTypeEnum.JUMP, ProcessLogEventTypeEnum.WAIT) // TODO 如果运行时任务正好是被驳回的,需要想办法排除调被驳回的任务,不能直接在这加 ProcessLogEventTypeEnum.REJECT |
| | | .list().stream().map(ProcessLog::getTaskDefKey).collect(Collectors.toList()); |
| | | List<String> runtimeTaskKey = taskService.createTaskQuery().processInstanceId(processInsId).list().stream().map(Task::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | jumpAndWaitTaskKeys.addAll(runtimeTaskKey); |
| | | hisTaskList = hisTaskList.stream().filter(hisTask -> jumpAndWaitTaskKeys.indexOf(hisTask.getTaskDefinitionKey()) == -1).collect(Collectors.toList()); |
| | | List<String> hisTaskKeys = hisTaskList.stream().map(HistoricTaskInstance::getTaskDefinitionKey).distinct().collect(Collectors.toList()); |
| | | |
| | | if (CollectionUtils.isEmpty(hisTaskKeys)) { |
| | | return 0L; |
| | | } |
| | | Map<String, HistoricTaskInstance> hisTaskMap = hisTaskList.stream().collect(Collectors.toMap(HistoricTaskInstance::getTaskDefinitionKey, his -> his)); |
| | | // 查出时间正常的任务key |
| | | List<ProcessCoding> codeList = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | |
| | | int endNum = startNum + pageSize; |
| | | |
| | | // 查出已完成的任务key |
| | | List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery() |
| | | HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(processInsId) |
| | | .finished() |
| | | .taskNameLike(taskName) |
| | | .includeIdentityLinks() |
| | | .orderByTaskCreateTime() |
| | | .desc() |
| | | .list(); |
| | | .desc(); |
| | | if (StringUtils.isNotBlank(taskName)) { |
| | | query.taskNameLike(taskName); |
| | | } |
| | | List<HistoricTaskInstance> hisTaskList = query.list(); |
| | | if (CollectionUtils.isEmpty(hisTaskList)) { |
| | | result.total(0); |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | hisTaskList = this.distinctHisTask(hisTaskList); |
| | | // 排除跳过、容缺的任务,因为这两个操作都会完成任务而产生历史任务 |
| | | List<String> jumpAndWaitTaskKeys = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getProjectId, projectId) |
| | | .in(ProcessLog::getEventType, ProcessLogEventTypeEnum.JUMP, ProcessLogEventTypeEnum.WAIT) |
| | | .list().stream().map(ProcessLog::getTaskDefKey).collect(Collectors.toList()); |
| | | List<String> runtimeTaskKey = taskService.createTaskQuery().processInstanceId(processInsId).list().stream().map(Task::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | jumpAndWaitTaskKeys.addAll(runtimeTaskKey); |
| | | hisTaskList = hisTaskList.stream().filter(hisTask -> jumpAndWaitTaskKeys.indexOf(hisTask.getTaskDefinitionKey()) == -1).collect(Collectors.toList()); |
| | | List<String> hisTaskKeys = hisTaskList.stream().map(HistoricTaskInstance::getTaskDefinitionKey).distinct().collect(Collectors.toList()); |
| | | Map<String, HistoricTaskInstance> hisTaskMap = this.distinctHisTask(hisTaskList).stream().collect(Collectors.toMap(HistoricTaskInstance::getTaskDefinitionKey, his -> his)); |
| | | |
| | | if (CollectionUtils.isEmpty(hisTaskKeys)) { |
| | | result.total(0); |
| | | return new ArrayList<>(); |
| | | } |
| | | Map<String, HistoricTaskInstance> hisTaskMap = hisTaskList.stream().collect(Collectors.toMap(HistoricTaskInstance::getTaskDefinitionKey, his -> his)); |
| | | // 查出时间正常的任务key |
| | | List<ProcessCoding> codeList = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | .eq(ProcessCoding::getProcessInsId, processInsId) |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置历史任务信息 |
| | | * |
| | | * @param hisTask |
| | | * @param vo |
| | | * @param projectId |
| | | * @param processInsId |
| | | */ |
| | | private void setHisTaskInfo(HistoricTaskInstance hisTask, CustomerTaskVO vo, String projectId, String processInsId) { |
| | | // 查出流程 |
| | | ProcessInstance process = runtimeService.createProcessInstanceQuery().processInstanceId(processInsId).singleResult(); |
| | | String deployId = ""; |
| | | String processName = ""; |
| | | String processDefinitionId = ""; |
| | | if (Objects.nonNull(process)) { |
| | | deployId = process.getDeploymentId(); |
| | | processName = process.getProcessDefinitionName(); |
| | | processDefinitionId = process.getProcessDefinitionId(); |
| | | } else { |
| | | HistoricProcessInstance hisProcess = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInsId).singleResult(); |
| | | deployId = hisProcess.getDeploymentId(); |
| | | processName = hisProcess.getProcessDefinitionName(); |
| | | processDefinitionId = hisProcess.getProcessDefinitionId(); |
| | | } |
| | | |
| | | vo.setProcessInsId(processInsId); |
| | | vo.setProcessDefId(processDefinitionId); |
| | | vo.setDeployId(deployId); |
| | | vo.setTaskName(hisTask.getName()); |
| | | vo.setProcessName(processName); |
| | | |
| | | // 一个任务可能有多个候选人/组,所以需要使用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); |
| | | List<UserTask> targetUserTasks = this.getAllUserTaskElement(processDefinitionId).stream().filter(userTask -> hisTask.getTaskDefinitionKey().equals(userTask.getId())).collect(Collectors.toList()); |
| | | UserTask userTask = null; |
| | | if (! CollectionUtils.isEmpty(targetUserTasks)) { |
| | | userTask = targetUserTasks.get(0); |
| | | } |
| | | this.setCandidateInfo(userTask, vo, projectId, processInsId); |
| | | |
| | | |
| | | vo.setTaskStatus(TaskStatusEnum.FINISHED); |
| | | // 如果是已完成的,信息需要单独赋值 |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | | vo.setTaskDefinitionKey(hisTask.getTaskDefinitionKey()); |
| | | this.distinctVo(vo); |
| | | } |
| | | |
| | | /** |
| | | * 用户名称后面跟电话号码 |
| | | * |
| | | * @param user |
| | |
| | | * @return |
| | | */ |
| | | private Long getOvertimeTaskNum(String processInsId) { |
| | | // 查出运行在的任务key |
| | | List<Task> taskList = taskService.createTaskQuery().processInstanceId(processInsId).list(); |
| | | |
| | | if (CollectionUtils.isEmpty(taskList)) { |
| | | // 查出已超时的任务id |
| | | List<ProcessCoding> overtimeRecords = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | .eq(ProcessCoding::getProcessInsId, processInsId) |
| | | .eq(ProcessCoding::getOvertimeStatus, ProcessOverTimeConstants.OVERTIME) |
| | | .orderByDesc(ProcessCoding::getGmtCreate) |
| | | .list(); |
| | | if (CollectionUtils.isEmpty(overtimeRecords)) { |
| | | return 0L; |
| | | } |
| | | List<String> taskKeys = taskList.stream().map(Task::getTaskDefinitionKey).distinct().collect(Collectors.toList()); |
| | | Map<String, Task> taskMap = taskList.stream().collect(Collectors.toMap(Task::getTaskDefinitionKey, his -> his)); |
| | | // 查出数据库的任务key |
| | | List<ProcessCoding> codeList = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | .eq(ProcessCoding::getProcessInsId, processInsId) |
| | | .in(ProcessCoding::getTaskDefKey, taskKeys) |
| | | .list(); |
| | | List<Task> tList = new ArrayList<>(); |
| | | // 判断 |
| | | for (String key : taskMap.keySet()) { |
| | | List<ProcessCoding> targetProcessCodings = codeList.stream().filter(code -> key.equals(code.getTaskDefKey())).collect(Collectors.toList()); |
| | | // 如果已完成的任务没从数据库查找出来,说明该任务没配置赋码等时间,直接设置为按时完成 |
| | | if (CollectionUtils.isEmpty(targetProcessCodings)) { |
| | | tList.add(taskMap.get(key)); |
| | | } else { |
| | | // 按照时间降序排列 |
| | | targetProcessCodings.sort(Comparator.comparing(ProcessCoding::getGmtCreate).reversed()); |
| | | ProcessCoding latestProjectProcess = targetProcessCodings.get(0); |
| | | if (Objects.nonNull(latestProjectProcess) && ProcessOverTimeConstants.OVERTIME.equals(latestProjectProcess.getOvertimeStatus())) { |
| | | tList.add(taskMap.get(key)); |
| | | } |
| | | } |
| | | } |
| | | return Long.valueOf(taskList.size()); |
| | | return Long.valueOf(overtimeRecords.size()); |
| | | } |
| | | |
| | | /** |
| | |
| | | int startNum = pageSize * (pageNum - 1); |
| | | int endNum = startNum + pageSize; |
| | | |
| | | // 查出运行在的任务key |
| | | List<Task> taskList = new ArrayList<>(12); |
| | | if (StringUtils.isNotBlank(taskName)) { |
| | | taskList = taskService.createTaskQuery().processInstanceId(processInsId).taskNameLike(taskName).orderByTaskCreateTime().desc().list(); |
| | | } else { |
| | | taskList = taskService.createTaskQuery().processInstanceId(processInsId).orderByTaskCreateTime().desc().list(); |
| | | } |
| | | if (CollectionUtils.isEmpty(taskList)) { |
| | | // 查出已超时的任务id |
| | | List<ProcessCoding> overtimeRecords = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | .eq(ProcessCoding::getProcessInsId, processInsId) |
| | | .eq(ProcessCoding::getOvertimeStatus, ProcessOverTimeConstants.OVERTIME) |
| | | .orderByDesc(ProcessCoding::getGmtCreate) |
| | | .list(); |
| | | if (CollectionUtils.isEmpty(overtimeRecords)) { |
| | | result.total(0); |
| | | return new ArrayList<>(); |
| | | } |
| | | List<String> taskKeys = taskList.stream().map(Task::getTaskDefinitionKey).distinct().collect(Collectors.toList()); |
| | | Map<String, Task> taskMap = taskList.stream().collect(Collectors.toMap(Task::getTaskDefinitionKey, his -> his)); |
| | | // 查出数据库的任务key |
| | | List<ProcessCoding> codeList = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | .eq(ProcessCoding::getProcessInsId, processInsId) |
| | | .in(ProcessCoding::getTaskDefKey, taskKeys) |
| | | .list(); |
| | | List<Task> tList = new ArrayList<>(); |
| | | // 判断 |
| | | for (String key : taskMap.keySet()) { |
| | | List<ProcessCoding> targetProcessCodings = codeList.stream().filter(code -> key.equals(code.getTaskDefKey())).collect(Collectors.toList()); |
| | | // 如果已完成的任务没从数据库查找出来,说明该任务没配置赋码等时间,直接设置为按时完成 |
| | | if (CollectionUtils.isEmpty(targetProcessCodings)) { |
| | | tList.add(taskMap.get(key)); |
| | | } else { |
| | | // 按照时间降序排列 |
| | | targetProcessCodings.sort(Comparator.comparing(ProcessCoding::getGmtCreate).reversed()); |
| | | ProcessCoding latestProjectProcess = targetProcessCodings.get(0); |
| | | if (Objects.nonNull(latestProjectProcess) && ProcessOverTimeConstants.OVERTIME.equals(latestProjectProcess.getOvertimeStatus())) { |
| | | tList.add(taskMap.get(key)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (startNum >= tList.size()) { |
| | | if (startNum >= overtimeRecords.size()) { |
| | | // 如果起始索引超出了列表的大小,返回一个空列表 |
| | | return new ArrayList<>(); |
| | | } |
| | | result.total(tList.size()); |
| | | int end = Math.min(endNum, tList.size()); |
| | | List<Task> pageTaskList = tList.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)); |
| | | result.total(overtimeRecords.size()); |
| | | int end = Math.min(endNum, overtimeRecords.size()); |
| | | List<ProcessCoding> pageOvertimeRecords = overtimeRecords.subList(startNum, end); |
| | | |
| | | // 得到目标任务对应的定义 |
| | | 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()); |
| | | List<CustomerTaskVO> vos = pageOvertimeRecords.stream().map(record -> { |
| | | CustomerTaskVO vo = new CustomerTaskVO(); |
| | | this.setRuntimeTaskInfo(task, vo, projectId); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | Task task = taskService.createTaskQuery().processInstanceId(processInsId).taskId(record.getTaskId()).singleResult(); |
| | | if (Objects.nonNull(task)) { |
| | | this.setRuntimeTaskInfo(task, vo, projectId); |
| | | vo.setTaskStatus(TaskStatusEnum.OVER_TIME); |
| | | return vo; |
| | | } else { |
| | | List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery() |
| | | .finished() |
| | | .processInstanceId(processInsId) |
| | | .taskId(record.getTaskId()) |
| | | .orderByHistoricTaskInstanceStartTime() |
| | | .desc() |
| | | .list(); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return null; |
| | | } |
| | | List<HistoricTaskInstance> hisTask = this.distinctHisTask(list); |
| | | this.setHisTaskInfo(hisTask.get(0), vo, projectId, processInsId); |
| | | vo.setTaskStatus(TaskStatusEnum.OVER_TIME_FINISHED); |
| | | return vo; |
| | | } |
| | | }).filter(Objects::nonNull).collect(Collectors.toList()); |
| | | result.data(vos); |
| | | return vos; |
| | | |
| | | // // 查出运行在的任务key |
| | | // List<Task> taskList = new ArrayList<>(12); |
| | | // if (StringUtils.isNotBlank(taskName)) { |
| | | // taskList = taskService.createTaskQuery().processInstanceId(processInsId).taskNameLike(taskName).orderByTaskCreateTime().desc().list(); |
| | | // } else { |
| | | // taskList = taskService.createTaskQuery().processInstanceId(processInsId).orderByTaskCreateTime().desc().list(); |
| | | // } |
| | | // if (CollectionUtils.isEmpty(taskList)) { |
| | | // result.total(0); |
| | | // return new ArrayList<>(); |
| | | // } |
| | | // List<String> taskKeys = taskList.stream().map(Task::getTaskDefinitionKey).distinct().collect(Collectors.toList()); |
| | | // Map<String, Task> taskMap = taskList.stream().collect(Collectors.toMap(Task::getTaskDefinitionKey, his -> his)); |
| | | // // 查出数据库的任务key |
| | | // List<ProcessCoding> codeList = new LambdaQueryChainWrapper<>(processCodingService.getBaseMapper()) |
| | | // .eq(ProcessCoding::getProcessInsId, processInsId) |
| | | // .in(ProcessCoding::getTaskDefKey, taskKeys) |
| | | // .list(); |
| | | // List<Task> tList = new ArrayList<>(); |
| | | // // 判断 |
| | | // for (String key : taskMap.keySet()) { |
| | | // List<ProcessCoding> targetProcessCodings = codeList.stream().filter(code -> key.equals(code.getTaskDefKey())).collect(Collectors.toList()); |
| | | // // 如果已完成的任务没从数据库查找出来,说明该任务没配置赋码等时间,直接设置为按时完成 |
| | | // if (CollectionUtils.isEmpty(targetProcessCodings)) { |
| | | // tList.add(taskMap.get(key)); |
| | | // } else { |
| | | // // 按照时间降序排列 |
| | | // targetProcessCodings.sort(Comparator.comparing(ProcessCoding::getGmtCreate).reversed()); |
| | | // ProcessCoding latestProjectProcess = targetProcessCodings.get(0); |
| | | // if (Objects.nonNull(latestProjectProcess) && ProcessOverTimeConstants.OVERTIME.equals(latestProjectProcess.getOvertimeStatus())) { |
| | | // tList.add(taskMap.get(key)); |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // if (startNum >= tList.size()) { |
| | | // // 如果起始索引超出了列表的大小,返回一个空列表 |
| | | // return new ArrayList<>(); |
| | | // } |
| | | // result.total(tList.size()); |
| | | // int end = Math.min(endNum, tList.size()); |
| | | // List<Task> pageTaskList = tList.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, projectId); |
| | | // return vo; |
| | | // }).collect(Collectors.toList()); |
| | | // result.data(vos); |
| | | // return 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> rejectTaskIds = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .select(ProcessLog::getTaskId) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.REJECT) |
| | | .orderByDesc(ProcessLog::getGmtCreate) |
| | | .list().stream().map(ProcessLog::getTaskId).collect(Collectors.toList()); |
| | | |
| | | List<String> jumpTaskIds = allJumpTaskList.stream().map(ProcessLog::getTaskId).collect(Collectors.toList()); |
| | | jumpTaskIds.removeAll(rejectTaskIds); |
| | | if(CollectionUtils.isEmpty(jumpTaskIds)) { |
| | | return 0L; |
| | | } |
| | | List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(processInsId) |
| | | .finished() |
| | | .taskIds(jumpTaskIds) |
| | | .includeIdentityLinks() |
| | | .orderByHistoricTaskInstanceStartTime() |
| | | .desc() |
| | | .list(); |
| | | hisTaskList = this.distinctHisTask(hisTaskList); |
| | | // 排除运行时任务 |
| | | List<String> runTaskKeys = taskService.createTaskQuery().processInstanceId(processInsId).list().stream().map(Task::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | hisTaskList = hisTaskList.stream().filter(his -> !runTaskKeys.contains(his.getTaskDefinitionKey())).collect(Collectors.toList()); |
| | | 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> rejectTaskIds = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .select(ProcessLog::getTaskId) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.REJECT) |
| | | .like(StringUtils.isNotBlank(taskName), ProcessLog::getTaskName, taskName) |
| | | .orderByDesc(ProcessLog::getGmtCreate) |
| | | .list().stream().map(ProcessLog::getTaskId).collect(Collectors.toList()); |
| | | |
| | | List<String> jumpTaskIds = allJumpTaskList.stream().map(ProcessLog::getTaskId).collect(Collectors.toList()); |
| | | jumpTaskIds.removeAll(rejectTaskIds); |
| | | if(CollectionUtils.isEmpty(jumpTaskIds)) { |
| | | result.total(0l); |
| | | return new ArrayList<>(); |
| | | } |
| | | List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(processInsId) |
| | | .finished() |
| | | .taskIds(jumpTaskIds) |
| | | .includeIdentityLinks() |
| | | .orderByHistoricTaskInstanceStartTime() |
| | | .desc() |
| | | .list(); |
| | | hisTaskList = this.distinctHisTask(hisTaskList); |
| | | // 排除运行时任务 |
| | | List<String> runTaskKeys = taskService.createTaskQuery().processInstanceId(processInsId).list().stream().map(Task::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | hisTaskList = hisTaskList.stream().filter(his -> !runTaskKeys.contains(his.getTaskDefinitionKey())).collect(Collectors.toList()); |
| | | 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 |
| | |
| | | // 排除容缺后又完成的任务 |
| | | List<ProcessLog> finishedTaskList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.FINISHED) |
| | | .in(ProcessLog::getEventType, ProcessLogEventTypeEnum.FINISHED, ProcessLogEventTypeEnum.REJECT) |
| | | .list(); |
| | | List<String> finishedTaskIds = finishedTaskList.stream().map(ProcessLog::getTaskId).distinct().collect(Collectors.toList()); |
| | | // 得到未完成的容缺任务 |
| | |
| | | .desc() |
| | | .list(); |
| | | hisTaskList = this.distinctHisTask(hisTaskList); |
| | | |
| | | // 排除运行时任务 |
| | | List<String> runTaskKeys = taskService.createTaskQuery().processInstanceId(processInsId).list().stream().map(Task::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | hisTaskList = hisTaskList.stream().filter(his -> !runTaskKeys.contains(his.getTaskDefinitionKey())).collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(hisTaskList)) { |
| | | result.total(0l); |
| | | return new ArrayList<>(); |
| | |
| | | |
| | | // 排除进行中的任务和已完成的任务 |
| | | List<String> runTaskKeyList = taskService.createTaskQuery().processInstanceId(processInsId).list().stream().map(Task::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | List<String> finishedTaskKeyList = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInsId).finished().list().stream().map(HistoricTaskInstance::getTaskDefinitionKey).distinct().collect(Collectors.toList()); |
| | | allUserTaskElement = allUserTaskElement.stream().filter(el -> !runTaskKeyList.contains(el.getId()) && !finishedTaskKeyList.contains(el.getId())).collect(Collectors.toList()); |
| | | List<String> finishedTaskKeyList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .select(ProcessLog::getTaskDefKey) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .in(ProcessLog::getEventType, ProcessLogEventTypeEnum.FINISHED, ProcessLogEventTypeEnum.JUMP, ProcessLogEventTypeEnum.WAIT) |
| | | .list().stream().map(ProcessLog::getTaskDefKey).collect(Collectors.toList()); |
| | | finishedTaskKeyList.addAll(runTaskKeyList); |
| | | // List<String> finishedTaskKeyList = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInsId).finished().list().stream().map(HistoricTaskInstance::getTaskDefinitionKey).distinct().collect(Collectors.toList()); |
| | | allUserTaskElement = allUserTaskElement.stream().filter(el -> finishedTaskKeyList.indexOf(el.getId()) == -1).collect(Collectors.toList()); |
| | | // 模拟模糊查询 |
| | | if (StringUtils.isNotBlank(taskName)) { |
| | | allUserTaskElement = allUserTaskElement.stream().filter(taskEl -> taskEl.getName().contains(taskName)).collect(Collectors.toList()); |
| | |
| | | // 运行时未找到流程,说明流程已经结束了 |
| | | return 0L; |
| | | } |
| | | // 查出已完成的任务,用总任务数-已完成的就得到剩余事项 |
| | | List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(process.getProcessInstanceId()) |
| | | .finished() |
| | | .list(); |
| | | long num = list.stream().map(HistoricTaskInstance::getTaskDefinitionKey).distinct().count(); |
| | | List<UserTask> allUserTaskElement = this.getAllUserTaskElement(processDefinitionId); |
| | | |
| | | return totalNum - num; |
| | | // 排除进行中的任务和已完成的任务 |
| | | List<String> runTaskKeyList = taskService.createTaskQuery().processInstanceId(processInsId).list().stream().map(Task::getTaskDefinitionKey).collect(Collectors.toList()); |
| | | List<String> finishedTaskKeyList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .select(ProcessLog::getTaskDefKey) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .in(ProcessLog::getEventType, ProcessLogEventTypeEnum.FINISHED, ProcessLogEventTypeEnum.JUMP, ProcessLogEventTypeEnum.WAIT) |
| | | .list().stream().map(ProcessLog::getTaskDefKey).collect(Collectors.toList()); |
| | | finishedTaskKeyList.addAll(runTaskKeyList); |
| | | allUserTaskElement = allUserTaskElement.stream().filter(el -> finishedTaskKeyList.indexOf(el.getId()) == -1).collect(Collectors.toList()); |
| | | return Long.valueOf(allUserTaskElement.size()); |
| | | } |
| | | |
| | | /** |
| | |
| | | private List<Task> getCurrentNodeTaskList(String processInstanceId) { |
| | | return taskService.createTaskQuery().processDefinitionId(processInstanceId).list(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result editFinishedTask(EditFinishedTaskForm form) { |
| | | List<HistoricTaskInstance> hisTasks = historyService.createHistoricTaskInstanceQuery().taskId(form.getTaskId()).orderByHistoricTaskInstanceStartTime().desc().list(); |
| | | if (org.apache.commons.collections4.CollectionUtils.isEmpty(hisTasks) || Objects.isNull(hisTasks.get(0))) { |
| | | return Result.error("任务不存在"); |
| | | } |
| | | HistoricTaskInstance task = hisTasks.get(0); |
| | | ProjectProcess projectProcess = new LambdaQueryChainWrapper<>(projectProcessMapper) |
| | | .eq(ProjectProcess::getProcessInsId, task.getProcessInstanceId()) |
| | | .eq(ProjectProcess::getProcessDefId, task.getProcessDefinitionId()) |
| | | .one(); |
| | | if (Objects.isNull(projectProcess)) { |
| | | return Result.error("项目流程未绑定"); |
| | | } |
| | | // 查出字典中需要注入的字段信息 |
| | | List<String> dictList = dictTypeService.selectDictDataByType("flow_variables").stream().map(SysDictData::getDictValue).collect(Collectors.toList()); |
| | | Map<String, Object> newV = new HashMap<>(2); |
| | | if (!org.springframework.util.CollectionUtils.isEmpty(form.getVariables())) { |
| | | for (String key : form.getVariables().keySet()) { |
| | | newV.put(task.getTaskDefinitionKey() + "&" + key, form.getVariables().get(key)); |
| | | // 字典里有就不做处理 |
| | | if (!org.apache.commons.collections4.CollectionUtils.isEmpty(dictList) && dictList.contains(key)) { |
| | | newV.put(key,form.getVariables().get(key)); |
| | | } |
| | | } |
| | | } |
| | | ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); |
| | | Date now = new Date(); |
| | | |
| | | // 1. 表单变量替换 |
| | | for (String key : newV.keySet()) { |
| | | FlowableVarVO var = null; |
| | | if (Objects.isNull(processInstance)) { |
| | | // 查询历史流程变量 |
| | | var = projectProcessMapper.getHisByteId(projectProcess.getProcessInsId(), key); |
| | | } else { |
| | | // 查询运行时流程变量 |
| | | var = projectProcessMapper.getRuByteId(projectProcess.getProcessInsId(), key); |
| | | } |
| | | if (Objects.nonNull(var)) { |
| | | // 先删除原来的变量,再把当前的保存进去 |
| | | projectProcessMapper.deleteHisFlowableVar(var.getID_()); |
| | | projectProcessMapper.deleteRunFlowableVar(var.getID_()); |
| | | if (StringUtils.isNotBlank(var.getBYTEARRAY_ID_())) { |
| | | projectProcessMapper.deleteByteArray(var.getID_()); |
| | | } |
| | | } |
| | | |
| | | // 保存当前的表单数据 |
| | | FlowableVarVO run = new FlowableVarVO(); |
| | | FlowableVarVO v = new FlowableVarVO(); |
| | | v.setNAME_(key); |
| | | v.setPROC_INST_ID_(task.getProcessInstanceId()); |
| | | v.setEXECUTION_ID_(task.getProcessInstanceId()); |
| | | v.setCREATE_TIME_(now); |
| | | v.setLAST_UPDATED_TIME_(now); |
| | | v.setID_(new StrongUuidGenerator().getNextId()); |
| | | |
| | | BeanUtils.copyProperties(v, run); |
| | | run.setID_(new StrongUuidGenerator().getNextId()); |
| | | if (newV.get(key) instanceof String) { |
| | | v.setVAR_TYPE_("string"); |
| | | v.setTEXT_((String) newV.get(key)); |
| | | run.setVAR_TYPE_("string"); |
| | | run.setTEXT_((String) newV.get(key)); |
| | | } else if (newV.get(key) instanceof Integer) { |
| | | v.setVAR_TYPE_("integer"); |
| | | v.setLONG_((Long) newV.get(key)); |
| | | v.setTEXT_((String) newV.get(key)); |
| | | run.setVAR_TYPE_("integer"); |
| | | run.setLONG_((Long) newV.get(key)); |
| | | run.setTEXT_((String) newV.get(key)); |
| | | } else if (newV.get(key) instanceof Long) { |
| | | v.setVAR_TYPE_("long"); |
| | | v.setLONG_((Long) newV.get(key)); |
| | | v.setTEXT_((String) newV.get(key)); |
| | | run.setVAR_TYPE_("long"); |
| | | run.setLONG_((Long) newV.get(key)); |
| | | run.setTEXT_((String) newV.get(key)); |
| | | } else if (newV.get(key) instanceof Boolean) { |
| | | v.setVAR_TYPE_("boolean"); |
| | | v.setLONG_((Long) newV.get(key)); |
| | | v.setTEXT_((String) newV.get(key)); |
| | | run.setVAR_TYPE_("boolean"); |
| | | run.setLONG_((Long) newV.get(key)); |
| | | run.setTEXT_((String) newV.get(key)); |
| | | } else { |
| | | // 其它类型的表单数据:如图片、文件单独存表的。历史、运行中的流程需各存一份 |
| | | v.setVAR_TYPE_("serializable"); |
| | | v.setBYTEARRAY_ID_(new StrongUuidGenerator().getNextId()); |
| | | projectProcessMapper.insertByteArray(v.getBYTEARRAY_ID_(), 1, "hist.var-" + key, newV.get(key)); |
| | | |
| | | run.setVAR_TYPE_("serializable"); |
| | | run.setBYTEARRAY_ID_(new StrongUuidGenerator().getNextId()); |
| | | projectProcessMapper.insertByteArray(run.getBYTEARRAY_ID_(), 1, "var-" + key, newV.get(key)); |
| | | } |
| | | |
| | | projectProcessMapper.insertHisFlowableVar(v); |
| | | projectProcessMapper.insertRunFlowableVar(run); |
| | | |
| | | } |
| | | // 2. 任务状态调整:仅支持 已完成==》容缺/跳过 容缺《===》跳过 |
| | | if (Objects.nonNull(form.getNowStatus()) && ! Objects.equals(form.getOriginalStatus(), form.getNowStatus())) { |
| | | if (TaskStatusEnum.FINISHED.equals(form.getOriginalStatus())) { |
| | | ProcessLog finishedLog = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getTaskId, form.getTaskId()) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.FINISHED) |
| | | .one(); |
| | | if (Objects.nonNull(finishedLog)) { |
| | | if (TaskStatusEnum.JUMP.equals(form.getNowStatus())) { |
| | | // 添加跳过日志 |
| | | publisher.publishEvent(new TaskLogEvent(this, null, |
| | | finishedLog.getUserId(), |
| | | projectProcess.getProjectId(), |
| | | projectProcess.getProcessInsId(), |
| | | form.getTaskId(), |
| | | task.getTaskDefinitionKey(), |
| | | task.getName(), |
| | | ProcessLogEventTypeEnum.JUMP, |
| | | new JumpData(form.getTaskJumpForm().getDesc()))); |
| | | // 删除原来的完成日志 |
| | | processLogService.removeById(finishedLog.getId()); |
| | | } else if (TaskStatusEnum.WAIT.equals(form.getNowStatus())) { |
| | | // 添加容缺日志 |
| | | publisher.publishEvent(new TaskLogEvent(this, null, |
| | | finishedLog.getUserId(), |
| | | projectProcess.getProjectId(), |
| | | projectProcess.getProcessInsId(), |
| | | form.getTaskId(), |
| | | task.getTaskDefinitionKey(), |
| | | task.getName(), |
| | | ProcessLogEventTypeEnum.WAIT, |
| | | new WaitData(form.getTaskWaitForm().getDesc()))); |
| | | // 删除原来的完成日志 |
| | | processLogService.removeById(finishedLog.getId()); |
| | | } else { |
| | | return Result.error("已完成任务只能调整为容缺或跳过状态"); |
| | | } |
| | | } |
| | | } |
| | | else if (TaskStatusEnum.WAIT.equals(form.getOriginalStatus())) { |
| | | ProcessLog waitLog = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getTaskId, form.getTaskId()) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.WAIT) |
| | | .one(); |
| | | if (Objects.nonNull(waitLog)) { |
| | | if (TaskStatusEnum.JUMP.equals(form.getNowStatus())) { |
| | | // 添加跳过日志 |
| | | publisher.publishEvent(new TaskLogEvent(this, null, |
| | | waitLog.getUserId(), |
| | | projectProcess.getProjectId(), |
| | | projectProcess.getProcessInsId(), |
| | | form.getTaskId(), |
| | | task.getTaskDefinitionKey(), |
| | | task.getName(), |
| | | ProcessLogEventTypeEnum.JUMP, |
| | | new JumpData(form.getTaskJumpForm().getDesc()))); |
| | | // 删除原来的容缺日志 |
| | | processLogService.removeById(waitLog.getId()); |
| | | } else { |
| | | return Result.error("容缺任务只能调整为跳过状态"); |
| | | } |
| | | } |
| | | } else if (TaskStatusEnum.JUMP.equals(form.getOriginalStatus())) { |
| | | ProcessLog jumpLog = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) |
| | | .eq(ProcessLog::getTaskId, form.getTaskId()) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.JUMP) |
| | | .one(); |
| | | if (Objects.nonNull(jumpLog)) { |
| | | if (TaskStatusEnum.WAIT.equals(form.getNowStatus())) { |
| | | // 添加容缺日志 |
| | | publisher.publishEvent(new TaskLogEvent(this, null, |
| | | jumpLog.getUserId(), |
| | | projectProcess.getProjectId(), |
| | | projectProcess.getProcessInsId(), |
| | | form.getTaskId(), |
| | | task.getTaskDefinitionKey(), |
| | | task.getName(), |
| | | ProcessLogEventTypeEnum.WAIT, |
| | | new WaitData(form.getTaskWaitForm().getDesc()))); |
| | | // 删除原来的跳过日志 |
| | | processLogService.removeById(jumpLog.getId()); |
| | | } else { |
| | | return Result.error("跳过任务只能调整为容缺任务"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 3. 保存修改日志 |
| | | publisher.publishEvent(new TaskLogEvent(this, null, |
| | | SecurityUtils.getUserId(), |
| | | projectProcess.getProjectId(), |
| | | projectProcess.getProcessInsId(), |
| | | form.getTaskId(), |
| | | task.getTaskDefinitionKey(), |
| | | task.getName(), |
| | | ProcessLogEventTypeEnum.EDIT, |
| | | null)); |
| | | |
| | | return Result.ok("修改成功"); |
| | | } |
| | | } |