From 405a98c8f3fb970806f93e70a8dc97da395c54d3 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期四, 09 五月 2024 17:08:21 +0800 Subject: [PATCH] update 优化 规范命名规则 --- ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java | 407 ++++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 281 insertions(+), 126 deletions(-) diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java index 700dab5..75739c1 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java @@ -2,15 +2,15 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.RequiredArgsConstructor; import org.dromara.common.core.domain.dto.RoleDTO; +import org.dromara.common.core.domain.dto.UserDTO; import org.dromara.common.core.exception.ServiceException; +import org.dromara.common.core.service.UserService; import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.PageQuery; @@ -20,16 +20,21 @@ import org.dromara.workflow.common.constant.FlowConstant; import org.dromara.workflow.common.enums.BusinessStatusEnum; import org.dromara.workflow.common.enums.TaskStatusEnum; +import org.dromara.workflow.domain.ActHiTaskinst; +import org.dromara.workflow.domain.WfTaskBackNode; import org.dromara.workflow.domain.bo.*; -import org.dromara.workflow.domain.vo.MultiInstanceVo; -import org.dromara.workflow.domain.vo.TaskVo; -import org.dromara.workflow.domain.vo.WfCopy; +import org.dromara.workflow.domain.vo.*; import org.dromara.workflow.flowable.cmd.*; import org.dromara.workflow.flowable.strategy.FlowEventStrategy; import org.dromara.workflow.flowable.strategy.FlowProcessEventHandler; import org.dromara.workflow.flowable.strategy.FlowTaskEventHandler; +import org.dromara.workflow.mapper.ActHiTaskinstMapper; import org.dromara.workflow.mapper.ActTaskMapper; import org.dromara.workflow.service.IActTaskService; +import org.dromara.workflow.service.IWfDefinitionConfigService; +import org.dromara.workflow.service.IWfNodeConfigService; +import org.dromara.workflow.service.IWfTaskBackNodeService; +import org.dromara.workflow.utils.ModelUtils; import org.dromara.workflow.utils.QueryUtils; import org.dromara.workflow.utils.WorkflowUtils; import org.flowable.common.engine.api.FlowableObjectNotFoundException; @@ -41,11 +46,12 @@ import org.flowable.engine.impl.bpmn.behavior.SequentialMultiInstanceBehavior; import org.flowable.engine.impl.persistence.entity.ExecutionEntity; import org.flowable.engine.runtime.ProcessInstance; +import org.flowable.identitylink.api.history.HistoricIdentityLink; 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.flowable.task.service.impl.persistence.entity.TaskEntity; +import org.flowable.variable.api.persistence.entity.VariableInstance; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -53,8 +59,7 @@ import java.util.*; import java.util.stream.Collectors; -import static org.dromara.workflow.common.constant.FlowConstant.FLOWABLE_SKIP_EXPRESSION_ENABLED; -import static org.dromara.workflow.common.constant.FlowConstant.INITIATOR; +import static org.dromara.workflow.common.constant.FlowConstant.*; /** * 浠诲姟 鏈嶅姟灞傚疄鐜� @@ -72,6 +77,11 @@ private final ManagementService managementService; private final FlowEventStrategy flowEventStrategy; private final ActTaskMapper actTaskMapper; + private final IWfTaskBackNodeService wfTaskBackNodeService; + private final ActHiTaskinstMapper actHiTaskinstMapper; + private final IWfNodeConfigService wfNodeConfigService; + private final IWfDefinitionConfigService wfDefinitionConfigService; + private final UserService userService; /** * 鍚姩浠诲姟 @@ -96,9 +106,13 @@ if (CollUtil.isNotEmpty(startProcessBo.getVariables())) { taskService.setVariables(taskResult.get(0).getId(), startProcessBo.getVariables()); } - map.put("processInstanceId", taskResult.get(0).getProcessInstanceId()); + map.put(PROCESS_INSTANCE_ID, taskResult.get(0).getProcessInstanceId()); map.put("taskId", taskResult.get(0).getId()); return map; + } + WfDefinitionConfigVo wfDefinitionConfigVo = wfDefinitionConfigService.getByTableNameLastVersion(startProcessBo.getTableName()); + if (wfDefinitionConfigVo == null) { + throw new ServiceException("璇峰埌娴佺▼瀹氫箟缁戝畾涓氬姟琛ㄥ悕涓庢祦绋婯EY锛�"); } // 璁剧疆鍚姩浜� identityService.setAuthenticatedUserId(String.valueOf(LoginHelper.getUserId())); @@ -112,12 +126,12 @@ ProcessInstance pi; try { if (TenantHelper.isEnable()) { - pi = runtimeService.startProcessInstanceByKeyAndTenantId(startProcessBo.getProcessKey(), startProcessBo.getBusinessKey(), variables, TenantHelper.getTenantId()); + pi = runtimeService.startProcessInstanceByKeyAndTenantId(wfDefinitionConfigVo.getProcessKey(), startProcessBo.getBusinessKey(), variables, TenantHelper.getTenantId()); } else { - pi = runtimeService.startProcessInstanceByKey(startProcessBo.getProcessKey(), startProcessBo.getBusinessKey(), variables); + pi = runtimeService.startProcessInstanceByKey(wfDefinitionConfigVo.getProcessKey(), startProcessBo.getBusinessKey(), variables); } } catch (FlowableObjectNotFoundException e) { - throw new ServiceException("鎵句笉鍒板綋鍓嶃��" + startProcessBo.getProcessKey() + "銆戞祦绋嬪畾涔夛紒"); + throw new ServiceException("鎵句笉鍒板綋鍓嶃��" + wfDefinitionConfigVo.getProcessKey() + "銆戞祦绋嬪畾涔夛紒"); } // 灏嗘祦绋嬪畾涔夊悕绉� 浣滀负 娴佺▼瀹炰緥鍚嶇О runtimeService.setProcessInstanceName(pi.getProcessInstanceId(), pi.getProcessDefinitionName()); @@ -129,7 +143,8 @@ runtimeService.updateBusinessStatus(pi.getProcessInstanceId(), BusinessStatusEnum.DRAFT.getStatus()); taskService.setAssignee(taskList.get(0).getId(), LoginHelper.getUserId().toString()); - taskService.setVariable(taskList.get(0).getId(), "processInstanceId", pi.getProcessInstanceId()); + taskService.setVariable(taskList.get(0).getId(), PROCESS_INSTANCE_ID, pi.getProcessInstanceId()); + taskService.setVariable(taskList.get(0).getId(), BUSINESS_KEY, pi.getBusinessKey()); map.put("processInstanceId", pi.getProcessInstanceId()); map.put("taskId", taskList.get(0).getId()); return map; @@ -164,7 +179,7 @@ if (ObjectUtil.isNotEmpty(task.getDelegationState()) && FlowConstant.PENDING.equals(task.getDelegationState().name())) { taskService.resolveTask(completeTaskBo.getTaskId()); TaskEntity newTask = WorkflowUtils.createNewTask(task); - taskService.addComment(newTask.getId(), task.getProcessInstanceId(), completeTaskBo.getMessage()); + taskService.addComment(newTask.getId(), task.getProcessInstanceId(), TaskStatusEnum.PASS.getStatus(), StringUtils.isNotBlank(completeTaskBo.getMessage()) ? completeTaskBo.getMessage() : StrUtil.EMPTY); taskService.complete(newTask.getId()); return true; } @@ -182,16 +197,19 @@ String key = processInstance.getProcessDefinitionKey() + "_" + task.getTaskDefinitionKey(); FlowTaskEventHandler taskHandler = flowEventStrategy.getTaskHandler(key); if (taskHandler != null) { - taskHandler.handleTask(task, processInstance.getBusinessKey()); + taskHandler.handleTask(task.getId(), processInstance.getBusinessKey()); } //鍔炵悊鎰忚 taskService.addComment(completeTaskBo.getTaskId(), task.getProcessInstanceId(), TaskStatusEnum.PASS.getStatus(), StringUtils.isBlank(completeTaskBo.getMessage()) ? "鍚屾剰" : completeTaskBo.getMessage()); //鍔炵悊浠诲姟 + taskService.setAssignee(task.getId(), userId); if (CollUtil.isNotEmpty(completeTaskBo.getVariables())) { taskService.complete(completeTaskBo.getTaskId(), completeTaskBo.getVariables()); } else { taskService.complete(completeTaskBo.getTaskId()); } + //璁板綍鎵ц杩囩殑娴佺▼浠诲姟鑺傜偣 + wfTaskBackNodeService.recordExecuteNode(task); ProcessInstance pi = QueryUtils.instanceQuery(task.getProcessInstanceId()).singleResult(); if (pi == null) { UpdateBusinessStatusCmd updateBusinessStatusCmd = new UpdateBusinessStatusCmd(task.getProcessInstanceId(), BusinessStatusEnum.FINISH.getStatus()); @@ -201,10 +219,18 @@ } } else { List<Task> list = QueryUtils.taskQuery(task.getProcessInstanceId()).list(); + for (Task t : list) { + if (ModelUtils.isUserTask(t.getProcessDefinitionId(), t.getTaskDefinitionKey())) { + List<HistoricIdentityLink> links = historyService.getHistoricIdentityLinksForTask(t.getId()); + if (CollUtil.isEmpty(links) && StringUtils.isBlank(t.getAssignee())) { + throw new ServiceException("涓嬩竴鑺傜偣銆�" + t.getName() + "銆戞病鏈夊姙鐞嗕汉!"); + } + } + } + if (CollUtil.isNotEmpty(list) && CollUtil.isNotEmpty(completeTaskBo.getWfCopyList())) { TaskEntity newTask = WorkflowUtils.createNewTask(task); - taskService.addComment(newTask.getId(), task.getProcessInstanceId(), TaskStatusEnum.COPY.getStatus(), - LoginHelper.getLoginUser().getNickname() + "銆愭妱閫併�戠粰" + String.join(",", StreamUtils.toList(completeTaskBo.getWfCopyList(), WfCopy::getUserName))); + taskService.addComment(newTask.getId(), task.getProcessInstanceId(), TaskStatusEnum.COPY.getStatus(), LoginHelper.getLoginUser().getNickname() + "銆愭妱閫併�戠粰" + String.join(",", StreamUtils.toList(completeTaskBo.getWfCopyList(), WfCopy::getUserName))); taskService.complete(newTask.getId()); List<Task> taskList = QueryUtils.taskQuery(task.getProcessInstanceId()).list(); WorkflowUtils.createCopyTask(taskList, StreamUtils.toList(completeTaskBo.getWfCopyList(), WfCopy::getUserId)); @@ -239,14 +265,11 @@ public TableDataInfo<TaskVo> getPageByTaskWait(TaskBo taskBo, PageQuery pageQuery) { QueryWrapper<TaskVo> queryWrapper = new QueryWrapper<>(); List<RoleDTO> roles = LoginHelper.getLoginUser().getRoles(); + List<String> roleIds = StreamUtils.toList(roles, e -> String.valueOf(e.getRoleId())); String userId = String.valueOf(LoginHelper.getUserId()); queryWrapper.eq("t.business_status_", BusinessStatusEnum.WAITING.getStatus()); queryWrapper.eq(TenantHelper.isEnable(), "t.tenant_id_", TenantHelper.getTenantId()); - queryWrapper.and(w1 -> - w1.eq("t.assignee_", userId) - .or(w2 -> w2.isNull("t.assignee_") - .and(w3 -> w3.eq("t.user_id_", userId).or().in("t.group_id_", StreamUtils.toList(roles, RoleDTO::getRoleId)))) - ); + queryWrapper.and(w1 -> w1.eq("t.assignee_", userId).or(w2 -> w2.isNull("t.assignee_").apply("exists ( select LINK.ID_ from ACT_RU_IDENTITYLINK LINK where LINK.TASK_ID_ = t.ID_ and LINK.TYPE_ = 'candidate' " + "and (LINK.USER_ID_ = {0} or ( LINK.GROUP_ID_ IN " + getInParam(roleIds) + " ) ))", userId))); if (StringUtils.isNotBlank(taskBo.getName())) { queryWrapper.like("t.name_", taskBo.getName()); } @@ -259,12 +282,33 @@ Page<TaskVo> page = actTaskMapper.getTaskWaitByPage(pageQuery.build(), queryWrapper); List<TaskVo> taskList = page.getRecords(); - for (TaskVo task : taskList) { - task.setBusinessStatusName(BusinessStatusEnum.findByStatus(task.getBusinessStatus())); - task.setParticipantVo(WorkflowUtils.getCurrentTaskParticipant(task.getId())); - task.setMultiInstance(WorkflowUtils.isMultiInstance(task.getProcessDefinitionId(), task.getTaskDefinitionKey()) != null); + if (CollUtil.isNotEmpty(taskList)) { + List<String> processDefinitionIds = StreamUtils.toList(taskList, TaskVo::getProcessDefinitionId); + List<WfNodeConfigVo> wfNodeConfigVoList = wfNodeConfigService.selectByDefIds(processDefinitionIds); + for (TaskVo task : taskList) { + task.setBusinessStatusName(BusinessStatusEnum.findByStatus(task.getBusinessStatus())); + task.setParticipantVo(WorkflowUtils.getCurrentTaskParticipant(task.getId())); + task.setMultiInstance(WorkflowUtils.isMultiInstance(task.getProcessDefinitionId(), task.getTaskDefinitionKey()) != null); + if (CollUtil.isNotEmpty(wfNodeConfigVoList)) { + wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && FlowConstant.TRUE.equals(e.getApplyUserTask())).findFirst().ifPresent(task::setWfNodeConfigVo); + wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && e.getNodeId().equals(task.getTaskDefinitionKey()) && FlowConstant.FALSE.equals(e.getApplyUserTask())).findFirst().ifPresent(task::setWfNodeConfigVo); + } + } } - return new TableDataInfo<>(taskList, page.getTotal()); + return TableDataInfo.build(page); + } + + private String getInParam(List<String> param) { + StringBuilder sb = new StringBuilder(); + sb.append("("); + for (int i = 0; i < param.size(); i++) { + sb.append("'").append(param.get(i)).append("'"); + if (i != param.size() - 1) { + sb.append(","); + } + } + sb.append(")"); + return sb.toString(); } /** @@ -292,23 +336,36 @@ processInstanceList = QueryUtils.instanceQuery(processInstanceIds).list(); } List<TaskVo> list = new ArrayList<>(); - for (Task task : taskList) { - TaskVo taskVo = BeanUtil.toBean(task, TaskVo.class); - if (CollUtil.isNotEmpty(processInstanceList)) { - processInstanceList.stream().filter(e -> e.getId().equals(task.getProcessInstanceId())).findFirst().ifPresent(e -> { - taskVo.setBusinessStatus(e.getBusinessStatus()); - taskVo.setBusinessStatusName(BusinessStatusEnum.findByStatus(taskVo.getBusinessStatus())); - taskVo.setProcessDefinitionKey(e.getProcessDefinitionKey()); - taskVo.setProcessDefinitionName(e.getProcessDefinitionName()); - }); + if (CollUtil.isNotEmpty(taskList)) { + List<String> processDefinitionIds = StreamUtils.toList(taskList, Task::getProcessDefinitionId); + List<WfNodeConfigVo> wfNodeConfigVoList = wfNodeConfigService.selectByDefIds(processDefinitionIds); + for (Task task : taskList) { + TaskVo taskVo = BeanUtil.toBean(task, TaskVo.class); + if (CollUtil.isNotEmpty(processInstanceList)) { + processInstanceList.stream().filter(e -> e.getId().equals(task.getProcessInstanceId())).findFirst().ifPresent(e -> { + taskVo.setBusinessStatus(e.getBusinessStatus()); + taskVo.setBusinessStatusName(BusinessStatusEnum.findByStatus(taskVo.getBusinessStatus())); + taskVo.setProcessDefinitionKey(e.getProcessDefinitionKey()); + taskVo.setProcessDefinitionName(e.getProcessDefinitionName()); + taskVo.setProcessDefinitionVersion(e.getProcessDefinitionVersion()); + taskVo.setBusinessKey(e.getBusinessKey()); + }); + } + taskVo.setAssignee(StringUtils.isNotBlank(task.getAssignee()) ? Long.valueOf(task.getAssignee()) : null); + taskVo.setParticipantVo(WorkflowUtils.getCurrentTaskParticipant(task.getId())); + taskVo.setMultiInstance(WorkflowUtils.isMultiInstance(task.getProcessDefinitionId(), task.getTaskDefinitionKey()) != null); + if (CollUtil.isNotEmpty(wfNodeConfigVoList)) { + wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && FlowConstant.TRUE.equals(e.getApplyUserTask())).findFirst().ifPresent(taskVo::setWfNodeConfigVo); + wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && e.getNodeId().equals(task.getTaskDefinitionKey()) && FlowConstant.FALSE.equals(e.getApplyUserTask())).findFirst().ifPresent(taskVo::setWfNodeConfigVo); + } + list.add(taskVo); } - taskVo.setAssignee(StringUtils.isNotBlank(task.getAssignee()) ? Long.valueOf(task.getAssignee()) : null); - taskVo.setParticipantVo(WorkflowUtils.getCurrentTaskParticipant(task.getId())); - taskVo.setMultiInstance(WorkflowUtils.isMultiInstance(task.getProcessDefinitionId(), task.getTaskDefinitionKey()) != null); - list.add(taskVo); } long count = query.count(); - return new TableDataInfo<>(list, count); + TableDataInfo<TaskVo> build = TableDataInfo.build(); + build.setRows(list); + build.setTotal(count); + return build; } /** @@ -319,39 +376,26 @@ @Override public TableDataInfo<TaskVo> getPageByTaskFinish(TaskBo taskBo, PageQuery pageQuery) { String userId = String.valueOf(LoginHelper.getUserId()); - HistoricTaskInstanceQuery query = QueryUtils.hisTaskInstanceQuery(); - query.taskAssignee(userId).finished().orderByHistoricTaskInstanceStartTime().desc(); - if (StringUtils.isNotBlank(taskBo.getName())) { - query.taskNameLike("%" + taskBo.getName() + "%"); - } - if (StringUtils.isNotBlank(taskBo.getProcessDefinitionName())) { - query.processDefinitionNameLike("%" + taskBo.getProcessDefinitionName() + "%"); - } - if (StringUtils.isNotBlank(taskBo.getProcessDefinitionKey())) { - query.processDefinitionKey(taskBo.getProcessDefinitionKey()); - } - List<HistoricTaskInstance> taskInstanceList = query.listPage(pageQuery.getFirstNum(), pageQuery.getPageSize()); - List<HistoricProcessInstance> historicProcessInstanceList = null; - if (CollUtil.isNotEmpty(taskInstanceList)) { - Set<String> processInstanceIds = StreamUtils.toSet(taskInstanceList, HistoricTaskInstance::getProcessInstanceId); - historicProcessInstanceList = QueryUtils.hisInstanceQuery(processInstanceIds).list(); - } - List<TaskVo> list = new ArrayList<>(); - for (HistoricTaskInstance task : taskInstanceList) { - TaskVo taskVo = BeanUtil.toBean(task, TaskVo.class); - if (CollUtil.isNotEmpty(historicProcessInstanceList)) { - historicProcessInstanceList.stream().filter(e -> e.getId().equals(task.getProcessInstanceId())).findFirst().ifPresent(e -> { - taskVo.setBusinessStatus(e.getBusinessStatus()); - taskVo.setBusinessStatusName(BusinessStatusEnum.findByStatus(taskVo.getBusinessStatus())); - taskVo.setProcessDefinitionKey(e.getProcessDefinitionKey()); - taskVo.setProcessDefinitionName(e.getProcessDefinitionName()); - }); + QueryWrapper<TaskVo> queryWrapper = new QueryWrapper<>(); + queryWrapper.like(StringUtils.isNotBlank(taskBo.getName()), "t.name_", taskBo.getName()); + queryWrapper.like(StringUtils.isNotBlank(taskBo.getProcessDefinitionName()), "t.processDefinitionName", taskBo.getProcessDefinitionName()); + queryWrapper.eq(StringUtils.isNotBlank(taskBo.getProcessDefinitionKey()), "t.processDefinitionKey", taskBo.getProcessDefinitionKey()); + queryWrapper.eq("t.assignee_", userId); + Page<TaskVo> page = actTaskMapper.getTaskFinishByPage(pageQuery.build(), queryWrapper); + + List<TaskVo> taskList = page.getRecords(); + if (CollUtil.isNotEmpty(taskList)) { + List<String> processDefinitionIds = StreamUtils.toList(taskList, TaskVo::getProcessDefinitionId); + List<WfNodeConfigVo> wfNodeConfigVoList = wfNodeConfigService.selectByDefIds(processDefinitionIds); + for (TaskVo task : taskList) { + task.setBusinessStatusName(BusinessStatusEnum.findByStatus(task.getBusinessStatus())); + if (CollUtil.isNotEmpty(wfNodeConfigVoList)) { + wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && FlowConstant.TRUE.equals(e.getApplyUserTask())).findFirst().ifPresent(task::setWfNodeConfigVo); + wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && e.getNodeId().equals(task.getTaskDefinitionKey()) && FlowConstant.FALSE.equals(e.getApplyUserTask())).findFirst().ifPresent(task::setWfNodeConfigVo); + } } - taskVo.setAssignee(StringUtils.isNotBlank(task.getAssignee()) ? Long.valueOf(task.getAssignee()) : null); - list.add(taskVo); } - long count = query.count(); - return new TableDataInfo<>(list, count); + return TableDataInfo.build(page); } /** @@ -376,11 +420,18 @@ Page<TaskVo> page = actTaskMapper.getTaskCopyByPage(pageQuery.build(), queryWrapper); List<TaskVo> taskList = page.getRecords(); - for (TaskVo task : taskList) { - task.setBusinessStatusName(BusinessStatusEnum.findByStatus(task.getBusinessStatus())); - task.setMultiInstance(WorkflowUtils.isMultiInstance(task.getProcessDefinitionId(), task.getTaskDefinitionKey()) != null); + if (CollUtil.isNotEmpty(taskList)) { + List<String> processDefinitionIds = StreamUtils.toList(taskList, TaskVo::getProcessDefinitionId); + List<WfNodeConfigVo> wfNodeConfigVoList = wfNodeConfigService.selectByDefIds(processDefinitionIds); + for (TaskVo task : taskList) { + task.setBusinessStatusName(BusinessStatusEnum.findByStatus(task.getBusinessStatus())); + if (CollUtil.isNotEmpty(wfNodeConfigVoList)) { + wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && FlowConstant.TRUE.equals(e.getApplyUserTask())).findFirst().ifPresent(task::setWfNodeConfigVo); + wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && e.getNodeId().equals(task.getTaskDefinitionKey()) && FlowConstant.FALSE.equals(e.getApplyUserTask())).findFirst().ifPresent(task::setWfNodeConfigVo); + } + } } - return new TableDataInfo<>(taskList, page.getTotal()); + return TableDataInfo.build(page); } /** @@ -390,39 +441,25 @@ */ @Override public TableDataInfo<TaskVo> getPageByAllTaskFinish(TaskBo taskBo, PageQuery pageQuery) { - HistoricTaskInstanceQuery query = QueryUtils.hisTaskInstanceQuery(); - query.finished().orderByHistoricTaskInstanceStartTime().desc(); - if (StringUtils.isNotBlank(taskBo.getName())) { - query.taskNameLike("%" + taskBo.getName() + "%"); - } - if (StringUtils.isNotBlank(taskBo.getProcessDefinitionName())) { - query.processDefinitionNameLike("%" + taskBo.getProcessDefinitionName() + "%"); - } - if (StringUtils.isNotBlank(taskBo.getProcessDefinitionKey())) { - query.processDefinitionKey(taskBo.getProcessDefinitionKey()); - } - List<HistoricTaskInstance> taskInstanceList = query.listPage(pageQuery.getFirstNum(), pageQuery.getPageSize()); - List<HistoricProcessInstance> historicProcessInstanceList = null; - if (CollUtil.isNotEmpty(taskInstanceList)) { - Set<String> processInstanceIds = StreamUtils.toSet(taskInstanceList, HistoricTaskInstance::getProcessInstanceId); - historicProcessInstanceList = QueryUtils.hisInstanceQuery(processInstanceIds).list(); - } - List<TaskVo> list = new ArrayList<>(); - for (HistoricTaskInstance task : taskInstanceList) { - TaskVo taskVo = BeanUtil.toBean(task, TaskVo.class); - if (CollUtil.isNotEmpty(historicProcessInstanceList)) { - historicProcessInstanceList.stream().filter(e -> e.getId().equals(task.getProcessInstanceId())).findFirst().ifPresent(e -> { - taskVo.setBusinessStatus(e.getBusinessStatus()); - taskVo.setBusinessStatusName(BusinessStatusEnum.findByStatus(taskVo.getBusinessStatus())); - taskVo.setProcessDefinitionKey(e.getProcessDefinitionKey()); - taskVo.setProcessDefinitionName(e.getProcessDefinitionName()); - }); + QueryWrapper<TaskVo> queryWrapper = new QueryWrapper<>(); + queryWrapper.like(StringUtils.isNotBlank(taskBo.getName()), "t.name_", taskBo.getName()); + queryWrapper.like(StringUtils.isNotBlank(taskBo.getProcessDefinitionName()), "t.processDefinitionName", taskBo.getProcessDefinitionName()); + queryWrapper.eq(StringUtils.isNotBlank(taskBo.getProcessDefinitionKey()), "t.processDefinitionKey", taskBo.getProcessDefinitionKey()); + Page<TaskVo> page = actTaskMapper.getTaskFinishByPage(pageQuery.build(), queryWrapper); + + List<TaskVo> taskList = page.getRecords(); + if (CollUtil.isNotEmpty(taskList)) { + List<String> processDefinitionIds = StreamUtils.toList(taskList, TaskVo::getProcessDefinitionId); + List<WfNodeConfigVo> wfNodeConfigVoList = wfNodeConfigService.selectByDefIds(processDefinitionIds); + for (TaskVo task : taskList) { + task.setBusinessStatusName(BusinessStatusEnum.findByStatus(task.getBusinessStatus())); + if (CollUtil.isNotEmpty(wfNodeConfigVoList)) { + wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && FlowConstant.TRUE.equals(e.getApplyUserTask())).findFirst().ifPresent(task::setWfNodeConfigVo); + wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && e.getNodeId().equals(task.getTaskDefinitionKey()) && FlowConstant.FALSE.equals(e.getApplyUserTask())).findFirst().ifPresent(task::setWfNodeConfigVo); + } } - taskVo.setAssignee(Convert.toLong(task.getAssignee())); - list.add(taskVo); } - long count = query.count(); - return new TableDataInfo<>(list, count); + return TableDataInfo.build(page); } /** @@ -472,8 +509,7 @@ if (task.isSuspended()) { throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED); } - HistoricProcessInstance historicProcessInstance = QueryUtils.hisInstanceQuery() - .processInstanceBusinessKey(task.getProcessInstanceId()).singleResult(); + HistoricProcessInstance historicProcessInstance = QueryUtils.hisInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); BusinessStatusEnum.checkInvalidStatus(historicProcessInstance.getBusinessStatus()); try { if (StringUtils.isBlank(terminationBo.getComment())) { @@ -483,14 +519,14 @@ } taskService.addComment(task.getId(), task.getProcessInstanceId(), TaskStatusEnum.TERMINATION.getStatus(), terminationBo.getComment()); List<Task> list = QueryUtils.taskQuery(task.getProcessInstanceId()).list(); - if (CollectionUtil.isNotEmpty(list)) { + if (CollUtil.isNotEmpty(list)) { List<Task> subTasks = StreamUtils.filter(list, e -> StringUtils.isNotBlank(e.getParentTaskId())); - if (CollectionUtil.isNotEmpty(subTasks)) { + if (CollUtil.isNotEmpty(subTasks)) { subTasks.forEach(e -> taskService.deleteTask(e.getId())); } + runtimeService.updateBusinessStatus(task.getProcessInstanceId(), BusinessStatusEnum.TERMINATION.getStatus()); runtimeService.deleteProcessInstance(task.getProcessInstanceId(), StrUtil.EMPTY); } - runtimeService.updateBusinessStatus(task.getProcessInstanceId(), BusinessStatusEnum.TERMINATION.getStatus()); FlowProcessEventHandler processHandler = flowEventStrategy.getProcessHandler(historicProcessInstance.getProcessDefinitionKey()); if (processHandler != null) { processHandler.handleProcess(historicProcessInstance.getBusinessKey(), BusinessStatusEnum.TERMINATION.getStatus(), false); @@ -508,8 +544,7 @@ */ @Override public boolean transferTask(TransmitBo transmitBo) { - Task task = QueryUtils.taskQuery().taskId(transmitBo.getTaskId()) - .taskCandidateOrAssigned(String.valueOf(LoginHelper.getUserId())).singleResult(); + Task task = QueryUtils.taskQuery().taskId(transmitBo.getTaskId()).taskCandidateOrAssigned(String.valueOf(LoginHelper.getUserId())).singleResult(); if (ObjectUtil.isEmpty(task)) { throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); } @@ -635,7 +670,8 @@ @Transactional(rollbackFor = Exception.class) public String backProcess(BackProcessBo backProcessBo) { TaskQuery query = QueryUtils.taskQuery(); - Task task = query.taskId(backProcessBo.getTaskId()).taskAssignee(String.valueOf(LoginHelper.getUserId())).singleResult(); + String userId = String.valueOf(LoginHelper.getUserId()); + Task task = query.taskId(backProcessBo.getTaskId()).taskCandidateOrAssigned(userId).singleResult(); if (ObjectUtil.isEmpty(task)) { throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); } @@ -649,26 +685,36 @@ ExecutionChildByExecutionIdCmd childByExecutionIdCmd = new ExecutionChildByExecutionIdCmd(task.getExecutionId()); List<ExecutionEntity> executionEntities = managementService.executeCommand(childByExecutionIdCmd); //鏍¢獙鍗曟嵁 - if (BusinessStatusEnum.BACK.getStatus().equals(processInstance.getBusinessStatus())) { - throw new ServiceException("璇ュ崟鎹凡閫�鍥烇紒"); - } BusinessStatusEnum.checkBackStatus(processInstance.getBusinessStatus()); //鍒ゆ柇鏄惁鏈夊涓换鍔� List<Task> taskList = QueryUtils.taskQuery(processInstanceId).list(); - //鐢宠浜鸿妭鐐� - HistoricTaskInstance historicTaskInstance = QueryUtils.hisTaskInstanceQuery(processInstanceId).finished().orderByHistoricTaskInstanceEndTime().asc().list().get(0); - String backTaskDefinitionKey = historicTaskInstance.getTaskDefinitionKey(); + String backTaskDefinitionKey = backProcessBo.getTargetActivityId(); taskService.addComment(task.getId(), processInstanceId, TaskStatusEnum.BACK.getStatus(), StringUtils.isNotBlank(backProcessBo.getMessage()) ? backProcessBo.getMessage() : "閫�鍥�"); if (taskList.size() > 1) { //褰撳墠澶氫釜浠诲姟椹冲洖鍒板崟涓妭鐐� runtimeService.createChangeActivityStateBuilder().processInstanceId(processInstanceId).moveActivityIdsToSingleActivityId(taskList.stream().map(Task::getTaskDefinitionKey).distinct().collect(Collectors.toList()), backTaskDefinitionKey).changeState(); + ActHiTaskinst actHiTaskinst = new ActHiTaskinst(); + actHiTaskinst.setAssignee(userId); + actHiTaskinst.setId(task.getId()); + actHiTaskinstMapper.updateById(actHiTaskinst); } else { //褰撳墠鍗曚釜鑺傜偣椹冲洖鍗曚釜鑺傜偣 runtimeService.createChangeActivityStateBuilder().processInstanceId(processInstanceId).moveActivityIdTo(task.getTaskDefinitionKey(), backTaskDefinitionKey).changeState(); } + //鍒犻櫎骞惰鐜妭鏈姙鐞嗚褰� + MultiInstanceVo multiInstance = WorkflowUtils.isMultiInstance(task.getProcessDefinitionId(), task.getTaskDefinitionKey()); + if (multiInstance == null && taskList.size() > 1) { + List<Task> tasks = StreamUtils.filter(taskList, e -> !e.getTaskDefinitionKey().equals(task.getTaskDefinitionKey())); + actHiTaskinstMapper.deleteBatchIds(StreamUtils.toList(tasks, Task::getId)); + } + + + List<HistoricTaskInstance> instanceList = QueryUtils.hisTaskInstanceQuery(processInstanceId).finished().orderByHistoricTaskInstanceEndTime().desc().list(); List<Task> list = QueryUtils.taskQuery(processInstanceId).list(); for (Task t : list) { - taskService.setAssignee(t.getId(), historicTaskInstance.getAssignee()); + instanceList.stream().filter(e -> e.getTaskDefinitionKey().equals(t.getTaskDefinitionKey())).findFirst().ifPresent(e -> { + taskService.setAssignee(t.getId(), e.getAssignee()); + }); } //鍙戦�佹秷鎭� String message = "鎮ㄧ殑銆�" + processInstance.getName() + "銆戝崟鎹凡缁忚椹冲洖锛岃鎮ㄦ敞鎰忔煡鏀躲��"; @@ -678,11 +724,17 @@ DeleteExecutionCmd deleteExecutionCmd = new DeleteExecutionCmd(executionEntity.getId()); managementService.executeCommand(deleteExecutionCmd); } - runtimeService.updateBusinessStatus(processInstanceId, BusinessStatusEnum.BACK.getStatus()); - FlowProcessEventHandler processHandler = flowEventStrategy.getProcessHandler(processInstance.getProcessDefinitionKey()); - if (processHandler != null) { - processHandler.handleProcess(processInstance.getBusinessKey(), BusinessStatusEnum.BACK.getStatus(), false); + + WfTaskBackNode wfTaskBackNode = wfTaskBackNodeService.getListByInstanceIdAndNodeId(task.getProcessInstanceId(), backProcessBo.getTargetActivityId()); + if (ObjectUtil.isNotNull(wfTaskBackNode) && wfTaskBackNode.getOrderNo() == 0) { + runtimeService.updateBusinessStatus(processInstanceId, BusinessStatusEnum.BACK.getStatus()); + FlowProcessEventHandler processHandler = flowEventStrategy.getProcessHandler(processInstance.getProcessDefinitionKey()); + if (processHandler != null) { + processHandler.handleProcess(processInstance.getBusinessKey(), BusinessStatusEnum.BACK.getStatus(), false); + } } + //鍒犻櫎椹冲洖鍚庣殑娴佺▼鑺傜偣 + wfTaskBackNodeService.deleteBackTaskNode(processInstanceId, backProcessBo.getTargetActivityId()); } catch (Exception e) { throw new ServiceException(e.getMessage()); } @@ -708,4 +760,107 @@ } return true; } + + /** + * 鏌ヨ娴佺▼鍙橀噺 + * + * @param taskId 浠诲姟id + */ + @Override + public List<VariableVo> getInstanceVariable(String taskId) { + List<VariableVo> variableVoList = new ArrayList<>(); + Map<String, VariableInstance> variableInstances = taskService.getVariableInstances(taskId); + if (CollUtil.isNotEmpty(variableInstances)) { + for (Map.Entry<String, VariableInstance> entry : variableInstances.entrySet()) { + VariableVo variableVo = new VariableVo(); + variableVo.setKey(entry.getKey()); + variableVo.setValue(entry.getValue().getValue().toString()); + variableVoList.add(variableVo); + } + } + return variableVoList; + } + + @Override + @SuppressWarnings("unchecked") + public String getTaskUserIdsByAddMultiInstance(String taskId) { + Task task = QueryUtils.taskQuery().taskId(taskId).singleResult(); + if (task == null) { + throw new ServiceException("浠诲姟涓嶅瓨鍦�"); + } + MultiInstanceVo multiInstance = WorkflowUtils.isMultiInstance(task.getProcessDefinitionId(), task.getTaskDefinitionKey()); + if (multiInstance == null) { + return ""; + } + List<Long> userIds; + if (multiInstance.getType() instanceof SequentialMultiInstanceBehavior) { + userIds = (List<Long>) runtimeService.getVariable(task.getExecutionId(), multiInstance.getAssigneeList()); + } else { + List<Task> list = QueryUtils.taskQuery(task.getProcessInstanceId()).list(); + userIds = StreamUtils.toList(list, e -> Long.valueOf(e.getAssignee())); + } + return StringUtils.join(userIds, StringUtils.SEPARATOR); + } + + /** + * 鏌ヨ宸ヤ綔娴侀�夋嫨鍑忕浜哄憳 + * + * @param taskId 浠诲姟id 浠诲姟id + */ + @Override + @SuppressWarnings("unchecked") + public List<TaskVo> getListByDeleteMultiInstance(String taskId) { + Task task = QueryUtils.taskQuery().taskId(taskId).singleResult(); + List<Task> taskList = QueryUtils.taskQuery(task.getProcessInstanceId()).list(); + MultiInstanceVo multiInstance = WorkflowUtils.isMultiInstance(task.getProcessDefinitionId(), task.getTaskDefinitionKey()); + List<TaskVo> taskListVo = new ArrayList<>(); + if (multiInstance == null) { + return List.of(); + } + List<Long> assigneeList = new ArrayList<>(); + if (multiInstance.getType() instanceof SequentialMultiInstanceBehavior) { + List<Object> variable = (List<Object>) runtimeService.getVariable(task.getExecutionId(), multiInstance.getAssigneeList()); + for (Object o : variable) { + assigneeList.add(Long.valueOf(o.toString())); + } + } + + if (multiInstance.getType() instanceof SequentialMultiInstanceBehavior) { + List<Long> userIds = StreamUtils.filter(assigneeList, e -> !String.valueOf(e).equals(task.getAssignee())); + List<UserDTO> userList = userService.selectListByIds(userIds); + for (Long userId : userIds) { + TaskVo taskVo = new TaskVo(); + taskVo.setId("涓茶浼氱"); + taskVo.setExecutionId("涓茶浼氱"); + taskVo.setProcessInstanceId(task.getProcessInstanceId()); + taskVo.setName(task.getName()); + taskVo.setAssignee(userId); + if (CollUtil.isNotEmpty(userList)) { + userList.stream().filter(u -> u.getUserId().toString().equals(userId.toString())).findFirst().ifPresent(u -> taskVo.setAssigneeName(u.getNickName())); + } + taskListVo.add(taskVo); + } + return taskListVo; + } else if (multiInstance.getType() instanceof ParallelMultiInstanceBehavior) { + List<Task> tasks = StreamUtils.filter(taskList, e -> StringUtils.isBlank(e.getParentTaskId()) && !e.getExecutionId().equals(task.getExecutionId()) && e.getTaskDefinitionKey().equals(task.getTaskDefinitionKey())); + if (CollUtil.isNotEmpty(tasks)) { + List<Long> userIds = StreamUtils.toList(tasks, e -> Long.valueOf(e.getAssignee())); + List<UserDTO> userList = userService.selectListByIds(userIds); + for (Task t : tasks) { + TaskVo taskVo = new TaskVo(); + taskVo.setId(t.getId()); + taskVo.setExecutionId(t.getExecutionId()); + taskVo.setProcessInstanceId(t.getProcessInstanceId()); + taskVo.setName(t.getName()); + taskVo.setAssignee(Long.valueOf(t.getAssignee())); + if (CollUtil.isNotEmpty(userList)) { + userList.stream().filter(u -> u.getUserId().toString().equals(t.getAssignee())).findFirst().ifPresent(e -> taskVo.setAssigneeName(e.getNickName())); + } + taskListVo.add(taskVo); + } + return taskListVo; + } + } + return List.of(); + } } -- Gitblit v1.9.3