| | |
| | | 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.VariableVo; |
| | | import org.dromara.workflow.domain.vo.WfCopy; |
| | | import org.dromara.workflow.flowable.strategy.FlowEventStrategy; |
| | | 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.ActTaskMapper; |
| | | import org.dromara.workflow.service.IActTaskService; |
| | | import org.dromara.workflow.utils.QueryUtils; |
| | | import org.dromara.workflow.utils.WorkflowUtils; |
| | | import org.flowable.common.engine.api.FlowableObjectNotFoundException; |
| | | import org.flowable.common.engine.impl.identity.Authentication; |
| | |
| | | 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.engine.runtime.ProcessInstanceQuery; |
| | | 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; |
| | |
| | | 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.*; |
| | | |
| | | /** |
| | | * 任务 服务层实现 |
| | |
| | | throw new ServiceException("启动工作流时必须包含业务ID"); |
| | | } |
| | | // 判断当前业务是否启动过流程 |
| | | HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query.processInstanceTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | HistoricProcessInstanceQuery query = QueryUtils.hisInstanceQuery(); |
| | | HistoricProcessInstance historicProcessInstance = query.processInstanceBusinessKey(startProcessBo.getBusinessKey()).singleResult(); |
| | | if (ObjectUtil.isNotEmpty(historicProcessInstance)) { |
| | | BusinessStatusEnum.checkStartStatus(historicProcessInstance.getBusinessStatus()); |
| | | } |
| | | TaskQuery taskQuery = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | taskQuery.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | List<Task> taskResult = taskQuery.processInstanceBusinessKey(startProcessBo.getBusinessKey()).list(); |
| | | List<Task> taskResult = QueryUtils.taskQuery().processInstanceBusinessKey(startProcessBo.getBusinessKey()).list(); |
| | | if (CollUtil.isNotEmpty(taskResult)) { |
| | | 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; |
| | | } |
| | |
| | | // 将流程定义名称 作为 流程实例名称 |
| | | runtimeService.setProcessInstanceName(pi.getProcessInstanceId(), pi.getProcessDefinitionName()); |
| | | // 申请人执行流程 |
| | | TaskQuery taskQuery1 = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | taskQuery.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | List<Task> taskList = taskQuery1.processInstanceId(pi.getId()).list(); |
| | | List<Task> taskList = QueryUtils.taskQuery(pi.getId()).list(); |
| | | if (taskList.size() > 1) { |
| | | throw new ServiceException("请检查流程第一个环节是否为申请人!"); |
| | | } |
| | | |
| | | 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; |
| | |
| | | try { |
| | | List<RoleDTO> roles = LoginHelper.getLoginUser().getRoles(); |
| | | String userId = String.valueOf(LoginHelper.getUserId()); |
| | | TaskQuery taskQuery = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | taskQuery.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | TaskQuery taskQuery = QueryUtils.taskQuery(); |
| | | taskQuery.taskId(completeTaskBo.getTaskId()).taskCandidateOrAssigned(userId); |
| | | if (CollUtil.isNotEmpty(roles)) { |
| | | List<String> groupIds = StreamUtils.toList(roles, e -> String.valueOf(e.getRoleId())); |
| | |
| | | if (task.isSuspended()) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED); |
| | | } |
| | | ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); |
| | | ProcessInstance processInstance = QueryUtils.instanceQuery(task.getProcessInstanceId()).singleResult(); |
| | | //办理委托任务 |
| | | if (ObjectUtil.isNotEmpty(task.getDelegationState()) && FlowConstant.PENDING.equals(task.getDelegationState().name())) { |
| | | taskService.resolveTask(completeTaskBo.getTaskId()); |
| | |
| | | } else { |
| | | taskService.complete(completeTaskBo.getTaskId()); |
| | | } |
| | | ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query.processInstanceTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | ProcessInstance pi = query.processInstanceId(task.getProcessInstanceId()).singleResult(); |
| | | ProcessInstance pi = QueryUtils.instanceQuery(task.getProcessInstanceId()).singleResult(); |
| | | if (pi == null) { |
| | | UpdateBusinessStatusCmd updateBusinessStatusCmd = new UpdateBusinessStatusCmd(task.getProcessInstanceId(), BusinessStatusEnum.FINISH.getStatus()); |
| | | managementService.executeCommand(updateBusinessStatusCmd); |
| | |
| | | processHandler.handleProcess(processInstance.getBusinessKey(), BusinessStatusEnum.FINISH.getStatus(), false); |
| | | } |
| | | } else { |
| | | TaskQuery query1 = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query1.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | List<Task> list = query1.processInstanceId(task.getProcessInstanceId()).list(); |
| | | List<Task> list = QueryUtils.taskQuery(task.getProcessInstanceId()).list(); |
| | | 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.complete(newTask.getId()); |
| | | List<Task> taskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).list(); |
| | | List<Task> taskList = QueryUtils.taskQuery(task.getProcessInstanceId()).list(); |
| | | WorkflowUtils.createCopyTask(taskList, StreamUtils.toList(completeTaskBo.getWfCopyList(), WfCopy::getUserId)); |
| | | } |
| | | sendMessage(list, processInstance.getName(), completeTaskBo.getMessageType(), null); |
| | |
| | | * @param taskBo 参数 |
| | | */ |
| | | @Override |
| | | public TableDataInfo<TaskVo> getTaskWaitByPage(TaskBo taskBo) { |
| | | PageQuery pageQuery = new PageQuery(); |
| | | pageQuery.setPageNum(taskBo.getPageNum()); |
| | | pageQuery.setPageSize(taskBo.getPageSize()); |
| | | 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)))) |
| | | .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()); |
| | |
| | | return new TableDataInfo<>(taskList, page.getTotal()); |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | /** |
| | | * 查询当前租户所有待办任务 |
| | | * |
| | | * @param taskBo 参数 |
| | | */ |
| | | @Override |
| | | public TableDataInfo<TaskVo> getAllTaskWaitByPage(TaskBo taskBo) { |
| | | TaskQuery query = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | public TableDataInfo<TaskVo> getPageByAllTaskWait(TaskBo taskBo, PageQuery pageQuery) { |
| | | TaskQuery query = QueryUtils.taskQuery(); |
| | | if (StringUtils.isNotBlank(taskBo.getName())) { |
| | | query.taskNameLike("%" + taskBo.getName() + "%"); |
| | | } |
| | |
| | | query.processDefinitionKey(taskBo.getProcessDefinitionKey()); |
| | | } |
| | | query.orderByTaskCreateTime().desc(); |
| | | List<Task> taskList = query.listPage(taskBo.getPageNum(), taskBo.getPageSize()); |
| | | List<Task> taskList = query.listPage(pageQuery.getFirstNum(), pageQuery.getPageSize()); |
| | | List<ProcessInstance> processInstanceList = null; |
| | | if (CollUtil.isNotEmpty(taskList)) { |
| | | Set<String> processInstanceIds = StreamUtils.toSet(taskList, Task::getProcessInstanceId); |
| | | processInstanceList = runtimeService.createProcessInstanceQuery().processInstanceIds(processInstanceIds).list(); |
| | | processInstanceList = QueryUtils.instanceQuery(processInstanceIds).list(); |
| | | } |
| | | List<TaskVo> list = new ArrayList<>(); |
| | | for (Task task : taskList) { |
| | |
| | | * @param taskBo 参数 |
| | | */ |
| | | @Override |
| | | public TableDataInfo<TaskVo> getTaskFinishByPage(TaskBo taskBo) { |
| | | public TableDataInfo<TaskVo> getPageByTaskFinish(TaskBo taskBo, PageQuery pageQuery) { |
| | | String userId = String.valueOf(LoginHelper.getUserId()); |
| | | HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | HistoricTaskInstanceQuery query = QueryUtils.hisTaskInstanceQuery(); |
| | | query.taskAssignee(userId).finished().orderByHistoricTaskInstanceStartTime().desc(); |
| | | if (StringUtils.isNotBlank(taskBo.getName())) { |
| | | query.taskNameLike("%" + taskBo.getName() + "%"); |
| | |
| | | if (StringUtils.isNotBlank(taskBo.getProcessDefinitionKey())) { |
| | | query.processDefinitionKey(taskBo.getProcessDefinitionKey()); |
| | | } |
| | | List<HistoricTaskInstance> taskInstanceList = query.listPage(taskBo.getPageNum(), taskBo.getPageSize()); |
| | | 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 = historyService.createHistoricProcessInstanceQuery().processInstanceIds(processInstanceIds).list(); |
| | | historicProcessInstanceList = QueryUtils.hisInstanceQuery(processInstanceIds).list(); |
| | | } |
| | | List<TaskVo> list = new ArrayList<>(); |
| | | for (HistoricTaskInstance task : taskInstanceList) { |
| | |
| | | * @param taskBo 参数 |
| | | */ |
| | | @Override |
| | | public TableDataInfo<TaskVo> getTaskCopyByPage(TaskBo taskBo) { |
| | | PageQuery pageQuery = new PageQuery(); |
| | | pageQuery.setPageNum(taskBo.getPageNum()); |
| | | pageQuery.setPageSize(taskBo.getPageSize()); |
| | | public TableDataInfo<TaskVo> getPageByTaskCopy(TaskBo taskBo, PageQuery pageQuery) { |
| | | QueryWrapper<TaskVo> queryWrapper = new QueryWrapper<>(); |
| | | String userId = String.valueOf(LoginHelper.getUserId()); |
| | | if (StringUtils.isNotBlank(taskBo.getName())) { |
| | |
| | | * @param taskBo 参数 |
| | | */ |
| | | @Override |
| | | public TableDataInfo<TaskVo> getAllTaskFinishByPage(TaskBo taskBo) { |
| | | HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | 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.getProcessDefinitionKey())) { |
| | | query.processDefinitionKey(taskBo.getProcessDefinitionKey()); |
| | | } |
| | | List<HistoricTaskInstance> taskInstanceList = query.listPage(taskBo.getPageNum(), taskBo.getPageSize()); |
| | | 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 = historyService.createHistoricProcessInstanceQuery().processInstanceIds(processInstanceIds).list(); |
| | | historicProcessInstanceList = QueryUtils.hisInstanceQuery(processInstanceIds).list(); |
| | | } |
| | | List<TaskVo> list = new ArrayList<>(); |
| | | for (HistoricTaskInstance task : taskInstanceList) { |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean delegateTask(DelegateBo delegateBo) { |
| | | TaskQuery query = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | TaskQuery query = QueryUtils.taskQuery(); |
| | | TaskEntity task = (TaskEntity) query.taskId(delegateBo.getTaskId()).taskCandidateOrAssigned(String.valueOf(LoginHelper.getUserId())).singleResult(); |
| | | if (ObjectUtil.isEmpty(task)) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean terminationTask(TerminationBo terminationBo) { |
| | | TaskQuery query = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | TaskQuery query = QueryUtils.taskQuery(); |
| | | Task task = query.taskId(terminationBo.getTaskId()).singleResult(); |
| | | |
| | | if (ObjectUtil.isEmpty(task)) { |
| | |
| | | if (task.isSuspended()) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED); |
| | | } |
| | | HistoricProcessInstanceQuery query1 = historyService.createHistoricProcessInstanceQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query1.processInstanceTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | HistoricProcessInstance historicProcessInstance = query1.processInstanceBusinessKey(task.getProcessInstanceId()).singleResult(); |
| | | if (ObjectUtil.isNotEmpty(historicProcessInstance) && BusinessStatusEnum.TERMINATION.getStatus().equals(historicProcessInstance.getBusinessStatus())) { |
| | | throw new ServiceException("该单据已终止!"); |
| | | } |
| | | HistoricProcessInstance historicProcessInstance = QueryUtils.hisInstanceQuery() |
| | | .processInstanceId(task.getProcessInstanceId()).singleResult(); |
| | | BusinessStatusEnum.checkInvalidStatus(historicProcessInstance.getBusinessStatus()); |
| | | try { |
| | | if (StringUtils.isBlank(terminationBo.getComment())) { |
| | | terminationBo.setComment(LoginHelper.getLoginUser().getNickname() + "终止了申请"); |
| | |
| | | terminationBo.setComment(LoginHelper.getLoginUser().getNickname() + "终止了申请:" + terminationBo.getComment()); |
| | | } |
| | | taskService.addComment(task.getId(), task.getProcessInstanceId(), TaskStatusEnum.TERMINATION.getStatus(), terminationBo.getComment()); |
| | | TaskQuery query2 = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query2.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | List<Task> list = query2.processInstanceId(task.getProcessInstanceId()).list(); |
| | | List<Task> list = QueryUtils.taskQuery(task.getProcessInstanceId()).list(); |
| | | if (CollectionUtil.isNotEmpty(list)) { |
| | | List<Task> subTasks = StreamUtils.filter(list, e -> StringUtils.isNotBlank(e.getParentTaskId())); |
| | | if (CollectionUtil.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); |
| | |
| | | */ |
| | | @Override |
| | | public boolean transferTask(TransmitBo transmitBo) { |
| | | TaskQuery query = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | Task task = query.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); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public boolean addMultiInstanceExecution(AddMultiBo addMultiBo) { |
| | | TaskQuery taskQuery = taskService.createTaskQuery(); |
| | | TaskQuery taskQuery = QueryUtils.taskQuery(); |
| | | taskQuery.taskId(addMultiBo.getTaskId()); |
| | | if (TenantHelper.isEnable()) { |
| | | taskQuery.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | if (!LoginHelper.isSuperAdmin() && !LoginHelper.isTenantAdmin()) { |
| | | taskQuery.taskCandidateOrAssigned(String.valueOf(LoginHelper.getUserId())); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public boolean deleteMultiInstanceExecution(DeleteMultiBo deleteMultiBo) { |
| | | TaskQuery taskQuery = taskService.createTaskQuery(); |
| | | TaskQuery taskQuery = QueryUtils.taskQuery(); |
| | | taskQuery.taskId(deleteMultiBo.getTaskId()); |
| | | if (TenantHelper.isEnable()) { |
| | | taskQuery.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | if (!LoginHelper.isSuperAdmin() && !LoginHelper.isTenantAdmin()) { |
| | | taskQuery.taskCandidateOrAssigned(String.valueOf(LoginHelper.getUserId())); |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String backProcess(BackProcessBo backProcessBo) { |
| | | TaskQuery query = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | TaskQuery query = QueryUtils.taskQuery(); |
| | | Task task = query.taskId(backProcessBo.getTaskId()).taskAssignee(String.valueOf(LoginHelper.getUserId())).singleResult(); |
| | | if (ObjectUtil.isEmpty(task)) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); |
| | |
| | | } |
| | | try { |
| | | String processInstanceId = task.getProcessInstanceId(); |
| | | ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); |
| | | ProcessInstance processInstance = QueryUtils.instanceQuery(task.getProcessInstanceId()).singleResult(); |
| | | //获取并行网关执行后保留的执行实例数据 |
| | | 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()); |
| | | //判断是否有多个任务 |
| | | TaskQuery query1 = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query1.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | List<Task> taskList = query.processInstanceId(processInstanceId).list(); |
| | | List<Task> taskList = QueryUtils.taskQuery(processInstanceId).list(); |
| | | //申请人节点 |
| | | HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId).finished().orderByHistoricTaskInstanceEndTime().asc().list().get(0); |
| | | HistoricTaskInstance historicTaskInstance = QueryUtils.hisTaskInstanceQuery(processInstanceId).finished().orderByHistoricTaskInstanceEndTime().asc().list().get(0); |
| | | String backTaskDefinitionKey = historicTaskInstance.getTaskDefinitionKey(); |
| | | taskService.addComment(task.getId(), processInstanceId, TaskStatusEnum.BACK.getStatus(), StringUtils.isNotBlank(backProcessBo.getMessage()) ? backProcessBo.getMessage() : "退回"); |
| | | if (taskList.size() > 1) { |
| | |
| | | //当前单个节点驳回单个节点 |
| | | runtimeService.createChangeActivityStateBuilder().processInstanceId(processInstanceId).moveActivityIdTo(task.getTaskDefinitionKey(), backTaskDefinitionKey).changeState(); |
| | | } |
| | | TaskQuery query2 = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query1.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | List<Task> list = query2.processInstanceId(processInstanceId).list(); |
| | | List<Task> list = QueryUtils.taskQuery(processInstanceId).list(); |
| | | for (Task t : list) { |
| | | taskService.setAssignee(t.getId(), historicTaskInstance.getAssignee()); |
| | | } |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateAssignee(String[] taskIds, String userId) { |
| | | try { |
| | | TaskQuery query = taskService.createTaskQuery(); |
| | | if (TenantHelper.isEnable()) { |
| | | query.taskTenantId(TenantHelper.getTenantId()); |
| | | } |
| | | List<Task> list = query.taskIds(Arrays.asList(taskIds)).list(); |
| | | List<Task> list = QueryUtils.taskQuery().taskIds(Arrays.asList(taskIds)).list(); |
| | | for (Task task : list) { |
| | | taskService.setAssignee(task.getId(), userId); |
| | | } |
| | |
| | | } |
| | | 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 (CollectionUtil.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; |
| | | } |
| | | } |