Search in sources :

Example 1 with HistoricActivityInstanceQuery

use of org.flowable.engine.history.HistoricActivityInstanceQuery in project RuoYi-Flowable-Plus by KonBAI-Q.

the class WfTaskServiceImpl method getFlowViewer.

/**
 * 获取流程执行过程
 *
 * @param procInsId
 * @return
 */
@Override
public WfViewerVo getFlowViewer(String procInsId) {
    // 构建查询条件
    HistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery().processInstanceId(procInsId);
    List<HistoricActivityInstance> allActivityInstanceList = query.list();
    if (CollUtil.isEmpty(allActivityInstanceList)) {
        return new WfViewerVo();
    }
    // 获取流程发布Id信息
    String processDefinitionId = allActivityInstanceList.get(0).getProcessDefinitionId();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
    if (ObjectUtil.isNull(bpmnModel)) {
        throw new ServiceException("流程模型不存在");
    }
    Map<String, List<String>> sequenceElementMap = new HashMap<>();
    Map<String, String> sequenceFlowMap = new HashMap<>();
    Collection<FlowElement> flowElements = bpmnModel.getMainProcess().getFlowElements();
    for (FlowElement flowElement : flowElements) {
        if (flowElement instanceof SequenceFlow) {
            SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
            String sourceRef = sequenceFlow.getSourceRef();
            String targetRef = sequenceFlow.getTargetRef();
            List<String> targetRefList = sequenceElementMap.get(sourceRef);
            if (CollUtil.isEmpty(targetRefList)) {
                sequenceElementMap.put(sourceRef, ListUtil.toList(targetRef));
            } else {
                targetRefList.add(targetRef);
            }
            sequenceFlowMap.put(sourceRef + targetRef, sequenceFlow.getId());
        }
    }
    // 查询所有已完成的元素
    List<HistoricActivityInstance> finishedElementList = allActivityInstanceList.stream().filter(item -> ObjectUtil.isNotNull(item.getEndTime())).collect(Collectors.toList());
    // 所有已完成的连线
    Set<String> finishedSequenceFlowSet = new HashSet<>();
    // 所有已完成的任务节点
    Set<String> finishedTaskSet = new HashSet<>();
    finishedElementList.forEach(item -> {
        if ("sequenceFlow".equals(item.getActivityType())) {
            finishedSequenceFlowSet.add(item.getActivityId());
        } else {
            finishedTaskSet.add(item.getActivityId());
        }
    });
    // 查询所有未结束的节点
    Set<String> unfinishedTaskSet = allActivityInstanceList.stream().filter(item -> ObjectUtil.isNull(item.getEndTime())).map(HistoricActivityInstance::getActivityId).collect(Collectors.toSet());
    Set<String> rejectedTaskSet = new LinkedHashSet<>();
    Set<String> sourceTaskSet = unfinishedTaskSet;
    while (CollUtil.isNotEmpty(sourceTaskSet)) {
        Set<String> nextIdSet = new HashSet<>();
        for (String previousId : sourceTaskSet) {
            List<String> nextIdList = sequenceElementMap.get(previousId);
            if (CollUtil.isEmpty(nextIdList)) {
                continue;
            }
            nextIdList.forEach(nextId -> {
                if (finishedTaskSet.contains(nextId)) {
                    nextIdSet.add(nextId);
                    String rejectedSequenceFlow = sequenceFlowMap.get(previousId + nextId);
                    if (finishedSequenceFlowSet.contains(rejectedSequenceFlow)) {
                        nextIdSet.add(rejectedSequenceFlow);
                    }
                }
            });
        }
        rejectedTaskSet.addAll(nextIdSet);
        sourceTaskSet = nextIdSet;
    }
    return new WfViewerVo(finishedTaskSet, finishedSequenceFlowSet, unfinishedTaskSet, rejectedTaskSet);
}
Also used : JsonUtils(com.ruoyi.common.utils.JsonUtils) ProcessDiagramGenerator(org.flowable.image.ProcessDiagramGenerator) ServiceException(com.ruoyi.common.exception.ServiceException) WfFormVo(com.ruoyi.workflow.domain.vo.WfFormVo) ListUtil(cn.hutool.core.collection.ListUtil) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ProcessEngineConfiguration(org.flowable.engine.ProcessEngineConfiguration) StringUtils(org.apache.commons.lang3.StringUtils) WfNextDto(com.ruoyi.workflow.domain.dto.WfNextDto) HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) IWfTaskService(com.ruoyi.workflow.service.IWfTaskService) Authentication(org.flowable.common.engine.impl.identity.Authentication) WfTaskVo(com.ruoyi.workflow.domain.vo.WfTaskVo) org.flowable.bpmn.model(org.flowable.bpmn.model) Comment(org.flowable.engine.task.Comment) Predicate(java.util.function.Predicate) FlowComment(com.ruoyi.flowable.common.enums.FlowComment) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Deployment(org.flowable.engine.repository.Deployment) Task(org.flowable.task.api.Task) LoginHelper(com.ruoyi.common.helper.LoginHelper) CustomProcessDiagramGenerator(com.ruoyi.flowable.flow.CustomProcessDiagramGenerator) WfViewerVo(com.ruoyi.workflow.domain.vo.WfViewerVo) Process(org.flowable.bpmn.model.Process) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) FlowableUtils(com.ruoyi.flowable.flow.FlowableUtils) FlowableObjectNotFoundException(org.flowable.common.engine.api.FlowableObjectNotFoundException) HistoricTaskInstanceQuery(org.flowable.task.api.history.HistoricTaskInstanceQuery) HistoricIdentityLink(org.flowable.identitylink.api.history.HistoricIdentityLink) R(com.ruoyi.common.core.domain.R) java.util(java.util) SysUser(com.ruoyi.common.core.domain.entity.SysUser) TableDataInfo(com.ruoyi.common.core.page.TableDataInfo) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) ObjectUtil(cn.hutool.core.util.ObjectUtil) TaskQuery(org.flowable.task.api.TaskQuery) WfTaskBo(com.ruoyi.workflow.domain.bo.WfTaskBo) IWfDeployFormService(com.ruoyi.workflow.service.IWfDeployFormService) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) PageQuery(com.ruoyi.common.core.domain.PageQuery) FlowableException(org.flowable.common.engine.api.FlowableException) DelegationState(org.flowable.task.api.DelegationState) Execution(org.flowable.engine.runtime.Execution) HistoricActivityInstanceQuery(org.flowable.engine.history.HistoricActivityInstanceQuery) Lists(com.google.common.collect.Lists) ProcessConstants(com.ruoyi.flowable.common.constant.ProcessConstants) Service(org.springframework.stereotype.Service) ISysRoleService(com.ruoyi.system.service.ISysRoleService) FindNextNodeUtil(com.ruoyi.flowable.flow.FindNextNodeUtil) FlowServiceFactory(com.ruoyi.flowable.factory.FlowServiceFactory) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance) WfCommentDto(com.ruoyi.workflow.domain.dto.WfCommentDto) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) CollUtil(cn.hutool.core.collection.CollUtil) ISysUserService(com.ruoyi.system.service.ISysUserService) SysRole(com.ruoyi.common.core.domain.entity.SysRole) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) Transactional(org.springframework.transaction.annotation.Transactional) InputStream(java.io.InputStream) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HistoricActivityInstanceQuery(org.flowable.engine.history.HistoricActivityInstanceQuery) ServiceException(com.ruoyi.common.exception.ServiceException) WfViewerVo(com.ruoyi.workflow.domain.vo.WfViewerVo) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance)

