Search in sources :

Example 1 with ProcessDefinitionQuery

use of org.flowable.engine.repository.ProcessDefinitionQuery in project petals-se-flowable by petalslink.

the class GetProcessInstancesOperation method searchProcessInstances.

/**
 * Search process instances that are not ended (in state 'active' or 'suspended').
 */
private GetProcessInstancesResponse searchProcessInstances(final GetProcessInstances incomingObject, final ProcessInstanceState state) throws MessagingException {
    final ProcessInstanceQuery processInstanceQuery = this.runtimeService.createProcessInstanceQuery();
    if (state == ProcessInstanceState.ACTIVE) {
        processInstanceQuery.active();
    } else if (state == ProcessInstanceState.SUSPENDED) {
        processInstanceQuery.suspended();
    } else {
        // we search all process instances independently of their state: ACTIVE and SUSPENDED
        assert state == null;
    }
    final String processDefinitionId = incomingObject.getProcessDefinitionIdentifier();
    if (processDefinitionId != null && !processDefinitionId.isEmpty()) {
        processInstanceQuery.processDefinitionKey(processDefinitionId);
    }
    final String processInstanceId = incomingObject.getProcessInstanceIdentifier();
    if (processInstanceId != null && !processInstanceId.isEmpty()) {
        processInstanceQuery.processInstanceId(processInstanceId);
    }
    final Variables variables = incomingObject.getVariables();
    if (variables != null && !variables.getVariable().isEmpty()) {
        for (final Variable variable : variables.getVariable()) {
            processInstanceQuery.variableValueEquals(variable.getName(), Utils.parseVariableValue(variable));
        }
    }
    processInstanceQuery.includeProcessVariables();
    final GetProcessInstancesResponse response = new GetProcessInstancesResponse();
    final ProcessInstances responseProcessInstances = new ProcessInstances();
    response.setProcessInstances(responseProcessInstances);
    final List<ProcessInstance> processInstances = processInstanceQuery.list();
    for (final ProcessInstance processInstance : processInstances) {
        final org.ow2.petals.components.flowable.generic._1.ProcessInstance responseProcessInstance = new org.ow2.petals.components.flowable.generic._1.ProcessInstance();
        responseProcessInstances.getProcessInstance().add(responseProcessInstance);
        responseProcessInstance.setProcessInstanceIdentifier(processInstance.getProcessInstanceId());
        if (processInstance.isSuspended()) {
            responseProcessInstance.setState(ProcessInstanceState.SUSPENDED);
        } else if (processInstance.isEnded()) {
            responseProcessInstance.setState(ProcessInstanceState.FINISHED);
        } else {
            responseProcessInstance.setState(ProcessInstanceState.ACTIVE);
        }
        final ProcessDefinitionQuery processDefQuery = this.repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId());
        final ProcessDefinition processDefinition = processDefQuery.singleResult();
        responseProcessInstance.setProcessDefinitionIdentifier(processDefinition.getKey());
        responseProcessInstance.setVariables(Utils.buildVariables(processInstance.getProcessVariables(), this.log));
    }
    return response;
}
Also used : Variable(org.ow2.petals.components.flowable.generic._1.Variable) GetProcessInstancesResponse(org.ow2.petals.components.flowable.generic._1.GetProcessInstancesResponse) ProcessDefinitionQuery(org.flowable.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) Variables(org.ow2.petals.components.flowable.generic._1.Variables) ProcessInstances(org.ow2.petals.components.flowable.generic._1.ProcessInstances) GetProcessInstances(org.ow2.petals.components.flowable.generic._1.GetProcessInstances) ProcessInstanceQuery(org.flowable.engine.runtime.ProcessInstanceQuery) HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance)

Example 2 with ProcessDefinitionQuery

use of org.flowable.engine.repository.ProcessDefinitionQuery in project ruoyi-vue-pro by YunaiV.

the class BpmProcessDefinitionServiceImpl method getProcessDefinitionList.

@Override
public List<BpmProcessDefinitionRespVO> getProcessDefinitionList(BpmProcessDefinitionListReqVO listReqVO) {
    // 拼接查询条件
    ProcessDefinitionQuery definitionQuery = repositoryService.createProcessDefinitionQuery();
    if (Objects.equals(SuspensionState.SUSPENDED.getStateCode(), listReqVO.getSuspensionState())) {
        definitionQuery.suspended();
    } else if (Objects.equals(SuspensionState.ACTIVE.getStateCode(), listReqVO.getSuspensionState())) {
        definitionQuery.active();
    }
    // 执行查询
    List<ProcessDefinition> processDefinitions = definitionQuery.list();
    // 获得 BpmProcessDefinitionDO Map
    List<BpmProcessDefinitionExtDO> processDefinitionDOs = processDefinitionMapper.selectListByProcessDefinitionIds(convertList(processDefinitions, ProcessDefinition::getId));
    Map<String, BpmProcessDefinitionExtDO> processDefinitionDOMap = convertMap(processDefinitionDOs, BpmProcessDefinitionExtDO::getProcessDefinitionId);
    // 执行查询,并返回
    return BpmProcessDefinitionConvert.INSTANCE.convertList3(processDefinitions, processDefinitionDOMap);
}
Also used : ProcessDefinitionQuery(org.flowable.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) BpmProcessDefinitionExtDO(cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO)

