From 098d3347a0df808908aab8c554cd7c4febc5e6d9 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期一, 26 八月 2024 11:43:59 +0800 Subject: [PATCH] !577 发布 5.2.2 正式版 安全性提升 Merge pull request !577 from 疯狂的狮子Li/dev --- ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java | 87 ++++++++++++++++++++++--------------------- 1 files changed, 44 insertions(+), 43 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 468e397..77fb257 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 @@ -3,14 +3,13 @@ import cn.hutool.core.bean.BeanUtil; 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 cn.hutool.core.util.StrUtil; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; -import org.apache.commons.io.IOUtils; +import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StringUtils; @@ -38,7 +37,7 @@ import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.impl.bpmn.deployer.ResourceNameUtil; import org.flowable.engine.repository.*; -import org.flowable.task.api.history.HistoricTaskInstance; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; @@ -46,7 +45,10 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -55,16 +57,19 @@ * * @author may */ +@Slf4j @RequiredArgsConstructor @Service public class ActProcessDefinitionServiceImpl implements IActProcessDefinitionService { - private final RepositoryService repositoryService; - private final ProcessMigrationService processMigrationService; + @Autowired(required = false) + private RepositoryService repositoryService; + @Autowired(required = false) + private ProcessMigrationService processMigrationService; private final IWfCategoryService wfCategoryService; - private final IWfDefinitionConfigService iWfDefinitionConfigService; + private final IWfDefinitionConfigService wfDefinitionConfigService; private final WfDefinitionConfigMapper wfDefinitionConfigMapper; - private final IWfNodeConfigService iWfNodeConfigService; + private final IWfNodeConfigService wfNodeConfigService; /** * 鍒嗛〉鏌ヨ @@ -95,7 +100,7 @@ } if (CollUtil.isNotEmpty(definitionList)) { List<String> ids = StreamUtils.toList(definitionList, ProcessDefinition::getId); - List<WfDefinitionConfigVo> wfDefinitionConfigVos = iWfDefinitionConfigService.queryList(ids); + List<WfDefinitionConfigVo> wfDefinitionConfigVos = wfDefinitionConfigService.queryList(ids); for (ProcessDefinition processDefinition : definitionList) { ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); if (CollUtil.isNotEmpty(deploymentList)) { @@ -135,7 +140,7 @@ } if (CollUtil.isNotEmpty(definitionList)) { List<String> ids = StreamUtils.toList(definitionList, ProcessDefinition::getId); - List<WfDefinitionConfigVo> wfDefinitionConfigVos = iWfDefinitionConfigService.queryList(ids); + List<WfDefinitionConfigVo> wfDefinitionConfigVos = wfDefinitionConfigService.queryList(ids); for (ProcessDefinition processDefinition : definitionList) { ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); if (CollUtil.isNotEmpty(deploymentList)) { @@ -150,7 +155,7 @@ processDefinitionVoList.add(processDefinitionVo); } } - return CollectionUtil.reverse(processDefinitionVoList); + return CollUtil.reverse(processDefinitionVoList); } /** @@ -162,7 +167,7 @@ @Override public String definitionImage(String processDefinitionId) { InputStream inputStream = repositoryService.getProcessDiagram(processDefinitionId); - return Base64.encode(IOUtils.toByteArray(inputStream)); + return Base64.encode(IoUtil.readBytes(inputStream)); } /** @@ -174,13 +179,8 @@ public String definitionXml(String processDefinitionId) { StringBuilder xml = new StringBuilder(); ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId); - InputStream inputStream; - try { - inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName()); - xml.append(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - } catch (IOException e) { - e.printStackTrace(); - } + InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName()); + xml.append(IoUtil.read(inputStream, StandardCharsets.UTF_8)); return xml.toString(); } @@ -195,7 +195,7 @@ public boolean deleteDeployment(List<String> deploymentIds, List<String> processDefinitionIds) { try { List<HistoricProcessInstance> historicProcessInstances = QueryUtils.hisInstanceQuery().deploymentIdIn(deploymentIds).list(); - if (CollectionUtil.isNotEmpty(historicProcessInstances)) { + if (CollUtil.isNotEmpty(historicProcessInstances)) { Set<String> defIds = StreamUtils.toSet(historicProcessInstances, HistoricProcessInstance::getProcessDefinitionId); List<ProcessDefinition> processDefinitions = QueryUtils.definitionQuery().processDefinitionIds(defIds).list(); if (CollUtil.isNotEmpty(processDefinitions)) { @@ -208,12 +208,12 @@ repositoryService.deleteDeployment(deploymentId); } //鍒犻櫎娴佺▼瀹氫箟閰嶇疆 - iWfDefinitionConfigService.deleteByDefIds(processDefinitionIds); + wfDefinitionConfigService.deleteByDefIds(processDefinitionIds); //鍒犻櫎鑺傜偣閰嶇疆 - iWfNodeConfigService.deleteByDefIds(processDefinitionIds); + wfNodeConfigService.deleteByDefIds(processDefinitionIds); return true; } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage(), e); throw new ServiceException(e.getMessage()); } } @@ -238,7 +238,7 @@ } return true; } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage(), e); throw new ServiceException("鎿嶄綔澶辫触:" + e.getMessage()); } } @@ -267,6 +267,7 @@ .migrateProcessInstances(fromProcessDefinitionId); return true; } catch (Exception e) { + log.error(e.getMessage(), e); throw new ServiceException(e.getMessage()); } } @@ -290,13 +291,14 @@ Model modelData = repositoryService.newModel(); modelData.setKey(pd.getKey()); modelData.setName(pd.getName()); + modelData.setCategory(pd.getCategory()); modelData.setTenantId(pd.getTenantId()); repositoryService.saveModel(modelData); repositoryService.addModelEditorSource(modelData.getId(), IoUtil.readBytes(inputStream)); } return true; } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage(), e); throw new ServiceException(e.getMessage()); } } @@ -352,8 +354,7 @@ initWfDefConfig(); } else { String originalFilename = file.getOriginalFilename(); - String bpmnResourceSuffix = ResourceNameUtil.BPMN_RESOURCE_SUFFIXES[0]; - if (originalFilename.contains(bpmnResourceSuffix)) { + if (StringUtils.containsAny(originalFilename, ResourceNameUtil.BPMN_RESOURCE_SUFFIXES)) { // 鏂囦欢鍚� = 娴佺▼鍚嶇О-娴佺▼key String[] splitFilename = originalFilename.substring(0, originalFilename.lastIndexOf(".")).split("-"); if (splitFilename.length < 2) { @@ -387,12 +388,12 @@ 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); + WfDefinitionConfigBo wfDefinitionConfigBo = new WfDefinitionConfigBo(); + wfDefinitionConfigBo.setDefinitionId(processDefinition.getId()); + wfDefinitionConfigBo.setProcessKey(processDefinition.getKey()); + wfDefinitionConfigBo.setTableName("test_leave"); + wfDefinitionConfigBo.setVersion(processDefinition.getVersion()); + wfDefinitionConfigService.saveOrUpdate(wfDefinitionConfigBo); } } @@ -407,16 +408,16 @@ private void setWfConfig(ProcessDefinition oldProcessDefinition, ProcessDefinition definition) { //鏇存柊娴佺▼瀹氫箟琛ㄥ崟 if (oldProcessDefinition != null) { - WfDefinitionConfigVo definitionVo = iWfDefinitionConfigService.getByDefId(oldProcessDefinition.getId()); + WfDefinitionConfigVo definitionVo = wfDefinitionConfigService.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); + wfDefinitionConfigService.deleteByDefIds(Collections.singletonList(oldProcessDefinition.getId())); + WfDefinitionConfigBo wfDefinitionConfigBo = new WfDefinitionConfigBo(); + wfDefinitionConfigBo.setDefinitionId(definition.getId()); + wfDefinitionConfigBo.setProcessKey(definition.getKey()); + wfDefinitionConfigBo.setTableName(definitionVo.getTableName()); + wfDefinitionConfigBo.setVersion(definition.getVersion()); + wfDefinitionConfigBo.setRemark(definitionVo.getRemark()); + wfDefinitionConfigService.saveOrUpdate(wfDefinitionConfigBo); } } //鏇存柊娴佺▼鑺傜偣閰嶇疆琛ㄥ崟 @@ -437,7 +438,7 @@ } } if (CollUtil.isNotEmpty(wfNodeConfigList)) { - iWfNodeConfigService.saveOrUpdate(wfNodeConfigList); + wfNodeConfigService.saveOrUpdate(wfNodeConfigList); } } } -- Gitblit v1.9.3