flowable/src/main/java/com/ycl/cmd/RemoveDeploymentCacheCMD.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
flowable/src/main/java/com/ycl/controller/FlowDefinitionController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
flowable/src/main/java/com/ycl/domain/dto/FlowSaveXmlVo.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
flowable/src/main/java/com/ycl/mapper/FlowDeployMapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
flowable/src/main/java/com/ycl/service/IFlowDefinitionService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
flowable/src/main/java/com/ycl/service/impl/FlowDefinitionServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
flowable/src/main/resources/mapper/FlowDeployMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
flowable/src/main/java/com/ycl/cmd/RemoveDeploymentCacheCMD.java
New file @@ -0,0 +1,46 @@ package com.ycl.cmd; import lombok.RequiredArgsConstructor; import org.flowable.common.engine.impl.interceptor.Command; import org.flowable.common.engine.impl.interceptor.CommandContext; import org.flowable.common.engine.impl.persistence.deploy.DeploymentCache; import org.flowable.engine.impl.persistence.deploy.DeploymentManager; import org.flowable.engine.impl.persistence.deploy.ProcessDefinitionCacheEntry; import org.flowable.engine.impl.util.CommandContextUtil; import org.flowable.engine.repository.Deployment; import org.springframework.util.StringUtils; /** * @author:xp * @date:2025/3/17 14:54 */ public class RemoveDeploymentCacheCMD implements Command<Deployment> { /** * 流程定义id */ private String processDefId; public RemoveDeploymentCacheCMD(String processDefId) { this.processDefId = processDefId; } /** * 如果传入了流程定义id,那么只删除特定的缓存。没传就删除所有的缓存 * * @param commandContext * @return */ @Override public Deployment execute(CommandContext commandContext) { DeploymentManager deploymentManager = CommandContextUtil.getProcessEngineConfiguration().getDeploymentManager(); DeploymentCache<ProcessDefinitionCacheEntry> deploymentCache = deploymentManager.getProcessDefinitionCache(); if (StringUtils.hasText(processDefId)) { deploymentCache.remove(processDefId); } else { deploymentCache.clear(); } return null; } } flowable/src/main/java/com/ycl/controller/FlowDefinitionController.java
@@ -152,6 +152,30 @@ return AjaxResult.success("导入成功"); } @ApiOperation(value = "修改原来部署的流程,不再以新版本部署") @Log(title = "修改原来部署的流程,不再以新版本部署", businessType = BusinessType.UPDATE) @PostMapping("/update") public AjaxResult update(@RequestBody FlowSaveXmlVo vo) { InputStream in = null; try { in = new ByteArrayInputStream(vo.getXml().getBytes(StandardCharsets.UTF_8)); flowDefinitionService.updateProcess(vo.getDeploymentId(), vo.getName(), vo.getCategory(), in); } catch (Exception e) { log.error("导入失败:", e); return AjaxResult.error(e.getMessage()); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { log.error("关闭输入流出错", e); } } return AjaxResult.success("导入成功"); } @ApiOperation(value = "发起流程") @Log(title = "发起流程", businessType = BusinessType.INSERT) @PostMapping("/start/{procDefId}") flowable/src/main/java/com/ycl/domain/dto/FlowSaveXmlVo.java
@@ -12,6 +12,11 @@ public class FlowSaveXmlVo implements Serializable { /** * 流程部署id,只有二次保存时才会有 */ private String deploymentId; /** * 流程名称 */ private String name; flowable/src/main/java/com/ycl/mapper/FlowDeployMapper.java
@@ -39,4 +39,6 @@ * @param query */ IPage selectDeployListWithConfigPage(IPage<FlowProcDefWithConfigDto> page, @Param("query") ProcessConfigInfoQuery query); void updateProcess(@Param("bytes") Object bytes, @Param("deployId") String deployId); } flowable/src/main/java/com/ycl/service/IFlowDefinitionService.java
@@ -37,6 +37,17 @@ void importFile(String name, String category, InputStream in); /** * 更新部署的流程,不再重新部署 * * @param deploymentId * @param name * @param category * @param in */ void updateProcess(String deploymentId, String name, String category, InputStream in); /** * 读取xml * @param deployId * @return @@ -77,4 +88,6 @@ * @return */ InputStream readImage(String deployId); } flowable/src/main/java/com/ycl/service/impl/FlowDefinitionServiceImpl.java
@@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.ycl.cmd.RemoveDeploymentCacheCMD; import com.ycl.common.constant.ProcessConstants; import com.ycl.common.core.domain.AjaxResult; import com.ycl.common.core.domain.entity.SysUser; @@ -20,6 +21,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.flowable.bpmn.model.BpmnModel; import org.flowable.engine.ManagementService; import org.flowable.engine.repository.Deployment; import org.flowable.engine.repository.ProcessDefinition; import org.flowable.engine.repository.ProcessDefinitionQuery; @@ -28,6 +30,7 @@ import org.flowable.task.api.Task; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.io.IOException; @@ -50,12 +53,10 @@ public class FlowDefinitionServiceImpl extends FlowServiceFactory implements IFlowDefinitionService { private final ISysDeployFormService sysDeployFormService; private final ISysUserService sysUserService; private final ISysDeptService sysDeptService; private final FlowDeployMapper flowDeployMapper; private final ManagementService managementService; private static final String BPMN_FILE_SUFFIX = ".bpmn"; @@ -135,6 +136,21 @@ } @Override public void updateProcess(String deploymentId, String name, String category, InputStream in) { if (! StringUtils.hasText(deploymentId)) { throw new RuntimeException("该流程第一次部署,请直接选择保存按钮"); } ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult(); if (Objects.isNull(processDefinition)) { throw new RuntimeException("流程定义不存在"); } // 1.更新流程图数据 flowDeployMapper.updateProcess(in, deploymentId); // 2.清除该流程的缓存,使其重新加载新的流程图 managementService.executeCommand(new RemoveDeploymentCacheCMD(processDefinition.getId())); } /** * 读取xml * flowable/src/main/resources/mapper/FlowDeployMapper.xml
@@ -82,4 +82,8 @@ order by rd.deploy_time_ desc </select> <update id="updateProcess"> UPDATE act_ge_bytearray SET BYTES_ = #{bytes, jdbcType=BLOB} WHERE DEPLOYMENT_ID_ = #{deployId} AND GENERATED_ = 0 </update> </mapper>