| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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.OssService; |
| | | 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.satoken.utils.LoginHelper; |
| | | import org.dromara.common.tenant.helper.TenantHelper; |
| | | import org.dromara.workflow.common.constant.FlowConstant; |
| | | import org.dromara.workflow.common.enums.BusinessStatusEnum; |
| | | import org.dromara.common.core.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.*; |
| | | 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.flowable.handler.FlowProcessEventHandler; |
| | | import org.dromara.workflow.mapper.ActHiTaskinstMapper; |
| | | import org.dromara.workflow.mapper.ActTaskMapper; |
| | | import org.dromara.workflow.service.IActTaskService; |
| | |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.flowable.task.service.impl.persistence.entity.TaskEntity; |
| | | import org.flowable.variable.api.persistence.entity.VariableInstance; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | * |
| | | * @author may |
| | | */ |
| | | @Slf4j |
| | | @RequiredArgsConstructor |
| | | @Service |
| | | public class ActTaskServiceImpl implements IActTaskService { |
| | | |
| | | private final RuntimeService runtimeService; |
| | | private final TaskService taskService; |
| | | private final HistoryService historyService; |
| | | private final IdentityService identityService; |
| | | private final ManagementService managementService; |
| | | private final FlowEventStrategy flowEventStrategy; |
| | | @Autowired(required = false) |
| | | private RuntimeService runtimeService; |
| | | @Autowired(required = false) |
| | | private TaskService taskService; |
| | | @Autowired(required = false) |
| | | private HistoryService historyService; |
| | | @Autowired(required = false) |
| | | private IdentityService identityService; |
| | | @Autowired(required = false) |
| | | private ManagementService managementService; |
| | | private final ActTaskMapper actTaskMapper; |
| | | private final IWfTaskBackNodeService wfTaskBackNodeService; |
| | | private final ActHiTaskinstMapper actHiTaskinstMapper; |
| | | private final IWfNodeConfigService wfNodeConfigService; |
| | | private final IWfDefinitionConfigService wfDefinitionConfigService; |
| | | private final FlowProcessEventHandler flowProcessEventHandler; |
| | | private final UserService userService; |
| | | private final OssService ossService; |
| | | |
| | | /** |
| | | * 启动任务 |
| | |
| | | public boolean completeTask(CompleteTaskBo completeTaskBo) { |
| | | try { |
| | | String userId = String.valueOf(LoginHelper.getUserId()); |
| | | Task task = WorkflowUtils.getTaskByCurrUser(completeTaskBo.getTaskId()); |
| | | Task task = WorkflowUtils.getTaskByCurrentUser(completeTaskBo.getTaskId()); |
| | | if (task == null) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); |
| | | } |
| | |
| | | return true; |
| | | } |
| | | //附件上传 |
| | | AttachmentCmd attachmentCmd = new AttachmentCmd(completeTaskBo.getFileId(), task.getId(), task.getProcessInstanceId()); |
| | | AttachmentCmd attachmentCmd = new AttachmentCmd(completeTaskBo.getFileId(), task.getId(), task.getProcessInstanceId(), ossService); |
| | | managementService.executeCommand(attachmentCmd); |
| | | FlowProcessEventHandler processHandler = flowEventStrategy.getProcessHandler(processInstance.getProcessDefinitionKey()); |
| | | String businessStatus = WorkflowUtils.getBusinessStatus(task.getProcessInstanceId()); |
| | | String businessStatus = WorkflowUtils.getBusinessStatus(processInstance.getBusinessKey()); |
| | | //流程提交监听 |
| | | if (BusinessStatusEnum.DRAFT.getStatus().equals(businessStatus) || BusinessStatusEnum.BACK.getStatus().equals(businessStatus) || BusinessStatusEnum.CANCEL.getStatus().equals(businessStatus)) { |
| | | if (processHandler != null) { |
| | | processHandler.handleProcess(processInstance.getBusinessKey(), businessStatus, true); |
| | | } |
| | | flowProcessEventHandler.processHandler(processInstance.getProcessDefinitionKey(), processInstance.getBusinessKey(), businessStatus, true); |
| | | } |
| | | runtimeService.updateBusinessStatus(task.getProcessInstanceId(), BusinessStatusEnum.WAITING.getStatus()); |
| | | String key = processInstance.getProcessDefinitionKey() + "_" + task.getTaskDefinitionKey(); |
| | | FlowTaskEventHandler taskHandler = flowEventStrategy.getTaskHandler(key); |
| | | if (taskHandler != null) { |
| | | taskHandler.handleTask(task.getId(), processInstance.getBusinessKey()); |
| | | } |
| | | //办理监听 |
| | | flowProcessEventHandler.processTaskHandler(processInstance.getProcessDefinitionKey(), task.getTaskDefinitionKey(), |
| | | task.getId(), processInstance.getBusinessKey()); |
| | | //办理意见 |
| | | taskService.addComment(completeTaskBo.getTaskId(), task.getProcessInstanceId(), TaskStatusEnum.PASS.getStatus(), StringUtils.isBlank(completeTaskBo.getMessage()) ? "同意" : completeTaskBo.getMessage()); |
| | | //办理任务 |
| | |
| | | if (pi == null) { |
| | | UpdateBusinessStatusCmd updateBusinessStatusCmd = new UpdateBusinessStatusCmd(task.getProcessInstanceId(), BusinessStatusEnum.FINISH.getStatus()); |
| | | managementService.executeCommand(updateBusinessStatusCmd); |
| | | if (processHandler != null) { |
| | | processHandler.handleProcess(processInstance.getBusinessKey(), BusinessStatusEnum.FINISH.getStatus(), false); |
| | | } |
| | | flowProcessEventHandler.processHandler(processInstance.getProcessDefinitionKey(), processInstance.getBusinessKey(), |
| | | BusinessStatusEnum.FINISH.getStatus(), false); |
| | | } else { |
| | | List<Task> list = QueryUtils.taskQuery(task.getProcessInstanceId()).list(); |
| | | for (Task t : list) { |
| | |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | |
| | | */ |
| | | @Async |
| | | public void sendMessage(List<Task> list, String name, List<String> messageType, String message) { |
| | | WorkflowUtils.sendMessage(list, name, messageType, message); |
| | | WorkflowUtils.sendMessage(list, name, messageType, message, userService); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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_").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))); |
| | | String ids = StreamUtils.join(roleIds, x -> "'" + x + "'"); |
| | | 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 (" + ids + ") ) ))", userId))); |
| | | if (StringUtils.isNotBlank(taskBo.getName())) { |
| | | queryWrapper.like("t.name_", taskBo.getName()); |
| | | } |
| | |
| | | List<WfNodeConfigVo> wfNodeConfigVoList = wfNodeConfigService.selectByDefIds(processDefinitionIds); |
| | | for (TaskVo task : taskList) { |
| | | task.setBusinessStatusName(BusinessStatusEnum.findByStatus(task.getBusinessStatus())); |
| | | task.setParticipantVo(WorkflowUtils.getCurrentTaskParticipant(task.getId())); |
| | | task.setParticipantVo(WorkflowUtils.getCurrentTaskParticipant(task.getId(), userService)); |
| | | 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); |
| | |
| | | } |
| | | } |
| | | 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(); |
| | | } |
| | | |
| | | /** |
| | |
| | | }); |
| | | } |
| | | taskVo.setAssignee(StringUtils.isNotBlank(task.getAssignee()) ? Long.valueOf(task.getAssignee()) : null); |
| | | taskVo.setParticipantVo(WorkflowUtils.getCurrentTaskParticipant(task.getId())); |
| | | taskVo.setParticipantVo(WorkflowUtils.getCurrentTaskParticipant(task.getId(), userService)); |
| | | 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); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean delegateTask(DelegateBo delegateBo) { |
| | | Task task = WorkflowUtils.getTaskByCurrUser(delegateBo.getTaskId()); |
| | | Task task = WorkflowUtils.getTaskByCurrentUser(delegateBo.getTaskId()); |
| | | |
| | | if (ObjectUtil.isEmpty(task)) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); |
| | |
| | | taskService.complete(newTask.getId()); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(e.getMessage(), e); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | |
| | | runtimeService.updateBusinessStatus(task.getProcessInstanceId(), BusinessStatusEnum.TERMINATION.getStatus()); |
| | | runtimeService.deleteProcessInstance(task.getProcessInstanceId(), StrUtil.EMPTY); |
| | | } |
| | | FlowProcessEventHandler processHandler = flowEventStrategy.getProcessHandler(historicProcessInstance.getProcessDefinitionKey()); |
| | | if (processHandler != null) { |
| | | processHandler.handleProcess(historicProcessInstance.getBusinessKey(), BusinessStatusEnum.TERMINATION.getStatus(), false); |
| | | } |
| | | //流程终止监听 |
| | | flowProcessEventHandler.processHandler(historicProcessInstance.getProcessDefinitionKey(), |
| | | historicProcessInstance.getBusinessKey(), BusinessStatusEnum.TERMINATION.getStatus(), false); |
| | | return true; |
| | | } catch (Exception e) { |
| | | throw new ServiceException(e.getMessage()); |
| | |
| | | */ |
| | | @Override |
| | | public boolean transferTask(TransmitBo transmitBo) { |
| | | Task task = WorkflowUtils.getTaskByCurrUser(transmitBo.getTaskId()); |
| | | Task task = WorkflowUtils.getTaskByCurrentUser(transmitBo.getTaskId()); |
| | | if (ObjectUtil.isEmpty(task)) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); |
| | | } |
| | |
| | | taskService.setAssignee(task.getId(), transmitBo.getUserId()); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(e.getMessage(), e); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | |
| | | taskService.complete(newTask.getId()); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(e.getMessage(), e); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | |
| | | taskService.complete(newTask.getId()); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(e.getMessage(), e); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String backProcess(BackProcessBo backProcessBo) { |
| | | String userId = String.valueOf(LoginHelper.getUserId()); |
| | | Task task = WorkflowUtils.getTaskByCurrUser(backProcessBo.getTaskId()); |
| | | Task task = WorkflowUtils.getTaskByCurrentUser(backProcessBo.getTaskId()); |
| | | |
| | | if (ObjectUtil.isEmpty(task)) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); |
| | |
| | | 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)); |
| | | if (CollUtil.isNotEmpty(tasks)) { |
| | | actHiTaskinstMapper.deleteByIds(StreamUtils.toList(tasks, Task::getId)); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | 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); |
| | | } |
| | | flowProcessEventHandler.processHandler(processInstance.getProcessDefinitionKey(), |
| | | processInstance.getBusinessKey(), BusinessStatusEnum.BACK.getStatus(), false); |
| | | } |
| | | //删除驳回后的流程节点 |
| | | wfTaskBackNodeService.deleteBackTaskNode(processInstanceId, backProcessBo.getTargetActivityId()); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | return task.getProcessInstanceId(); |
| | |
| | | taskService.setAssignee(task.getId(), userId); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("修改失败:" + e.getMessage(), e); |
| | | throw new ServiceException("修改失败:" + e.getMessage()); |
| | | } |
| | | return true; |