From 6f5a368c86c3818b968ad1055f5215f86c989084 Mon Sep 17 00:00:00 2001 From: gssong <1742057357@qq.com> Date: 星期四, 21 三月 2024 21:02:16 +0800 Subject: [PATCH] add 添加流程表单配置 --- ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java | 159 +++++++++++++++++++++++++++++++--------------------- 1 files changed, 94 insertions(+), 65 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 a06fb34..28c3520 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 @@ -4,6 +4,7 @@ import cn.hutool.core.codec.Base64; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.ObjectUtil; import lombok.RequiredArgsConstructor; @@ -19,8 +20,10 @@ import org.dromara.workflow.domain.WfCategory; import org.dromara.workflow.domain.bo.ProcessDefinitionBo; import org.dromara.workflow.domain.vo.ProcessDefinitionVo; +import org.dromara.workflow.domain.vo.WfFormDefinitionVo; import org.dromara.workflow.service.IActProcessDefinitionService; import org.dromara.workflow.service.IWfCategoryService; +import org.dromara.workflow.service.IWfFormDefinitionService; import org.dromara.workflow.utils.QueryUtils; import org.flowable.engine.ProcessMigrationService; import org.flowable.engine.RepositoryService; @@ -28,6 +31,7 @@ import org.flowable.engine.repository.*; import org.flowable.task.api.history.HistoricTaskInstance; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; @@ -35,7 +39,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; +import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; /** @@ -50,6 +54,7 @@ private final RepositoryService repositoryService; private final ProcessMigrationService processMigrationService; private final IWfCategoryService wfCategoryService; + private final IWfFormDefinitionService iWfFormDefinitionService; /** * 鍒嗛〉鏌ヨ @@ -78,15 +83,22 @@ 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<WfFormDefinitionVo> wfFormDefinitionVos = iWfFormDefinitionService.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(wfFormDefinitionVos)) { + wfFormDefinitionVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfFormDefinitionVo); + } + processDefinitionVoList.add(processDefinitionVo); } - processDefinitionVoList.add(processDefinitionVo); } // 鎬昏褰曟暟 long total = query.count(); @@ -106,18 +118,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<WfFormDefinitionVo> wfFormDefinitionVos = iWfFormDefinitionService.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(wfFormDefinitionVos)) { + wfFormDefinitionVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfFormDefinitionVo); + } + } + processDefinitionVoList.add(processDefinitionVo); } - processDefinitionVoList.add(processDefinitionVo); } return CollectionUtil.reverse(processDefinitionVoList); } @@ -265,59 +284,69 @@ * @param file 鏂囦欢 * @param categoryCode 鍒嗙被 */ + @SneakyThrows @Override - public boolean deployByFile(MultipartFile file, String categoryCode) { - try { - WfCategory wfCategory = wfCategoryService.queryByCategoryCode(categoryCode); - if (wfCategory == null) { - throw new ServiceException("娴佺▼鍒嗙被涓嶅瓨鍦�"); - } - // 鏂囦欢鍚� = 娴佺▼鍚嶇О-娴佺▼key - String filename = file.getOriginalFilename(); - assert filename != null; - String[] splitFilename = filename.substring(0, filename.lastIndexOf(".")).split("-"); - if (splitFilename.length < 2) { - throw new ServiceException("娴佺▼鍒嗙被涓嶈兘涓虹┖(鏂囦欢鍚� = 娴佺▼鍚嶇О-娴佺▼key)"); - } - //娴佺▼鍚嶇О - String processName = splitFilename[0]; - //娴佺▼key - String processKey = splitFilename[1]; - // 鏂囦欢鍚庣紑鍚� - String suffix = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase(); - InputStream inputStream = file.getInputStream(); - Deployment deployment; - if (FlowConstant.ZIP.equals(suffix)) { - DeploymentBuilder builder = repositoryService.createDeployment(); - deployment = builder.addZipInputStream(new ZipInputStream(inputStream)) - .tenantId(TenantHelper.getTenantId()) - .name(processName).key(processKey).category(categoryCode).deploy(); - } else { - String[] list = ResourceNameUtil.BPMN_RESOURCE_SUFFIXES; - boolean flag = false; - for (String str : list) { - if (filename.contains(str)) { - flag = true; - break; - } - } - if (flag) { + @Transactional(rollbackFor = Exception.class) + public void deployByFile(MultipartFile file, String categoryCode) { + + WfCategory wfCategory = wfCategoryService.queryByCategoryCode(categoryCode); + if (wfCategory == null) { + throw new ServiceException("娴佺▼鍒嗙被涓嶅瓨鍦�"); + } + // 鏂囦欢鍚庣紑鍚� + String suffix = FileUtil.extName(file.getOriginalFilename()); + InputStream inputStream = file.getInputStream(); + if (FlowConstant.ZIP.equalsIgnoreCase(suffix)) { + ZipInputStream zipInputStream = null; + try { + zipInputStream = new ZipInputStream(inputStream); + ZipEntry zipEntry; + while ((zipEntry = zipInputStream.getNextEntry()) != null) { + String filename = zipEntry.getName(); + String[] splitFilename = filename.substring(0, filename.lastIndexOf(".")).split("-"); + //娴佺▼鍚嶇О + String processName = splitFilename[0]; + //娴佺▼key + String processKey = splitFilename[1]; DeploymentBuilder builder = repositoryService.createDeployment(); - deployment = builder.addInputStream(filename, inputStream) + Deployment deployment = builder.addInputStream(filename, zipInputStream) .tenantId(TenantHelper.getTenantId()) .name(processName).key(processKey).category(categoryCode).deploy(); - } else { - throw new ServiceException("鏂囦欢绫诲瀷涓婁紶閿欒锛�"); + ProcessDefinition definition = QueryUtils.definitionQuery().deploymentId(deployment.getId()).singleResult(); + repositoryService.setProcessDefinitionCategory(definition.getId(), categoryCode); + zipInputStream.closeEntry(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + if (zipInputStream != null) { + zipInputStream.close(); } } - // 鏇存柊鍒嗙被 - ProcessDefinition definition = QueryUtils.definitionQuery().deploymentId(deployment.getId()).singleResult(); - repositoryService.setProcessDefinitionCategory(definition.getId(), categoryCode); - - return true; - } catch (IOException e) { - e.printStackTrace(); - throw new ServiceException("閮ㄧ讲澶辫触" + e.getMessage()); + } else { + String originalFilename = file.getOriginalFilename(); + String bpmnResourceSuffix = ResourceNameUtil.BPMN_RESOURCE_SUFFIXES[0]; + if (originalFilename.contains(bpmnResourceSuffix)) { + // 鏂囦欢鍚� = 娴佺▼鍚嶇О-娴佺▼key + String[] splitFilename = originalFilename.substring(0, originalFilename.lastIndexOf(".")).split("-"); + if (splitFilename.length < 2) { + throw new ServiceException("鏂囦欢鍚� = 娴佺▼鍚嶇О-娴佺▼KEY"); + } + //娴佺▼鍚嶇О + String processName = splitFilename[0]; + //娴佺▼key + String processKey = splitFilename[1]; + DeploymentBuilder builder = repositoryService.createDeployment(); + Deployment deployment = builder.addInputStream(originalFilename, inputStream) + .tenantId(TenantHelper.getTenantId()) + .name(processName).key(processKey).category(categoryCode).deploy(); + // 鏇存柊鍒嗙被 + ProcessDefinition definition = QueryUtils.definitionQuery().deploymentId(deployment.getId()).singleResult(); + repositoryService.setProcessDefinitionCategory(definition.getId(), categoryCode); + } else { + throw new ServiceException("鏂囦欢绫诲瀷涓婁紶閿欒锛�"); + } } + } } -- Gitblit v1.9.3