From 1da98c8a8207dd062e433242e1567b6418c6ed81 Mon Sep 17 00:00:00 2001 From: gssong <1742057357@qq.com> Date: 星期六, 06 四月 2024 11:20:29 +0800 Subject: [PATCH] update 优化表单绑定逻辑,移除流程定义配置表单 --- ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java | 102 +++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 82 insertions(+), 20 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 cc82e00..89a71db 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,11 +19,17 @@ 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.WfNodeConfig; import org.dromara.workflow.domain.bo.ProcessDefinitionBo; import org.dromara.workflow.domain.vo.ProcessDefinitionVo; +import org.dromara.workflow.domain.vo.WfDefinitionConfigVo; import org.dromara.workflow.service.IActProcessDefinitionService; import org.dromara.workflow.service.IWfCategoryService; +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; @@ -36,8 +43,8 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -53,6 +60,8 @@ private final RepositoryService repositoryService; private final ProcessMigrationService processMigrationService; private final IWfCategoryService wfCategoryService; + private final IWfDefinitionConfigService iWfDefinitionConfigService; + private final IWfNodeConfigService iWfNodeConfigService; /** * 鍒嗛〉鏌ヨ @@ -81,20 +90,29 @@ List<String> deploymentIds = StreamUtils.toList(definitionList, ProcessDefinition::getDeploymentId); deploymentList = QueryUtils.deploymentQuery(deploymentIds).list(); } - for (ProcessDefinition processDefinition : definitionList) { - ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); - if (CollUtil.isNotEmpty(deploymentList)) { - // 閮ㄧ讲鏃堕棿 - deploymentList.stream().filter(e -> e.getId().equals(processDefinition.getDeploymentId())).findFirst().ifPresent(e -> { - processDefinitionVo.setDeploymentTime(e.getDeploymentTime()); - }); + if (CollUtil.isNotEmpty(definitionList)) { + List<String> ids = StreamUtils.toList(definitionList, ProcessDefinition::getId); + List<WfDefinitionConfigVo> wfDefinitionConfigVos = iWfDefinitionConfigService.queryList(ids); + for (ProcessDefinition processDefinition : definitionList) { + ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); + if (CollUtil.isNotEmpty(deploymentList)) { + // 閮ㄧ讲鏃堕棿 + deploymentList.stream().filter(e -> e.getId().equals(processDefinition.getDeploymentId())).findFirst().ifPresent(e -> { + processDefinitionVo.setDeploymentTime(e.getDeploymentTime()); + }); + } + if (CollUtil.isNotEmpty(wfDefinitionConfigVos)) { + wfDefinitionConfigVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfDefinitionConfigVo); + } + processDefinitionVoList.add(processDefinitionVo); } - 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; } /** @@ -109,18 +127,25 @@ 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()); + List<String> deploymentIds = StreamUtils.toList(definitionList, ProcessDefinition::getDeploymentId); deploymentList = QueryUtils.deploymentQuery(deploymentIds).list(); } - for (ProcessDefinition processDefinition : definitionList) { - ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); - if (CollUtil.isNotEmpty(deploymentList)) { - // 閮ㄧ讲鏃堕棿 - deploymentList.stream().filter(e -> e.getId().equals(processDefinition.getDeploymentId())).findFirst().ifPresent(e -> { - processDefinitionVo.setDeploymentTime(e.getDeploymentTime()); - }); + if (CollUtil.isNotEmpty(definitionList)) { + List<String> ids = StreamUtils.toList(definitionList, ProcessDefinition::getId); + List<WfDefinitionConfigVo> wfDefinitionConfigVos = iWfDefinitionConfigService.queryList(ids); + for (ProcessDefinition processDefinition : definitionList) { + ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); + if (CollUtil.isNotEmpty(deploymentList)) { + // 閮ㄧ讲鏃堕棿 + deploymentList.stream().filter(e -> e.getId().equals(processDefinition.getDeploymentId())).findFirst().ifPresent(e -> { + processDefinitionVo.setDeploymentTime(e.getDeploymentTime()); + }); + if (CollUtil.isNotEmpty(wfDefinitionConfigVos)) { + wfDefinitionConfigVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfDefinitionConfigVo); + } + } + processDefinitionVoList.add(processDefinitionVo); } - processDefinitionVoList.add(processDefinitionVo); } return CollectionUtil.reverse(processDefinitionVoList); } @@ -163,6 +188,7 @@ * @param processDefinitionId 娴佺▼瀹氫箟id */ @Override + @Transactional(rollbackFor = Exception.class) public boolean deleteDeployment(String deploymentId, String processDefinitionId) { try { List<HistoricTaskInstance> taskInstanceList = QueryUtils.hisTaskInstanceQuery() @@ -172,6 +198,10 @@ } //鍒犻櫎娴佺▼瀹氫箟 repositoryService.deleteDeployment(deploymentId); + //鍒犻櫎娴佺▼瀹氫箟閰嶇疆 + iWfDefinitionConfigService.deleteByDefIds(Collections.singletonList(processDefinitionId)); + //鍒犻櫎鑺傜偣閰嶇疆 + iWfNodeConfigService.deleteByDefIds(Collections.singletonList(processDefinitionId)); return true; } catch (Exception e) { e.printStackTrace(); @@ -298,6 +328,7 @@ .name(processName).key(processKey).category(categoryCode).deploy(); ProcessDefinition definition = QueryUtils.definitionQuery().deploymentId(deployment.getId()).singleResult(); repositoryService.setProcessDefinitionCategory(definition.getId(), categoryCode); + setWfNodeConfig(definition); zipInputStream.closeEntry(); } } catch (IOException e) { @@ -320,6 +351,7 @@ String processName = splitFilename[0]; //娴佺▼key String processKey = splitFilename[1]; + DeploymentBuilder builder = repositoryService.createDeployment(); Deployment deployment = builder.addInputStream(originalFilename, inputStream) .tenantId(TenantHelper.getTenantId()) @@ -327,10 +359,40 @@ // 鏇存柊鍒嗙被 ProcessDefinition definition = QueryUtils.definitionQuery().deploymentId(deployment.getId()).singleResult(); repositoryService.setProcessDefinitionCategory(definition.getId(), categoryCode); + setWfNodeConfig(definition); + } else { throw new ServiceException("鏂囦欢绫诲瀷涓婁紶閿欒锛�"); } } } + + /** + * 璁剧疆琛ㄥ崟鍐呭 + * + * @param definition 閮ㄧ讲鍚庢渶鏂版祦绋嬪畾涔� + */ + private void setWfNodeConfig(ProcessDefinition definition) { + //鏇存柊娴佺▼鑺傜偣閰嶇疆琛ㄥ崟 + 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