Aggregations

CollUtil (cn.hutool.core.collection.CollUtil)1 ListUtil (cn.hutool.core.collection.ListUtil)1 ObjectUtil (cn.hutool.core.util.ObjectUtil)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 Lists (com.google.common.collect.Lists)1 PageQuery (com.ruoyi.common.core.domain.PageQuery)1 R (com.ruoyi.common.core.domain.R)1 SysRole (com.ruoyi.common.core.domain.entity.SysRole)1 SysUser (com.ruoyi.common.core.domain.entity.SysUser)1 TableDataInfo (com.ruoyi.common.core.page.TableDataInfo)1 ServiceException (com.ruoyi.common.exception.ServiceException)1 LoginHelper (com.ruoyi.common.helper.LoginHelper)1 JsonUtils (com.ruoyi.common.utils.JsonUtils)1 ProcessConstants (com.ruoyi.flowable.common.constant.ProcessConstants)1 FlowComment (com.ruoyi.flowable.common.enums.FlowComment)1 FlowServiceFactory (com.ruoyi.flowable.factory.FlowServiceFactory)1 CustomProcessDiagramGenerator (com.ruoyi.flowable.flow.CustomProcessDiagramGenerator)1 FindNextNodeUtil (com.ruoyi.flowable.flow.FindNextNodeUtil)1 FlowableUtils (com.ruoyi.flowable.flow.FlowableUtils)1 ISysRoleService (com.ruoyi.system.service.ISysRoleService)1