| | |
| | | import org.dromara.workflow.domain.vo.ProcessDefinitionVo; |
| | | import org.dromara.workflow.service.IActProcessDefinitionService; |
| | | import org.dromara.workflow.service.IWfCategoryService; |
| | | import org.flowable.engine.HistoryService; |
| | | import org.dromara.workflow.utils.QueryUtils; |
| | | import org.flowable.engine.ProcessMigrationService; |
| | | import org.flowable.engine.RepositoryService; |
| | | import org.flowable.engine.impl.bpmn.deployer.ResourceNameUtil; |
| | | import org.flowable.engine.repository.Deployment; |
| | | import org.flowable.engine.repository.Model; |
| | | import org.flowable.engine.repository.ProcessDefinition; |
| | | import org.flowable.engine.repository.ProcessDefinitionQuery; |
| | | import org.flowable.engine.repository.*; |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | public class ActProcessDefinitionServiceImpl implements IActProcessDefinitionService { |
| | | |
| | | private final RepositoryService repositoryService; |
| | | |
| | | private final HistoryService historyService; |
| | | |
| | | private final ProcessMigrationService processMigrationService; |
| | | |
| | | private final IWfCategoryService wfCategoryService; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public TableDataInfo<ProcessDefinitionVo> page(ProcessDefinitionBo processDefinitionBo) { |
| | | ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery(); |
| | | query.processDefinitionTenantId(TenantHelper.getTenantId()); |
| | | ProcessDefinitionQuery query = QueryUtils.definitionQuery(); |
| | | if (StringUtils.isNotEmpty(processDefinitionBo.getKey())) { |
| | | query.processDefinitionKey(processDefinitionBo.getKey()); |
| | | } |
| | |
| | | List<Deployment> deploymentList = null; |
| | | if (CollUtil.isNotEmpty(definitionList)) { |
| | | List<String> deploymentIds = StreamUtils.toList(definitionList, ProcessDefinition::getDeploymentId); |
| | | deploymentList = repositoryService.createDeploymentQuery().deploymentIds(deploymentIds).list(); |
| | | deploymentList = QueryUtils.deploymentQuery(deploymentIds).list(); |
| | | } |
| | | for (ProcessDefinition processDefinition : definitionList) { |
| | | ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); |
| | |
| | | @Override |
| | | public List<ProcessDefinitionVo> getProcessDefinitionListByKey(String key) { |
| | | List<ProcessDefinitionVo> processDefinitionVoList = new ArrayList<>(); |
| | | ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery(); |
| | | List<ProcessDefinition> definitionList = query.processDefinitionTenantId(TenantHelper.getTenantId()).processDefinitionKey(key).list(); |
| | | ProcessDefinitionQuery query = QueryUtils.definitionQuery(); |
| | | List<ProcessDefinition> definitionList = query.processDefinitionKey(key).list(); |
| | | List<Deployment> deploymentList = null; |
| | | if (CollUtil.isNotEmpty(definitionList)) { |
| | | List<String> deploymentIds = definitionList.stream().map(ProcessDefinition::getDeploymentId).collect(Collectors.toList()); |
| | | deploymentList = repositoryService.createDeploymentQuery() |
| | | .deploymentIds(deploymentIds).list(); |
| | | deploymentList = QueryUtils.deploymentQuery(deploymentIds).list(); |
| | | } |
| | | for (ProcessDefinition processDefinition : definitionList) { |
| | | ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); |
| | |
| | | @Override |
| | | public boolean deleteDeployment(String deploymentId, String processDefinitionId) { |
| | | try { |
| | | List<HistoricTaskInstance> taskInstanceList = historyService.createHistoricTaskInstanceQuery() |
| | | List<HistoricTaskInstance> taskInstanceList = QueryUtils.hisTaskInstanceQuery() |
| | | .processDefinitionId(processDefinitionId).list(); |
| | | if (CollectionUtil.isNotEmpty(taskInstanceList)) { |
| | | throw new ServiceException("当前流程定义已被使用不可删除!"); |
| | |
| | | @Override |
| | | public boolean updateProcessDefState(String processDefinitionId) { |
| | | try { |
| | | ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() |
| | | .processDefinitionId(processDefinitionId).processDefinitionTenantId(TenantHelper.getTenantId()).singleResult(); |
| | | ProcessDefinition processDefinition = QueryUtils.definitionQuery() |
| | | .processDefinitionId(processDefinitionId).singleResult(); |
| | | //将当前为挂起状态更新为激活状态 |
| | | //参数说明:参数1:流程定义id,参数2:是否激活(true是否级联对应流程实例,激活了则对应流程实例都可以审批), |
| | | //参数3:什么时候激活,如果为null则立即激活,如果为具体时间则到达此时间后激活 |
| | |
| | | */ |
| | | @Override |
| | | public boolean convertToModel(String processDefinitionId) { |
| | | ProcessDefinition pd = repositoryService.createProcessDefinitionQuery() |
| | | ProcessDefinition pd = QueryUtils.definitionQuery() |
| | | .processDefinitionId(processDefinitionId).singleResult(); |
| | | InputStream inputStream = repositoryService.getResourceAsStream(pd.getDeploymentId(), pd.getResourceName()); |
| | | Model model = repositoryService.createModelQuery().modelKey(pd.getKey()).modelTenantId(TenantHelper.getTenantId()).singleResult(); |
| | | ModelQuery query = QueryUtils.modelQuery(); |
| | | Model model = query.modelKey(pd.getKey()).singleResult(); |
| | | try { |
| | | if (ObjectUtil.isNotNull(model)) { |
| | | repositoryService.addModelEditorSource(model.getId(), IoUtil.readBytes(inputStream)); |
| | |
| | | InputStream inputStream = file.getInputStream(); |
| | | Deployment deployment; |
| | | if (FlowConstant.ZIP.equals(suffix)) { |
| | | deployment = repositoryService.createDeployment() |
| | | DeploymentBuilder builder = repositoryService.createDeployment(); |
| | | deployment = builder.addZipInputStream(new ZipInputStream(inputStream)) |
| | | .tenantId(TenantHelper.getTenantId()) |
| | | .addZipInputStream(new ZipInputStream(inputStream)).name(processName).key(processKey).category(categoryCode).deploy(); |
| | | .name(processName).key(processKey).category(categoryCode).deploy(); |
| | | } else { |
| | | String[] list = ResourceNameUtil.BPMN_RESOURCE_SUFFIXES; |
| | | boolean flag = false; |
| | |
| | | } |
| | | } |
| | | if (flag) { |
| | | deployment = repositoryService.createDeployment() |
| | | DeploymentBuilder builder = repositoryService.createDeployment(); |
| | | deployment = builder.addInputStream(filename, inputStream) |
| | | .tenantId(TenantHelper.getTenantId()) |
| | | .addInputStream(filename, inputStream).name(processName).key(processKey).category(categoryCode).deploy(); |
| | | .name(processName).key(processKey).category(categoryCode).deploy(); |
| | | } else { |
| | | throw new ServiceException("文件类型上传错误!"); |
| | | } |
| | | } |
| | | // 更新分类 |
| | | ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult(); |
| | | ProcessDefinition definition = QueryUtils.definitionQuery().deploymentId(deployment.getId()).singleResult(); |
| | | repositoryService.setProcessDefinitionCategory(definition.getId(), categoryCode); |
| | | |
| | | return true; |