| | |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | 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; |
| | |
| | | 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; |
| | |
| | | private final IWfTaskBackNodeService iWfTaskBackNodeService; |
| | | private final ActHiTaskinstMapper actHiTaskinstMapper; |
| | | private final IWfNodeConfigService iWfNodeConfigService; |
| | | private final IWfDefinitionConfigService iWfDefinitionConfigService; |
| | | private final UserService userService; |
| | | |
| | | /** |
| | | * 启动任务 |
| | |
| | | map.put("taskId", taskResult.get(0).getId()); |
| | | return map; |
| | | } |
| | | WfDefinitionConfigVo wfDefinitionConfigVo = iWfDefinitionConfigService.getByTableNameLastVersion(startProcessBo.getTableName()); |
| | | if (wfDefinitionConfigVo == null) { |
| | | throw new ServiceException("请到流程定义绑定业务表名与流程KEY!"); |
| | | } |
| | | // 设置启动人 |
| | | identityService.setAuthenticatedUserId(String.valueOf(LoginHelper.getUserId())); |
| | | Authentication.setAuthenticatedUserId(String.valueOf(LoginHelper.getUserId())); |
| | |
| | | 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()); |
| | |
| | | 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()) && e.getNodeId().equals(task.getTaskDefinitionKey())).findFirst().ifPresent(task::setWfNodeConfigVo); |
| | | 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); |
| | | } |
| | | } |
| | | WorkflowUtils.setWfDefinitionConfigVo(taskList, processDefinitionIds, PROCESS_DEFINITION_ID); |
| | | } |
| | | return TableDataInfo.build(page); |
| | | } |
| | |
| | | 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()) && e.getNodeId().equals(task.getTaskDefinitionKey())).findFirst().ifPresent(taskVo::setWfNodeConfigVo); |
| | | 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); |
| | | } |
| | | WorkflowUtils.setWfDefinitionConfigVo(list, processDefinitionIds, PROCESS_DEFINITION_ID); |
| | | } |
| | | long count = query.count(); |
| | | TableDataInfo<TaskVo> build = TableDataInfo.build(); |
| | |
| | | for (TaskVo task : taskList) { |
| | | task.setBusinessStatusName(BusinessStatusEnum.findByStatus(task.getBusinessStatus())); |
| | | if (CollUtil.isNotEmpty(wfNodeConfigVoList)) { |
| | | wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && e.getNodeId().equals(task.getTaskDefinitionKey())).findFirst().ifPresent(task::setWfNodeConfigVo); |
| | | 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); |
| | | } |
| | | } |
| | | WorkflowUtils.setWfDefinitionConfigVo(taskList, processDefinitionIds, PROCESS_DEFINITION_ID); |
| | | } |
| | | return TableDataInfo.build(page); |
| | | } |
| | |
| | | for (TaskVo task : taskList) { |
| | | task.setBusinessStatusName(BusinessStatusEnum.findByStatus(task.getBusinessStatus())); |
| | | if (CollUtil.isNotEmpty(wfNodeConfigVoList)) { |
| | | wfNodeConfigVoList.stream().filter(e -> e.getDefinitionId().equals(task.getProcessDefinitionId()) && e.getNodeId().equals(task.getTaskDefinitionKey())).findFirst().ifPresent(task::setWfNodeConfigVo); |
| | | 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); |
| | | } |
| | | } |
| | | WorkflowUtils.setWfDefinitionConfigVo(taskList, processDefinitionIds, PROCESS_DEFINITION_ID); |
| | | |
| | | } |
| | | return TableDataInfo.build(page); |
| | | } |
| | |
| | | Page<TaskVo> page = actTaskMapper.getTaskFinishByPage(pageQuery.build(), queryWrapper); |
| | | |
| | | List<TaskVo> taskList = page.getRecords(); |
| | | for (TaskVo task : taskList) { |
| | | task.setBusinessStatusName(BusinessStatusEnum.findByStatus(task.getBusinessStatus())); |
| | | } |
| | | if (CollUtil.isNotEmpty(taskList)) { |
| | | List<String> processDefinitionIds = StreamUtils.toList(taskList, TaskVo::getProcessDefinitionId); |
| | | WorkflowUtils.setWfDefinitionConfigVo(taskList, processDefinitionIds, PROCESS_DEFINITION_ID); |
| | | List<WfNodeConfigVo> wfNodeConfigVoList = iWfNodeConfigService.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 TableDataInfo.build(page); |
| | | } |
| | |
| | | } |
| | | 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()); |
| | |
| | | public List<VariableVo> getInstanceVariable(String taskId) { |
| | | List<VariableVo> variableVoList = new ArrayList<>(); |
| | | Map<String, VariableInstance> variableInstances = taskService.getVariableInstances(taskId); |
| | | if (CollectionUtil.isNotEmpty(variableInstances)) { |
| | | if (CollUtil.isNotEmpty(variableInstances)) { |
| | | for (Map.Entry<String, VariableInstance> entry : variableInstances.entrySet()) { |
| | | VariableVo variableVo = new VariableVo(); |
| | | variableVo.setKey(entry.getKey()); |
| | |
| | | } |
| | | 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(); |
| | | } |
| | | } |