¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.dromara.workflow.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | 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.common.mybatis.core.page.TableDataInfo; |
| | | 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.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.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; |
| | | import org.flowable.common.engine.impl.identity.Authentication; |
| | | import org.flowable.engine.*; |
| | | import org.flowable.engine.history.HistoricProcessInstance; |
| | | import org.flowable.engine.history.HistoricProcessInstanceQuery; |
| | | import org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior; |
| | | 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.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.*; |
| | | |
| | | /** |
| | | * ä»»å¡ æå¡å±å®ç° |
| | | * |
| | | * @author may |
| | | */ |
| | | @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; |
| | | private final ActTaskMapper actTaskMapper; |
| | | private final IWfTaskBackNodeService wfTaskBackNodeService; |
| | | private final ActHiTaskinstMapper actHiTaskinstMapper; |
| | | private final IWfNodeConfigService wfNodeConfigService; |
| | | private final IWfDefinitionConfigService wfDefinitionConfigService; |
| | | private final UserService userService; |
| | | |
| | | /** |
| | | * å¯å¨ä»»å¡ |
| | | * |
| | | * @param startProcessBo å¯å¨æµç¨åæ° |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map<String, Object> startWorkFlow(StartProcessBo startProcessBo) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if (StringUtils.isBlank(startProcessBo.getBusinessKey())) { |
| | | throw new ServiceException("å¯å¨å·¥ä½æµæ¶å¿
é¡»å
å«ä¸å¡ID"); |
| | | } |
| | | // 夿å½åä¸å¡æ¯å¦å¯å¨è¿æµç¨ |
| | | HistoricProcessInstanceQuery query = QueryUtils.hisInstanceQuery(); |
| | | HistoricProcessInstance historicProcessInstance = query.processInstanceBusinessKey(startProcessBo.getBusinessKey()).singleResult(); |
| | | if (ObjectUtil.isNotEmpty(historicProcessInstance)) { |
| | | BusinessStatusEnum.checkStartStatus(historicProcessInstance.getBusinessStatus()); |
| | | } |
| | | 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(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("è¯·å°æµç¨å®ä¹ç»å®ä¸å¡è¡¨å䏿µç¨KEYï¼"); |
| | | } |
| | | // 设置å¯å¨äºº |
| | | identityService.setAuthenticatedUserId(String.valueOf(LoginHelper.getUserId())); |
| | | Authentication.setAuthenticatedUserId(String.valueOf(LoginHelper.getUserId())); |
| | | // å¯å¨æµç¨å®ä¾ï¼æäº¤ç³è¯·ï¼ |
| | | Map<String, Object> variables = startProcessBo.getVariables(); |
| | | // å¯å¨è·³è¿è¡¨è¾¾å¼ |
| | | variables.put(FLOWABLE_SKIP_EXPRESSION_ENABLED, true); |
| | | // æµç¨å起人 |
| | | variables.put(INITIATOR, (String.valueOf(LoginHelper.getUserId()))); |
| | | ProcessInstance pi; |
| | | try { |
| | | if (TenantHelper.isEnable()) { |
| | | pi = runtimeService.startProcessInstanceByKeyAndTenantId(wfDefinitionConfigVo.getProcessKey(), startProcessBo.getBusinessKey(), variables, TenantHelper.getTenantId()); |
| | | } else { |
| | | pi = runtimeService.startProcessInstanceByKey(wfDefinitionConfigVo.getProcessKey(), startProcessBo.getBusinessKey(), variables); |
| | | } |
| | | } catch (FlowableObjectNotFoundException e) { |
| | | throw new ServiceException("æ¾ä¸å°å½åã" + wfDefinitionConfigVo.getProcessKey() + "ãæµç¨å®ä¹ï¼"); |
| | | } |
| | | // å°æµç¨å®ä¹åç§° ä½ä¸º æµç¨å®ä¾åç§° |
| | | runtimeService.setProcessInstanceName(pi.getProcessInstanceId(), pi.getProcessDefinitionName()); |
| | | // ç³è¯·äººæ§è¡æµç¨ |
| | | 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(), 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; |
| | | } |
| | | |
| | | /** |
| | | * åçä»»å¡ |
| | | * |
| | | * @param completeTaskBo åçä»»å¡åæ° |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean completeTask(CompleteTaskBo completeTaskBo) { |
| | | try { |
| | | List<RoleDTO> roles = LoginHelper.getLoginUser().getRoles(); |
| | | String userId = String.valueOf(LoginHelper.getUserId()); |
| | | 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())); |
| | | taskQuery.taskCandidateGroupIn(groupIds); |
| | | } |
| | | Task task = taskQuery.singleResult(); |
| | | if (task == null) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); |
| | | } |
| | | if (task.isSuspended()) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED); |
| | | } |
| | | ProcessInstance processInstance = QueryUtils.instanceQuery(task.getProcessInstanceId()).singleResult(); |
| | | //åçå§æä»»å¡ |
| | | 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(), TaskStatusEnum.PASS.getStatus(), StringUtils.isNotBlank(completeTaskBo.getMessage()) ? completeTaskBo.getMessage() : StrUtil.EMPTY); |
| | | taskService.complete(newTask.getId()); |
| | | return true; |
| | | } |
| | | //éä»¶ä¸ä¼ |
| | | AttachmentCmd attachmentCmd = new AttachmentCmd(completeTaskBo.getFileId(), task.getId(), task.getProcessInstanceId()); |
| | | managementService.executeCommand(attachmentCmd); |
| | | FlowProcessEventHandler processHandler = flowEventStrategy.getProcessHandler(processInstance.getProcessDefinitionKey()); |
| | | String businessStatus = WorkflowUtils.getBusinessStatus(task.getProcessInstanceId()); |
| | | 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); |
| | | } |
| | | } |
| | | 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()); |
| | | } |
| | | //åçæè§ |
| | | 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()); |
| | | managementService.executeCommand(updateBusinessStatusCmd); |
| | | if (processHandler != null) { |
| | | processHandler.handleProcess(processInstance.getBusinessKey(), BusinessStatusEnum.FINISH.getStatus(), false); |
| | | } |
| | | } 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.complete(newTask.getId()); |
| | | List<Task> taskList = QueryUtils.taskQuery(task.getProcessInstanceId()).list(); |
| | | WorkflowUtils.createCopyTask(taskList, StreamUtils.toList(completeTaskBo.getWfCopyList(), WfCopy::getUserId)); |
| | | } |
| | | sendMessage(list, processInstance.getName(), completeTaskBo.getMessageType(), null); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åéæ¶æ¯ |
| | | * |
| | | * @param list ä»»å¡ |
| | | * @param name æµç¨åç§° |
| | | * @param messageType æ¶æ¯ç±»å |
| | | * @param message æ¶æ¯å
容ï¼ä¸ºç©ºååéé»è®¤é
ç½®çæ¶æ¯å
容 |
| | | */ |
| | | @Async |
| | | public void sendMessage(List<Task> list, String name, List<String> messageType, String message) { |
| | | WorkflowUtils.sendMessage(list, name, messageType, message); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢å½åç¨æ·çå¾
åä»»å¡ |
| | | * |
| | | * @param taskBo åæ° |
| | | */ |
| | | @Override |
| | | 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_").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()); |
| | | } |
| | | if (StringUtils.isNotBlank(taskBo.getProcessDefinitionName())) { |
| | | queryWrapper.like("t.processDefinitionName", taskBo.getProcessDefinitionName()); |
| | | } |
| | | if (StringUtils.isNotBlank(taskBo.getProcessDefinitionKey())) { |
| | | queryWrapper.eq("t.processDefinitionKey", taskBo.getProcessDefinitionKey()); |
| | | } |
| | | Page<TaskVo> page = actTaskMapper.getTaskWaitByPage(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())); |
| | | 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 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(); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢å½åç§æ·ææå¾
åä»»å¡ |
| | | * |
| | | * @param taskBo åæ° |
| | | */ |
| | | @Override |
| | | public TableDataInfo<TaskVo> getPageByAllTaskWait(TaskBo taskBo, PageQuery pageQuery) { |
| | | TaskQuery query = QueryUtils.taskQuery(); |
| | | 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()); |
| | | } |
| | | query.orderByTaskCreateTime().desc(); |
| | | 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 = QueryUtils.instanceQuery(processInstanceIds).list(); |
| | | } |
| | | List<TaskVo> list = new ArrayList<>(); |
| | | 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); |
| | | } |
| | | } |
| | | long count = query.count(); |
| | | TableDataInfo<TaskVo> build = TableDataInfo.build(); |
| | | build.setRows(list); |
| | | build.setTotal(count); |
| | | return build; |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢å½åç¨æ·çå·²åä»»å¡ |
| | | * |
| | | * @param taskBo åæ° |
| | | */ |
| | | @Override |
| | | public TableDataInfo<TaskVo> getPageByTaskFinish(TaskBo taskBo, PageQuery pageQuery) { |
| | | String userId = String.valueOf(LoginHelper.getUserId()); |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | return TableDataInfo.build(page); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢å½åç¨æ·çæé |
| | | * |
| | | * @param taskBo åæ° |
| | | */ |
| | | @Override |
| | | public TableDataInfo<TaskVo> getPageByTaskCopy(TaskBo taskBo, PageQuery pageQuery) { |
| | | QueryWrapper<TaskVo> queryWrapper = new QueryWrapper<>(); |
| | | String userId = String.valueOf(LoginHelper.getUserId()); |
| | | if (StringUtils.isNotBlank(taskBo.getName())) { |
| | | queryWrapper.like("t.name_", taskBo.getName()); |
| | | } |
| | | if (StringUtils.isNotBlank(taskBo.getProcessDefinitionName())) { |
| | | queryWrapper.like("t.processDefinitionName", taskBo.getProcessDefinitionName()); |
| | | } |
| | | if (StringUtils.isNotBlank(taskBo.getProcessDefinitionKey())) { |
| | | queryWrapper.eq("t.processDefinitionKey", taskBo.getProcessDefinitionKey()); |
| | | } |
| | | queryWrapper.eq("t.assignee_", userId); |
| | | Page<TaskVo> page = actTaskMapper.getTaskCopyByPage(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); |
| | | } |
| | | } |
| | | } |
| | | return TableDataInfo.build(page); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢å½åç§æ·ææå·²åä»»å¡ |
| | | * |
| | | * @param taskBo åæ° |
| | | */ |
| | | @Override |
| | | public TableDataInfo<TaskVo> getPageByAllTaskFinish(TaskBo taskBo, PageQuery pageQuery) { |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | return TableDataInfo.build(page); |
| | | } |
| | | |
| | | /** |
| | | * å§æ´¾ä»»å¡ |
| | | * |
| | | * @param delegateBo åæ° |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean delegateTask(DelegateBo delegateBo) { |
| | | 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); |
| | | } |
| | | if (task.isSuspended()) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED); |
| | | } |
| | | try { |
| | | TaskEntity newTask = WorkflowUtils.createNewTask(task); |
| | | taskService.addComment(newTask.getId(), task.getProcessInstanceId(), TaskStatusEnum.PENDING.getStatus(), "ã" + LoginHelper.getLoginUser().getNickname() + "ãå§æ´¾ç»ã" + delegateBo.getNickName() + "ã"); |
| | | //å§æä»»å¡ |
| | | taskService.delegateTask(delegateBo.getTaskId(), delegateBo.getUserId()); |
| | | //åççæçä»»å¡è®°å½ |
| | | taskService.complete(newTask.getId()); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ç»æ¢ä»»å¡ |
| | | * |
| | | * @param terminationBo åæ° |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean terminationTask(TerminationBo terminationBo) { |
| | | TaskQuery query = QueryUtils.taskQuery(); |
| | | Task task = query.taskId(terminationBo.getTaskId()).singleResult(); |
| | | |
| | | if (ObjectUtil.isEmpty(task)) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); |
| | | } |
| | | if (task.isSuspended()) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED); |
| | | } |
| | | HistoricProcessInstance historicProcessInstance = QueryUtils.hisInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); |
| | | BusinessStatusEnum.checkInvalidStatus(historicProcessInstance.getBusinessStatus()); |
| | | try { |
| | | if (StringUtils.isBlank(terminationBo.getComment())) { |
| | | terminationBo.setComment(LoginHelper.getLoginUser().getNickname() + "ç»æ¢äºç³è¯·"); |
| | | } else { |
| | | terminationBo.setComment(LoginHelper.getLoginUser().getNickname() + "ç»æ¢äºç³è¯·ï¼" + terminationBo.getComment()); |
| | | } |
| | | taskService.addComment(task.getId(), task.getProcessInstanceId(), TaskStatusEnum.TERMINATION.getStatus(), terminationBo.getComment()); |
| | | List<Task> list = QueryUtils.taskQuery(task.getProcessInstanceId()).list(); |
| | | if (CollUtil.isNotEmpty(list)) { |
| | | List<Task> subTasks = StreamUtils.filter(list, e -> StringUtils.isNotBlank(e.getParentTaskId())); |
| | | if (CollUtil.isNotEmpty(subTasks)) { |
| | | subTasks.forEach(e -> taskService.deleteTask(e.getId())); |
| | | } |
| | | 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); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转åä»»å¡ |
| | | * |
| | | * @param transmitBo åæ° |
| | | */ |
| | | @Override |
| | | public boolean transferTask(TransmitBo transmitBo) { |
| | | 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); |
| | | } |
| | | if (task.isSuspended()) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED); |
| | | } |
| | | try { |
| | | TaskEntity newTask = WorkflowUtils.createNewTask(task); |
| | | taskService.addComment(newTask.getId(), task.getProcessInstanceId(), TaskStatusEnum.TRANSFER.getStatus(), StringUtils.isNotBlank(transmitBo.getComment()) ? transmitBo.getComment() : LoginHelper.getUsername() + "转åäºä»»å¡"); |
| | | taskService.complete(newTask.getId()); |
| | | taskService.setAssignee(task.getId(), transmitBo.getUserId()); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ä¼ç¾ä»»å¡å ç¾ |
| | | * |
| | | * @param addMultiBo åæ° |
| | | */ |
| | | @Override |
| | | public boolean addMultiInstanceExecution(AddMultiBo addMultiBo) { |
| | | TaskQuery taskQuery = QueryUtils.taskQuery(); |
| | | taskQuery.taskId(addMultiBo.getTaskId()); |
| | | if (!LoginHelper.isSuperAdmin() && !LoginHelper.isTenantAdmin()) { |
| | | taskQuery.taskCandidateOrAssigned(String.valueOf(LoginHelper.getUserId())); |
| | | } |
| | | Task task = taskQuery.singleResult(); |
| | | if (ObjectUtil.isEmpty(task)) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); |
| | | } |
| | | if (task.isSuspended()) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED); |
| | | } |
| | | String taskDefinitionKey = task.getTaskDefinitionKey(); |
| | | String processInstanceId = task.getProcessInstanceId(); |
| | | String processDefinitionId = task.getProcessDefinitionId(); |
| | | |
| | | try { |
| | | MultiInstanceVo multiInstanceVo = WorkflowUtils.isMultiInstance(processDefinitionId, taskDefinitionKey); |
| | | if (multiInstanceVo == null) { |
| | | throw new ServiceException("å½åç¯è䏿¯ä¼ç¾èç¹"); |
| | | } |
| | | if (multiInstanceVo.getType() instanceof ParallelMultiInstanceBehavior) { |
| | | for (Long assignee : addMultiBo.getAssignees()) { |
| | | runtimeService.addMultiInstanceExecution(taskDefinitionKey, processInstanceId, Collections.singletonMap(multiInstanceVo.getAssignee(), assignee)); |
| | | } |
| | | } else if (multiInstanceVo.getType() instanceof SequentialMultiInstanceBehavior) { |
| | | AddSequenceMultiInstanceCmd addSequenceMultiInstanceCmd = new AddSequenceMultiInstanceCmd(task.getExecutionId(), multiInstanceVo.getAssigneeList(), addMultiBo.getAssignees()); |
| | | managementService.executeCommand(addSequenceMultiInstanceCmd); |
| | | } |
| | | List<String> assigneeNames = addMultiBo.getAssigneeNames(); |
| | | String username = LoginHelper.getUsername(); |
| | | TaskEntity newTask = WorkflowUtils.createNewTask(task); |
| | | taskService.addComment(newTask.getId(), processInstanceId, TaskStatusEnum.SIGN.getStatus(), username + "å ç¾ã" + String.join(StringUtils.SEPARATOR, assigneeNames) + "ã"); |
| | | taskService.complete(newTask.getId()); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ä¼ç¾ä»»å¡åç¾ |
| | | * |
| | | * @param deleteMultiBo åæ° |
| | | */ |
| | | @Override |
| | | public boolean deleteMultiInstanceExecution(DeleteMultiBo deleteMultiBo) { |
| | | TaskQuery taskQuery = QueryUtils.taskQuery(); |
| | | taskQuery.taskId(deleteMultiBo.getTaskId()); |
| | | if (!LoginHelper.isSuperAdmin() && !LoginHelper.isTenantAdmin()) { |
| | | taskQuery.taskCandidateOrAssigned(String.valueOf(LoginHelper.getUserId())); |
| | | } |
| | | Task task = taskQuery.singleResult(); |
| | | if (ObjectUtil.isEmpty(task)) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_CURRENT_TASK_IS_NULL); |
| | | } |
| | | if (task.isSuspended()) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED); |
| | | } |
| | | String taskDefinitionKey = task.getTaskDefinitionKey(); |
| | | String processInstanceId = task.getProcessInstanceId(); |
| | | String processDefinitionId = task.getProcessDefinitionId(); |
| | | try { |
| | | MultiInstanceVo multiInstanceVo = WorkflowUtils.isMultiInstance(processDefinitionId, taskDefinitionKey); |
| | | if (multiInstanceVo == null) { |
| | | throw new ServiceException("å½åç¯è䏿¯ä¼ç¾èç¹"); |
| | | } |
| | | if (multiInstanceVo.getType() instanceof ParallelMultiInstanceBehavior) { |
| | | for (String executionId : deleteMultiBo.getExecutionIds()) { |
| | | runtimeService.deleteMultiInstanceExecution(executionId, false); |
| | | } |
| | | for (String taskId : deleteMultiBo.getTaskIds()) { |
| | | historyService.deleteHistoricTaskInstance(taskId); |
| | | } |
| | | } else if (multiInstanceVo.getType() instanceof SequentialMultiInstanceBehavior) { |
| | | DeleteSequenceMultiInstanceCmd deleteSequenceMultiInstanceCmd = new DeleteSequenceMultiInstanceCmd(task.getAssignee(), task.getExecutionId(), multiInstanceVo.getAssigneeList(), deleteMultiBo.getAssigneeIds()); |
| | | managementService.executeCommand(deleteSequenceMultiInstanceCmd); |
| | | } |
| | | List<String> assigneeNames = deleteMultiBo.getAssigneeNames(); |
| | | String username = LoginHelper.getUsername(); |
| | | TaskEntity newTask = WorkflowUtils.createNewTask(task); |
| | | taskService.addComment(newTask.getId(), processInstanceId, TaskStatusEnum.SIGN_OFF.getStatus(), username + "åç¾ã" + String.join(StringUtils.SEPARATOR, assigneeNames) + "ã"); |
| | | taskService.complete(newTask.getId()); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 驳åå®¡æ¹ |
| | | * |
| | | * @param backProcessBo åæ° |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String backProcess(BackProcessBo backProcessBo) { |
| | | TaskQuery query = QueryUtils.taskQuery(); |
| | | 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); |
| | | } |
| | | if (task.isSuspended()) { |
| | | throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED); |
| | | } |
| | | try { |
| | | String processInstanceId = task.getProcessInstanceId(); |
| | | ProcessInstance processInstance = QueryUtils.instanceQuery(task.getProcessInstanceId()).singleResult(); |
| | | //è·åå¹¶è¡ç½å
³æ§è¡åä¿ççæ§è¡å®ä¾æ°æ® |
| | | ExecutionChildByExecutionIdCmd childByExecutionIdCmd = new ExecutionChildByExecutionIdCmd(task.getExecutionId()); |
| | | List<ExecutionEntity> executionEntities = managementService.executeCommand(childByExecutionIdCmd); |
| | | //æ ¡éªåæ® |
| | | BusinessStatusEnum.checkBackStatus(processInstance.getBusinessStatus()); |
| | | //夿æ¯å¦æå¤ä¸ªä»»å¡ |
| | | List<Task> taskList = QueryUtils.taskQuery(processInstanceId).list(); |
| | | 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) { |
| | | instanceList.stream().filter(e -> e.getTaskDefinitionKey().equals(t.getTaskDefinitionKey())).findFirst().ifPresent(e -> { |
| | | taskService.setAssignee(t.getId(), e.getAssignee()); |
| | | }); |
| | | } |
| | | //åéæ¶æ¯ |
| | | String message = "æ¨çã" + processInstance.getName() + "ã忮已ç»è¢«é©³åï¼è¯·æ¨æ³¨ææ¥æ¶ã"; |
| | | sendMessage(list, processInstance.getName(), backProcessBo.getMessageType(), message); |
| | | //å 餿µç¨å®ä¾å徿°æ® |
| | | for (ExecutionEntity executionEntity : executionEntities) { |
| | | DeleteExecutionCmd deleteExecutionCmd = new DeleteExecutionCmd(executionEntity.getId()); |
| | | managementService.executeCommand(deleteExecutionCmd); |
| | | } |
| | | |
| | | 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()); |
| | | } |
| | | return task.getProcessInstanceId(); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä»»å¡åç人 |
| | | * |
| | | * @param taskIds ä»»å¡id |
| | | * @param userId åç人id |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateAssignee(String[] taskIds, String userId) { |
| | | try { |
| | | List<Task> list = QueryUtils.taskQuery().taskIds(Arrays.asList(taskIds)).list(); |
| | | for (Task task : list) { |
| | | taskService.setAssignee(task.getId(), userId); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new ServiceException("ä¿®æ¹å¤±è´¥ï¼" + e.getMessage()); |
| | | } |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢å·¥ä½æµä»»å¡ç¨æ·éæ©å ç¾äººå |
| | | * |
| | | * @param taskId ä»»å¡id |
| | | * @return |
| | | */ |
| | | @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(); |
| | | } |
| | | } |