Example 3 with ProcessDefinitionQuery

use of org.flowable.engine.repository.ProcessDefinitionQuery in project RuoYi-Flowable-Plus by KonBAI-Q.

the class WfDefinitionServiceImpl method publishList.

@Override
public TableDataInfo<WfDefinitionVo> publishList(String processKey, PageQuery pageQuery) {
    Page<WfDefinitionVo> page = new Page<>();
    // 创建查询条件
    ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().processDefinitionKey(processKey).orderByProcessDefinitionVersion().asc();
    long pageTotal = processDefinitionQuery.count();
    if (pageTotal <= 0) {
        return TableDataInfo.build();
    }
    // 根据查询条件,查询所有版本
    int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
    List<ProcessDefinition> processDefinitionList = processDefinitionQuery.listPage(offset, pageQuery.getPageSize());
    List<WfDefinitionVo> definitionVoList = processDefinitionList.stream().map(item -> {
        WfDefinitionVo vo = new WfDefinitionVo();
        vo.setDefinitionId(item.getId());
        vo.setProcessKey(item.getKey());
        vo.setProcessName(item.getName());
        vo.setVersion(item.getVersion());
        vo.setCategory(item.getCategory());
        vo.setDeploymentId(item.getDeploymentId());
        vo.setSuspended(item.isSuspended());
        // BeanUtil.copyProperties(item, vo);
        return vo;
    }).collect(Collectors.toList());
    page.setRecords(definitionVoList);
    page.setTotal(pageTotal);
    return TableDataInfo.build(page);
}
Also used : java.util(java.util) TableDataInfo(com.ruoyi.common.core.page.TableDataInfo) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) ServiceException(com.ruoyi.common.exception.ServiceException) WfFormVo(com.ruoyi.workflow.domain.vo.WfFormVo) RequiredArgsConstructor(lombok.RequiredArgsConstructor) DeploymentBuilder(org.flowable.engine.repository.DeploymentBuilder) IWfDeployFormService(com.ruoyi.workflow.service.IWfDeployFormService) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) PageQuery(com.ruoyi.common.core.domain.PageQuery) IWfDefinitionService(com.ruoyi.workflow.service.IWfDefinitionService) ProcessConstants(com.ruoyi.flowable.common.constant.ProcessConstants) Service(org.springframework.stereotype.Service) BpmnModel(org.flowable.bpmn.model.BpmnModel) FlowServiceFactory(com.ruoyi.flowable.factory.FlowServiceFactory) DefaultProcessDiagramGenerator(org.flowable.image.impl.DefaultProcessDiagramGenerator) ProcessDefinitionQuery(org.flowable.engine.repository.ProcessDefinitionQuery) WfDefinitionVo(com.ruoyi.workflow.domain.vo.WfDefinitionVo) FlowComment(com.ruoyi.flowable.common.enums.FlowComment) IOException(java.io.IOException) Deployment(org.flowable.engine.repository.Deployment) Task(org.flowable.task.api.Task) LoginHelper(com.ruoyi.common.helper.LoginHelper) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IOUtils(org.apache.commons.io.IOUtils) StrUtil(cn.hutool.core.util.StrUtil) Slf4j(lombok.extern.slf4j.Slf4j) Transactional(org.springframework.transaction.annotation.Transactional) InputStream(java.io.InputStream) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) ProcessDefinitionQuery(org.flowable.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) WfDefinitionVo(com.ruoyi.workflow.domain.vo.WfDefinitionVo)

Example 4 with ProcessDefinitionQuery

use of org.flowable.engine.repository.ProcessDefinitionQuery in project RuoYi-Flowable-Plus by KonBAI-Q.

the class WfProcessServiceImpl method processList.

/**
 * 流程定义列表
 *
 * @param pageQuery 分页参数
 * @return 流程定义分页列表数据
 */
