From 040ecb2532859f369518cb49287c5c2d4cf22308 Mon Sep 17 00:00:00 2001 From: gssong <1742057357@qq.com> Date: 星期一, 08 四月 2024 21:30:36 +0800 Subject: [PATCH] add 添加初始化配置数据(demo使用,不用可删除) --- ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java | 108 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 97 insertions(+), 11 deletions(-) diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java index 28c3520..1627eba 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java @@ -7,6 +7,7 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.apache.commons.io.IOUtils; @@ -18,13 +19,20 @@ import org.dromara.common.tenant.helper.TenantHelper; import org.dromara.workflow.common.constant.FlowConstant; import org.dromara.workflow.domain.WfCategory; +import org.dromara.workflow.domain.WfDefinitionConfig; +import org.dromara.workflow.domain.WfNodeConfig; import org.dromara.workflow.domain.bo.ProcessDefinitionBo; +import org.dromara.workflow.domain.bo.WfDefinitionConfigBo; import org.dromara.workflow.domain.vo.ProcessDefinitionVo; -import org.dromara.workflow.domain.vo.WfFormDefinitionVo; +import org.dromara.workflow.domain.vo.WfDefinitionConfigVo; +import org.dromara.workflow.mapper.WfDefinitionConfigMapper; import org.dromara.workflow.service.IActProcessDefinitionService; import org.dromara.workflow.service.IWfCategoryService; -import org.dromara.workflow.service.IWfFormDefinitionService; +import org.dromara.workflow.service.IWfDefinitionConfigService; +import org.dromara.workflow.service.IWfNodeConfigService; +import org.dromara.workflow.utils.ModelUtils; import org.dromara.workflow.utils.QueryUtils; +import org.flowable.bpmn.model.UserTask; import org.flowable.engine.ProcessMigrationService; import org.flowable.engine.RepositoryService; import org.flowable.engine.impl.bpmn.deployer.ResourceNameUtil; @@ -38,6 +46,7 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -54,7 +63,9 @@ private final RepositoryService repositoryService; private final ProcessMigrationService processMigrationService; private final IWfCategoryService wfCategoryService; - private final IWfFormDefinitionService iWfFormDefinitionService; + private final IWfDefinitionConfigService iWfDefinitionConfigService; + private final WfDefinitionConfigMapper wfDefinitionConfigMapper; + private final IWfNodeConfigService iWfNodeConfigService; /** * 鍒嗛〉鏌ヨ @@ -85,7 +96,7 @@ } if (CollUtil.isNotEmpty(definitionList)) { List<String> ids = StreamUtils.toList(definitionList, ProcessDefinition::getId); - List<WfFormDefinitionVo> wfFormDefinitionVos = iWfFormDefinitionService.queryList(ids); + List<WfDefinitionConfigVo> wfDefinitionConfigVos = iWfDefinitionConfigService.queryList(ids); for (ProcessDefinition processDefinition : definitionList) { ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); if (CollUtil.isNotEmpty(deploymentList)) { @@ -94,16 +105,18 @@ processDefinitionVo.setDeploymentTime(e.getDeploymentTime()); }); } - if (CollUtil.isNotEmpty(wfFormDefinitionVos)) { - wfFormDefinitionVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfFormDefinitionVo); + if (CollUtil.isNotEmpty(wfDefinitionConfigVos)) { + wfDefinitionConfigVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfDefinitionConfigVo); } processDefinitionVoList.add(processDefinitionVo); } } // 鎬昏褰曟暟 long total = query.count(); - - return new TableDataInfo<>(processDefinitionVoList, total); + TableDataInfo<ProcessDefinitionVo> build = TableDataInfo.build(); + build.setRows(processDefinitionVoList); + build.setTotal(total); + return build; } /** @@ -123,7 +136,7 @@ } if (CollUtil.isNotEmpty(definitionList)) { List<String> ids = StreamUtils.toList(definitionList, ProcessDefinition::getId); - List<WfFormDefinitionVo> wfFormDefinitionVos = iWfFormDefinitionService.queryList(ids); + List<WfDefinitionConfigVo> wfDefinitionConfigVos = iWfDefinitionConfigService.queryList(ids); for (ProcessDefinition processDefinition : definitionList) { ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); if (CollUtil.isNotEmpty(deploymentList)) { @@ -131,8 +144,8 @@ deploymentList.stream().filter(e -> e.getId().equals(processDefinition.getDeploymentId())).findFirst().ifPresent(e -> { processDefinitionVo.setDeploymentTime(e.getDeploymentTime()); }); - if (CollUtil.isNotEmpty(wfFormDefinitionVos)) { - wfFormDefinitionVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfFormDefinitionVo); + if (CollUtil.isNotEmpty(wfDefinitionConfigVos)) { + wfDefinitionConfigVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfDefinitionConfigVo); } } processDefinitionVoList.add(processDefinitionVo); @@ -179,6 +192,7 @@ * @param processDefinitionId 娴佺▼瀹氫箟id */ @Override + @Transactional(rollbackFor = Exception.class) public boolean deleteDeployment(String deploymentId, String processDefinitionId) { try { List<HistoricTaskInstance> taskInstanceList = QueryUtils.hisTaskInstanceQuery() @@ -188,6 +202,10 @@ } //鍒犻櫎娴佺▼瀹氫箟 repositoryService.deleteDeployment(deploymentId); + //鍒犻櫎娴佺▼瀹氫箟閰嶇疆 + iWfDefinitionConfigService.deleteByDefIds(Collections.singletonList(processDefinitionId)); + //鍒犻櫎鑺傜偣閰嶇疆 + iWfNodeConfigService.deleteByDefIds(Collections.singletonList(processDefinitionId)); return true; } catch (Exception e) { e.printStackTrace(); @@ -308,12 +326,14 @@ String processName = splitFilename[0]; //娴佺▼key String processKey = splitFilename[1]; + ProcessDefinition oldProcessDefinition = QueryUtils.definitionQuery().processDefinitionKey(processKey).latestVersion().singleResult(); DeploymentBuilder builder = repositoryService.createDeployment(); Deployment deployment = builder.addInputStream(filename, zipInputStream) .tenantId(TenantHelper.getTenantId()) .name(processName).key(processKey).category(categoryCode).deploy(); ProcessDefinition definition = QueryUtils.definitionQuery().deploymentId(deployment.getId()).singleResult(); repositoryService.setProcessDefinitionCategory(definition.getId(), categoryCode); + setWfConfig(oldProcessDefinition, definition); zipInputStream.closeEntry(); } } catch (IOException e) { @@ -323,6 +343,8 @@ zipInputStream.close(); } } + //鍒濆鍖栭厤缃暟鎹紙demo浣跨敤锛屼笉鐢ㄥ彲鍒犻櫎锛� + initWfDefConfig(); } else { String originalFilename = file.getOriginalFilename(); String bpmnResourceSuffix = ResourceNameUtil.BPMN_RESOURCE_SUFFIXES[0]; @@ -336,6 +358,7 @@ String processName = splitFilename[0]; //娴佺▼key String processKey = splitFilename[1]; + ProcessDefinition oldProcessDefinition = QueryUtils.definitionQuery().processDefinitionKey(processKey).latestVersion().singleResult(); DeploymentBuilder builder = repositoryService.createDeployment(); Deployment deployment = builder.addInputStream(originalFilename, inputStream) .tenantId(TenantHelper.getTenantId()) @@ -343,10 +366,73 @@ // 鏇存柊鍒嗙被 ProcessDefinition definition = QueryUtils.definitionQuery().deploymentId(deployment.getId()).singleResult(); repositoryService.setProcessDefinitionCategory(definition.getId(), categoryCode); + setWfConfig(oldProcessDefinition, definition); } else { throw new ServiceException("鏂囦欢绫诲瀷涓婁紶閿欒锛�"); } } } + + /** + * 鍒濆鍖栭厤缃暟鎹紙demo浣跨敤锛屼笉鐢ㄥ彲鍒犻櫎锛� + */ + private void initWfDefConfig() { + List<WfDefinitionConfig> wfDefinitionConfigs = wfDefinitionConfigMapper.selectList(); + if (CollUtil.isEmpty(wfDefinitionConfigs)) { + ProcessDefinition processDefinition = QueryUtils.definitionQuery().processDefinitionKey("leave1").latestVersion().singleResult(); + if (processDefinition != null) { + WfDefinitionConfigBo wfFormDefinition = new WfDefinitionConfigBo(); + wfFormDefinition.setDefinitionId(processDefinition.getId()); + wfFormDefinition.setProcessKey(processDefinition.getKey()); + wfFormDefinition.setTableName("test_leave"); + wfFormDefinition.setVersion(processDefinition.getVersion()); + iWfDefinitionConfigService.saveOrUpdate(wfFormDefinition); + } + } + + } + + /** + * 璁剧疆琛ㄥ崟鍐呭 + * + * @param oldProcessDefinition 閮ㄧ讲鍓嶆渶鏂版祦绋嬪畾涔� + * @param definition 閮ㄧ讲鍚庢渶鏂版祦绋嬪畾涔� + */ + private void setWfConfig(ProcessDefinition oldProcessDefinition, ProcessDefinition definition) { + //鏇存柊娴佺▼瀹氫箟琛ㄥ崟 + if (oldProcessDefinition != null) { + WfDefinitionConfigVo definitionVo = iWfDefinitionConfigService.getByDefId(oldProcessDefinition.getId()); + if (definitionVo != null) { + iWfDefinitionConfigService.deleteByDefIds(Collections.singletonList(oldProcessDefinition.getId())); + WfDefinitionConfigBo wfFormDefinition = new WfDefinitionConfigBo(); + wfFormDefinition.setDefinitionId(definition.getId()); + wfFormDefinition.setProcessKey(definition.getKey()); + wfFormDefinition.setTableName(definitionVo.getTableName()); + wfFormDefinition.setVersion(definition.getVersion()); + wfFormDefinition.setRemark(definitionVo.getRemark()); + iWfDefinitionConfigService.saveOrUpdate(wfFormDefinition); + } + } + //鏇存柊娴佺▼鑺傜偣閰嶇疆琛ㄥ崟 + List<UserTask> userTasks = ModelUtils.getUserTaskFlowElements(definition.getId()); + UserTask applyUserTask = ModelUtils.getApplyUserTask(definition.getId()); + List<WfNodeConfig> wfNodeConfigList = new ArrayList<>(); + for (UserTask userTask : userTasks) { + if (StringUtils.isNotBlank(userTask.getFormKey()) && userTask.getFormKey().contains(StrUtil.COLON)) { + WfNodeConfig wfNodeConfig = new WfNodeConfig(); + wfNodeConfig.setNodeId(userTask.getId()); + wfNodeConfig.setNodeName(userTask.getName()); + wfNodeConfig.setDefinitionId(definition.getId()); + String[] split = userTask.getFormKey().split(StrUtil.COLON); + wfNodeConfig.setFormType(split[0]); + wfNodeConfig.setFormId(Long.valueOf(split[1])); + wfNodeConfig.setApplyUserTask(applyUserTask.getId().equals(userTask.getId()) ? FlowConstant.TRUE : FlowConstant.FALSE); + wfNodeConfigList.add(wfNodeConfig); + } + } + if (CollUtil.isNotEmpty(wfNodeConfigList)) { + iWfNodeConfigService.saveOrUpdate(wfNodeConfigList); + } + } } -- Gitblit v1.9.3