| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.dromara.common.core.enums.BusinessStatusEnum; |
| | | 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.workflow.common.constant.FlowConstant; |
| | | import org.dromara.common.core.enums.BusinessStatusEnum; |
| | | import org.dromara.workflow.common.enums.TaskStatusEnum; |
| | | import org.dromara.workflow.domain.ActHiProcinst; |
| | | import org.dromara.workflow.domain.bo.ProcessInstanceBo; |
| | |
| | | import org.dromara.workflow.service.IWfTaskBackNodeService; |
| | | import org.dromara.workflow.utils.QueryUtils; |
| | | import org.dromara.workflow.utils.WorkflowUtils; |
| | | import org.flowable.bpmn.model.*; |
| | | import org.flowable.bpmn.model.BpmnModel; |
| | | import org.flowable.engine.*; |
| | | import org.flowable.engine.history.HistoricActivityInstance; |
| | | import org.flowable.engine.history.HistoricProcessInstance; |
| | |
| | | import org.flowable.task.api.Task; |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 流程实例 服务层实现 |
| | |
| | | @Service |
| | | public class ActProcessInstanceServiceImpl implements IActProcessInstanceService { |
| | | |
| | | private final RepositoryService repositoryService; |
| | | private final RuntimeService runtimeService; |
| | | private final HistoryService historyService; |
| | | private final TaskService taskService; |
| | | @Autowired(required = false) |
| | | private RepositoryService repositoryService; |
| | | @Autowired(required = false) |
| | | private RuntimeService runtimeService; |
| | | @Autowired(required = false) |
| | | private HistoryService historyService; |
| | | @Autowired(required = false) |
| | | private TaskService taskService; |
| | | @Autowired(required = false) |
| | | private ManagementService managementService; |
| | | private final IActHiProcinstService actHiProcinstService; |
| | | private final ManagementService managementService; |
| | | private final IWfTaskBackNodeService wfTaskBackNodeService; |
| | | private final IWfNodeConfigService wfNodeConfigService; |
| | | private final FlowProcessEventHandler flowProcessEventHandler; |
| | | private final UserService userService; |
| | | |
| | | @Value("${flowable.activity-font-name}") |
| | | private String activityFontName; |
| | |
| | | List<HistoricActivityInstance> highLightedFlowList = QueryUtils.hisActivityInstanceQuery(processInstanceId).orderByHistoricActivityInstanceStartTime().asc().list(); |
| | | for (HistoricActivityInstance tempActivity : highLightedFlowList) { |
| | | Map<String, Object> task = new HashMap<>(); |
| | | if (!FlowConstant.SEQUENCE_FLOW.equals(tempActivity.getActivityType()) && |
| | | !FlowConstant.PARALLEL_GATEWAY.equals(tempActivity.getActivityType()) && |
| | | !FlowConstant.EXCLUSIVE_GATEWAY.equals(tempActivity.getActivityType()) && |
| | | !FlowConstant.INCLUSIVE_GATEWAY.equals(tempActivity.getActivityType()) |
| | | ) { |
| | | task.put("key", tempActivity.getActivityId()); |
| | | task.put("completed", tempActivity.getEndTime() != null); |
| | | task.put("activityType", tempActivity.getActivityType()); |
| | | taskList.add(task); |
| | | switch (tempActivity.getActivityType()) { |
| | | case FlowConstant.SEQUENCE_FLOW, FlowConstant.PARALLEL_GATEWAY, |
| | | FlowConstant.EXCLUSIVE_GATEWAY, FlowConstant.INCLUSIVE_GATEWAY -> {} |
| | | default -> { |
| | | task.put("key", tempActivity.getActivityId()); |
| | | task.put("completed", tempActivity.getEndTime() != null); |
| | | task.put("activityType", tempActivity.getActivityType()); |
| | | taskList.add(task); |
| | | } |
| | | } |
| | | } |
| | | ProcessInstance processInstance = QueryUtils.instanceQuery(processInstanceId).singleResult(); |
| | | if (processInstance != null) { |
| | | taskList = taskList.stream().filter(e -> !e.get("activityType").equals(FlowConstant.END_EVENT)).collect(Collectors.toList()); |
| | | taskList = StreamUtils.filter(taskList, e -> !e.get("activityType").equals(FlowConstant.END_EVENT)); |
| | | } |
| | | //查询出运行中节点 |
| | | List<Map<String, Object>> runtimeNodeList = taskList.stream().filter(e -> !(Boolean) e.get("completed")).collect(Collectors.toList()); |
| | | List<Map<String, Object>> runtimeNodeList = StreamUtils.filter(taskList, e -> !(Boolean) e.get("completed")); |
| | | if (CollUtil.isNotEmpty(runtimeNodeList)) { |
| | | Iterator<Map<String, Object>> iterator = taskList.iterator(); |
| | | while (iterator.hasNext()) { |
| | |
| | | } |
| | | } |
| | | map.put("taskList", taskList); |
| | | List<ActHistoryInfoVo> historyTaskList = getHistoryTaskList(processInstanceId, processInstance.getProcessDefinitionVersion()); |
| | | List<ActHistoryInfoVo> historyTaskList = getHistoryTaskList(processInstanceId, processDefinition.getVersion()); |
| | | map.put("historyList", historyTaskList); |
| | | InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName()); |
| | | xml.append(IoUtil.read(inputStream, StandardCharsets.UTF_8)); |
| | |
| | | Map<String, List<ActHistoryInfoVo>> groupByKey = StreamUtils.groupByKey(actHistoryInfoVoList, ActHistoryInfoVo::getTaskDefinitionKey); |
| | | for (Map.Entry<String, List<ActHistoryInfoVo>> entry : groupByKey.entrySet()) { |
| | | ActHistoryInfoVo historyInfoVo = new ActHistoryInfoVo(); |
| | | BeanUtils.copyProperties(entry.getValue().get(0), historyInfoVo); |
| | | actHistoryInfoVoList.stream().filter(e -> e.getTaskDefinitionKey().equals(entry.getKey()) && e.getEndTime() == null).findFirst() |
| | | .ifPresent(e -> { |
| | | historyInfoVo.setStatus("待处理"); |
| | | historyInfoVo.setStartTime(e.getStartTime()); |
| | | historyInfoVo.setEndTime(null); |
| | | historyInfoVo.setRunDuration(null); |
| | | if (ObjectUtil.isEmpty(e.getAssignee())) { |
| | | ParticipantVo participantVo = WorkflowUtils.getCurrentTaskParticipant(e.getId()); |
| | | if (entry.getValue().size() > 1) { |
| | | List<ActHistoryInfoVo> historyInfoVos = StreamUtils.filter(entry.getValue(), e -> StringUtils.isNotBlank(e.getAssignee())); |
| | | if (CollUtil.isNotEmpty(historyInfoVos)) { |
| | | ActHistoryInfoVo infoVo = historyInfoVos.get(0); |
| | | BeanUtils.copyProperties(infoVo, historyInfoVo); |
| | | historyInfoVo.setStatus(infoVo.getEndTime() == null ? "待处理" : "已处理"); |
| | | historyInfoVo.setStartTime(infoVo.getStartTime()); |
| | | historyInfoVo.setEndTime(infoVo.getEndTime() == null ? null : infoVo.getEndTime()); |
| | | historyInfoVo.setRunDuration(infoVo.getEndTime() == null ? null : infoVo.getRunDuration()); |
| | | if (ObjectUtil.isEmpty(infoVo.getAssignee())) { |
| | | ParticipantVo participantVo = WorkflowUtils.getCurrentTaskParticipant(infoVo.getId(), userService); |
| | | if (ObjectUtil.isNotEmpty(participantVo) && CollUtil.isNotEmpty(participantVo.getCandidate())) { |
| | | historyInfoVo.setAssignee(StreamUtils.join(participantVo.getCandidate(), Convert::toStr)); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } else { |
| | | actHistoryInfoVoList.stream().filter(e -> e.getTaskDefinitionKey().equals(entry.getKey())).findFirst() |
| | | .ifPresent(e -> { |
| | | BeanUtils.copyProperties(e, historyInfoVo); |
| | | historyInfoVo.setStatus(e.getEndTime() == null ? "待处理" : "已处理"); |
| | | historyInfoVo.setStartTime(e.getStartTime()); |
| | | historyInfoVo.setEndTime(e.getEndTime() == null ? null : e.getEndTime()); |
| | | historyInfoVo.setRunDuration(e.getEndTime() == null ? null : e.getRunDuration()); |
| | | if (ObjectUtil.isEmpty(e.getAssignee())) { |
| | | ParticipantVo participantVo = WorkflowUtils.getCurrentTaskParticipant(e.getId(), userService); |
| | | if (ObjectUtil.isNotEmpty(participantVo) && CollUtil.isNotEmpty(participantVo.getCandidate())) { |
| | | historyInfoVo.setAssignee(StreamUtils.join(participantVo.getCandidate(), Convert::toStr)); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | historyInfoVoList.add(historyInfoVo); |
| | | |
| | | } |
| | | return historyInfoVoList; |
| | | } |
| | |
| | | } |
| | | //附件 |
| | | if (CollUtil.isNotEmpty(attachmentList)) { |
| | | List<Attachment> attachments = attachmentList.stream().filter(e -> e.getTaskId().equals(historicTaskInstance.getId())).collect(Collectors.toList()); |
| | | List<Attachment> attachments = StreamUtils.filter(attachmentList, e -> e.getTaskId().equals(historicTaskInstance.getId())); |
| | | if (CollUtil.isNotEmpty(attachments)) { |
| | | actHistoryInfoVo.setAttachmentList(attachments); |
| | | } |
| | | } |
| | | //设置人员id |
| | | if (ObjectUtil.isEmpty(historicTaskInstance.getAssignee())) { |
| | | ParticipantVo participantVo = WorkflowUtils.getCurrentTaskParticipant(historicTaskInstance.getId()); |
| | | ParticipantVo participantVo = WorkflowUtils.getCurrentTaskParticipant(historicTaskInstance.getId(), userService); |
| | | if (ObjectUtil.isNotEmpty(participantVo) && CollUtil.isNotEmpty(participantVo.getCandidate())) { |
| | | actHistoryInfoVo.setAssignee(StreamUtils.join(participantVo.getCandidate(), Convert::toStr)); |
| | | } |
| | |
| | | historicProcessInstance.getBusinessKey(), BusinessStatusEnum.INVALID.getStatus(), false); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(e.getMessage(), e); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | |
| | | wfTaskBackNodeService.deleteByInstanceIds(processInstanceIds); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(e.getMessage(), e); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | |
| | | wfTaskBackNodeService.deleteByInstanceIds(processInstanceIds); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error(e.getMessage(), e); |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | |
| | | processInstance.getBusinessKey(), BusinessStatusEnum.CANCEL.getStatus(), false); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("撤销失败:" + e.getMessage(), e); |
| | | throw new ServiceException("撤销失败:" + e.getMessage()); |
| | | } |
| | | } |
| | |
| | | message = "您的【" + processInstance.getName() + "】单据还未审批,请您及时处理。"; |
| | | } |
| | | List<Task> list = QueryUtils.taskQuery(taskUrgingBo.getProcessInstanceId()).list(); |
| | | WorkflowUtils.sendMessage(list, processInstance.getName(), taskUrgingBo.getMessageType(), message); |
| | | WorkflowUtils.sendMessage(list, processInstance.getName(), taskUrgingBo.getMessageType(), message, userService); |
| | | } catch (ServiceException e) { |
| | | throw new ServiceException(e.getMessage()); |
| | | } |