@Override
public TableDataInfo<WfDefinitionVo> processList(PageQuery pageQuery) {
    Page<WfDefinitionVo> page = new Page<>();
    // 流程定义列表数据查询
    ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().latestVersion().active().orderByProcessDefinitionKey().asc();
    long pageTotal = processDefinitionQuery.count();
    if (pageTotal <= 0) {
        return TableDataInfo.build();
    }
    int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
    List<ProcessDefinition> definitionList = processDefinitionQuery.listPage(offset, pageQuery.getPageSize());
    List<WfDefinitionVo> definitionVoList = new ArrayList<>();
    for (ProcessDefinition processDefinition : definitionList) {
        String deploymentId = processDefinition.getDeploymentId();
        Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
        WfDefinitionVo vo = new WfDefinitionVo();
        vo.setDefinitionId(processDefinition.getId());
        vo.setProcessKey(processDefinition.getKey());
        vo.setProcessName(processDefinition.getName());
        vo.setVersion(processDefinition.getVersion());
        vo.setCategory(processDefinition.getCategory());
        vo.setDeploymentId(processDefinition.getDeploymentId());
        vo.setSuspended(processDefinition.isSuspended());
        // 流程定义时间
        vo.setCategory(deployment.getCategory());
        vo.setDeploymentTime(deployment.getDeploymentTime());
        definitionVoList.add(vo);
    }
    page.setRecords(definitionVoList);
    page.setTotal(pageTotal);
    return TableDataInfo.build(page);
}
Also used : ArrayList(java.util.ArrayList) Deployment(org.flowable.engine.repository.Deployment) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) ProcessDefinitionQuery(org.flowable.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) WfDefinitionVo(com.ruoyi.workflow.domain.vo.WfDefinitionVo)

Example 5 with ProcessDefinitionQuery

use of org.flowable.engine.repository.ProcessDefinitionQuery in project ruoyi-vue-pro by YunaiV.

the class BpmProcessDefinitionServiceImpl method getProcessDefinitionPage.

@Override
public PageResult<BpmProcessDefinitionPageItemRespVO> getProcessDefinitionPage(BpmProcessDefinitionPageReqVO pageVO) {
    ProcessDefinitionQuery definitionQuery = repositoryService.createProcessDefinitionQuery();
    if (StrUtil.isNotBlank(pageVO.getKey())) {
        definitionQuery.processDefinitionKey(pageVO.getKey());
    }
    // 执行查询
    List<ProcessDefinition> processDefinitions = definitionQuery.orderByProcessDefinitionVersion().desc().listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
    if (CollUtil.isEmpty(processDefinitions)) {
        return new PageResult<>(emptyList(), definitionQuery.count());
    }
    // 获得 Deployment Map
    Set<String> deploymentIds = new HashSet<>();
    processDefinitions.forEach(definition -> addIfNotNull(deploymentIds, definition.getDeploymentId()));
    Map<String, Deployment> deploymentMap = getDeploymentMap(deploymentIds);
    // 获得 BpmProcessDefinitionDO Map
    List<BpmProcessDefinitionExtDO> processDefinitionDOs = processDefinitionMapper.selectListByProcessDefinitionIds(convertList(processDefinitions, ProcessDefinition::getId));
    Map<String, BpmProcessDefinitionExtDO> processDefinitionDOMap = convertMap(processDefinitionDOs, BpmProcessDefinitionExtDO::getProcessDefinitionId);
    // 获得 Form Map
    Set<Long> formIds = convertSet(processDefinitionDOs, BpmProcessDefinitionExtDO::getFormId);
    Map<Long, BpmFormDO> formMap = formService.getFormMap(formIds);
    // 拼接结果
    long definitionCount = definitionQuery.count();
    return new PageResult<>(BpmProcessDefinitionConvert.INSTANCE.convertList(processDefinitions, deploymentMap, processDefinitionDOMap, formMap), definitionCount);
}
Also used : Deployment(org.flowable.engine.repository.Deployment) ProcessDefinitionQuery(org.flowable.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) BpmProcessDefinitionExtDO(cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO) PageResult(cn.iocoder.yudao.framework.common.pojo.PageResult) BpmFormDO(cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO)

Aggregations

ProcessDefinitionQuery (org.flowable.engine.repository.ProcessDefinitionQuery)9 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)8 Deployment (org.flowable.engine.repository.Deployment)4 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)3 WfDefinitionVo (com.ruoyi.workflow.domain.vo.WfDefinitionVo)3 ProcessInstance (org.flowable.engine.runtime.ProcessInstance)3 BpmProcessDefinitionExtDO (cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO)2 WfFormVo (com.ruoyi.workflow.domain.vo.WfFormVo)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 HistoricProcessInstance (org.flowable.engine.history.HistoricProcessInstance)2 HistoricProcessInstanceQuery (org.flowable.engine.history.HistoricProcessInstanceQuery)2 Task (org.flowable.task.api.Task)2 GetProcessInstances (org.ow2.petals.components.flowable.generic._1.GetProcessInstances)2 GetProcessInstancesResponse (org.ow2.petals.components.flowable.generic._1.GetProcessInstancesResponse)2 ProcessInstances (org.ow2.petals.components.flowable.generic._1.ProcessInstances)2 Variable (org.ow2.petals.components.flowable.generic._1.Variable)2 Variables (org.ow2.petals.components.flowable.generic._1.Variables)2 StrUtil (cn.hutool.core.util.StrUtil)1 PageResult (cn.iocoder.yudao.framework.common.pojo.PageResult)1