| | |
| | | import org.dromara.workflow.common.enums.TaskStatusEnum; |
| | | import org.dromara.workflow.domain.ActHiProcinst; |
| | | import org.dromara.workflow.domain.ActHiTaskinst; |
| | | import org.dromara.workflow.domain.vo.MultiInstanceVo; |
| | | import org.dromara.workflow.domain.vo.ParticipantVo; |
| | | import org.dromara.workflow.domain.vo.ProcessInstanceVo; |
| | | import org.dromara.workflow.domain.vo.*; |
| | | import org.dromara.workflow.flowable.cmd.UpdateHiTaskInstCmd; |
| | | import org.dromara.workflow.mapper.ActHiTaskinstMapper; |
| | | import org.dromara.workflow.service.IActHiProcinstService; |
| | | import org.dromara.workflow.service.IWorkflowUserService; |
| | | import org.dromara.workflow.service.*; |
| | | import org.flowable.bpmn.model.BpmnModel; |
| | | import org.flowable.bpmn.model.FlowNode; |
| | | import org.flowable.common.engine.api.delegate.Expression; |
| | |
| | | |
| | | import java.util.*; |
| | | |
| | | import static org.dromara.workflow.common.constant.FlowConstant.PROCESS_INSTANCE_VO; |
| | | import static org.dromara.workflow.common.constant.FlowConstant.*; |
| | | |
| | | /** |
| | | * 工作流工具 |
| | |
| | | private static final IWorkflowUserService WORKFLOW_USER_SERVICE = SpringUtils.getBean(IWorkflowUserService.class); |
| | | private static final IActHiProcinstService ACT_HI_PROCINST_SERVICE = SpringUtils.getBean(IActHiProcinstService.class); |
| | | private static final ActHiTaskinstMapper ACT_HI_TASKINST_MAPPER = SpringUtils.getBean(ActHiTaskinstMapper.class); |
| | | private static final IWfDefinitionConfigService I_WF_DEFINITION_CONFIG_SERVICE = SpringUtils.getBean(IWfDefinitionConfigService.class); |
| | | private static final IWfFormManageService I_WF_FORM_MANAGE_SERVICE = SpringUtils.getBean(IWfFormManageService.class); |
| | | |
| | | /** |
| | | * 创建一个新任务 |
| | |
| | | */ |
| | | public static void createCopyTask(List<Task> parentTaskList, List<Long> userIds) { |
| | | List<Task> list = new ArrayList<>(); |
| | | String tenantId = TenantHelper.getTenantId(); |
| | | for (Task parentTask : parentTaskList) { |
| | | for (Long userId : userIds) { |
| | | TaskEntity newTask = (TaskEntity) PROCESS_ENGINE.getTaskService().newTask(); |
| | |
| | | newTask.setProcessDefinitionId(parentTask.getProcessDefinitionId()); |
| | | newTask.setProcessInstanceId(parentTask.getProcessInstanceId()); |
| | | newTask.setTaskDefinitionKey(parentTask.getTaskDefinitionKey()); |
| | | newTask.setTenantId(TenantHelper.getTenantId()); |
| | | newTask.setTenantId(tenantId); |
| | | list.add(newTask); |
| | | } |
| | | } |
| | |
| | | actHiTaskinst.setProcDefId(processDefinitionId); |
| | | actHiTaskinst.setProcInstId(processInstanceId); |
| | | actHiTaskinst.setScopeType(TaskStatusEnum.COPY.getStatus()); |
| | | actHiTaskinst.setTenantId(TenantHelper.getTenantId()); |
| | | actHiTaskinst.setTenantId(tenantId); |
| | | LambdaUpdateWrapper<ActHiTaskinst> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.in(ActHiTaskinst::getId, taskIds); |
| | | ACT_HI_TASKINST_MAPPER.update(actHiTaskinst, updateWrapper); |
| | |
| | | } |
| | | } else { |
| | | List<HistoricIdentityLink> candidateList = StreamUtils.filter(linksForTask, e -> FlowConstant.CANDIDATE.equals(e.getType())); |
| | | List<Long> userIdList = StreamUtils.toList(linksForTask, e -> Long.valueOf(e.getUserId())); |
| | | List<Long> userIdList = new ArrayList<>(); |
| | | for (HistoricIdentityLink historicIdentityLink : linksForTask) { |
| | | try { |
| | | userIdList.add(Long.valueOf(historicIdentityLink.getUserId())); |
| | | } catch (NumberFormatException ignored) { |
| | | |
| | | } |
| | | } |
| | | List<SysUserVo> sysUsers = WORKFLOW_USER_SERVICE.getUserListByIds(userIdList); |
| | | if (CollUtil.isNotEmpty(sysUsers)) { |
| | | List<Long> userIds = StreamUtils.toList(sysUsers, SysUserVo::getUserId); |
| | | List<String> nickNames = StreamUtils.toList(sysUsers, SysUserVo::getNickName); |
| | | participantVo.setCandidate(userIds); |
| | | participantVo.setCandidateName(nickNames); |
| | | if (StringUtils.isBlank(task.getAssignee()) && CollUtil.isNotEmpty(candidateList)) { |
| | | participantVo.setClaim(false); |
| | | } |
| | | if (!StringUtils.isBlank(task.getAssignee()) && CollUtil.isNotEmpty(candidateList)) { |
| | | participantVo.setClaim(true); |
| | | // 判断当前任务是否具有多个办理人 |
| | | if (CollUtil.isNotEmpty(candidateList) && candidateList.size() > 1) { |
| | | // 如果 assignee 存在,则设置当前任务已经被认领 |
| | | participantVo.setClaim(StringUtils.isNotBlank(task.getAssignee())); |
| | | } |
| | | } |
| | | } |
| | |
| | | * @param businessKey 业务id |
| | | */ |
| | | public static void setProcessInstanceVo(Object obj, String businessKey) { |
| | | if (StringUtils.isBlank(businessKey)) { |
| | | if (StringUtils.isBlank(businessKey) || obj == null) { |
| | | return; |
| | | } |
| | | ActHiProcinst actHiProcinst = ACT_HI_PROCINST_SERVICE.selectByBusinessKey(businessKey); |
| | |
| | | * @param fieldName 主键属性名称 |
| | | */ |
| | | public static void setProcessInstanceListVo(Object obj, List<String> idList, String fieldName) { |
| | | if (CollUtil.isEmpty(idList)) { |
| | | if (CollUtil.isEmpty(idList) || obj == null) { |
| | | return; |
| | | } |
| | | List<ActHiProcinst> actHiProcinstList = ACT_HI_PROCINST_SERVICE.selectByBusinessKeyIn(idList); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置流程流程定义配置 |
| | | * |
| | | * @param obj 业务对象 |
| | | * @param idList 流程定义id |
| | | * @param fieldName 流程定义ID属性名称 |
| | | */ |
| | | public static void setWfDefinitionConfigVo(Object obj, List<String> idList, String fieldName) { |
| | | if (CollUtil.isEmpty(idList) || obj == null) { |
| | | return; |
| | | } |
| | | List<WfDefinitionConfigVo> wfDefinitionConfigVoList = I_WF_DEFINITION_CONFIG_SERVICE.queryList(idList); |
| | | if (CollUtil.isNotEmpty(wfDefinitionConfigVoList)) { |
| | | List<Long> formIds = StreamUtils.toList(wfDefinitionConfigVoList, WfDefinitionConfigVo::getFormId); |
| | | List<WfFormManageVo> wfFormManageVos = I_WF_FORM_MANAGE_SERVICE.queryByIds(formIds); |
| | | if (CollUtil.isNotEmpty(wfFormManageVos)) { |
| | | for (WfDefinitionConfigVo wfDefinitionConfigVo : wfDefinitionConfigVoList) { |
| | | wfFormManageVos.stream().filter(e -> ObjectUtil.equals(wfDefinitionConfigVo.getFormId(), e.getId())).findFirst().ifPresent(wfDefinitionConfigVo::setWfFormManageVo); |
| | | } |
| | | } |
| | | } |
| | | if (obj instanceof Collection<?> collection) { |
| | | for (Object o : collection) { |
| | | String fieldValue = ReflectUtils.invokeGetter(o, fieldName).toString(); |
| | | if (!CollUtil.isEmpty(wfDefinitionConfigVoList)) { |
| | | wfDefinitionConfigVoList.stream().filter(e -> e.getDefinitionId().equals(fieldValue)).findFirst().ifPresent(e -> { |
| | | ReflectUtils.invokeSetter(o, WF_DEFINITION_CONFIG_VO, BeanUtil.toBean(e, WfDefinitionConfigVo.class)); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发送消息 |
| | |
| | | if (CollUtil.isNotEmpty(userIds)) { |
| | | List<SysUserVo> sysUserVoList = WORKFLOW_USER_SERVICE.getUserListByIds(new ArrayList<>(userIds)); |
| | | for (String code : messageType) { |
| | | if (code.equals(MessageTypeEnum.SYSTEM_MESSAGE.getCode())) { |
| | | WebSocketMessageDto dto = new WebSocketMessageDto(); |
| | | dto.setSessionKeys(new ArrayList<>(userIds)); |
| | | dto.setMessage(message); |
| | | WebSocketUtils.publishMessage(dto); |
| | | } |
| | | if (code.equals(MessageTypeEnum.EMAIL_MESSAGE.getCode())) { |
| | | MailUtils.sendText(StreamUtils.join(sysUserVoList, SysUserVo::getEmail), "单据审批提醒", message); |
| | | } |
| | | if (code.equals(MessageTypeEnum.SMS_MESSAGE.getCode())) { |
| | | //todo 短信发送 |
| | | MessageTypeEnum messageTypeEnum = MessageTypeEnum.getByCode(code); |
| | | if (ObjectUtil.isNotEmpty(messageTypeEnum)) { |
| | | switch (messageTypeEnum) { |
| | | case SYSTEM_MESSAGE: |
| | | WebSocketMessageDto dto = new WebSocketMessageDto(); |
| | | dto.setSessionKeys(new ArrayList<>(userIds)); |
| | | dto.setMessage(message); |
| | | WebSocketUtils.publishMessage(dto); |
| | | break; |
| | | case EMAIL_MESSAGE: |
| | | MailUtils.sendText(StreamUtils.join(sysUserVoList, SysUserVo::getEmail), "单据审批提醒", message); |
| | | break; |
| | | case SMS_MESSAGE: |
| | | //todo 短信发送 |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |