From 6090356a42a816a69e86067cc91a728419451a7e Mon Sep 17 00:00:00 2001 From: huangqizhen <15552608129@163.com> Date: Sat, 11 Oct 2025 12:00:12 +0800 Subject: [PATCH] =?UTF-8?q?10.11=20=E8=BF=90=E8=A1=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/config/Mysql1DataSourceConfig.java | 11 +- .../demo/config/work/FlowableEngineConfig.java | 61 ++++++---- .../demo/controller/cash/CashRefundController.java | 4 + src/main/resources/application.yml | 7 +- src/main/resources/processes/work.bpmn20.xml | 132 --------------------- 5 files changed, 57 insertions(+), 158 deletions(-) delete mode 100644 src/main/resources/processes/work.bpmn20.xml diff --git a/src/main/java/com/example/demo/config/Mysql1DataSourceConfig.java b/src/main/java/com/example/demo/config/Mysql1DataSourceConfig.java index 717a28b..00f09e4 100644 --- a/src/main/java/com/example/demo/config/Mysql1DataSourceConfig.java +++ b/src/main/java/com/example/demo/config/Mysql1DataSourceConfig.java @@ -15,6 +15,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.PlatformTransactionManager; import javax.sql.DataSource; +import java.util.Arrays; @Slf4j @Configuration @@ -48,11 +49,19 @@ public DataSource mysql1DataSource() { @Qualifier("globalConfiguration1") org.apache.ibatis.session.Configuration globalConfiguration1) throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); - sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:{mapper,cashMapper}/*.xml")); + PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + + org.springframework.core.io.Resource[] mapperResources = resolver.getResources("classpath*:mapper/*.xml"); + org.springframework.core.io.Resource[] cashMapperResources = resolver.getResources("classpath*:cashMapper/*.xml"); + org.springframework.core.io.Resource[] allResources = Arrays.copyOf(mapperResources, mapperResources.length + cashMapperResources.length); + System.arraycopy(cashMapperResources, 0, allResources, mapperResources.length, cashMapperResources.length); + + sessionFactory.setMapperLocations(allResources); sessionFactory.setConfiguration(globalConfiguration1); return sessionFactory.getObject(); } + @Bean(name = "mysql1SqlSessionTemplate") // @Primary public SqlSessionTemplate mysql1SqlSessionTemplate(@Qualifier("mysql1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) { diff --git a/src/main/java/com/example/demo/config/work/FlowableEngineConfig.java b/src/main/java/com/example/demo/config/work/FlowableEngineConfig.java index 30e24e9..04d00ca 100644 --- a/src/main/java/com/example/demo/config/work/FlowableEngineConfig.java +++ b/src/main/java/com/example/demo/config/work/FlowableEngineConfig.java @@ -1,12 +1,8 @@ -// FlowableEngineConfig.java package com.example.demo.config.work; import org.flowable.common.engine.impl.history.HistoryLevel; -import org.flowable.engine.HistoryService; -import org.flowable.engine.RepositoryService; -import org.flowable.engine.RuntimeService; -import org.flowable.engine.TaskService; - +import org.flowable.engine.*; +import org.flowable.spring.ProcessEngineFactoryBean; import org.flowable.spring.SpringProcessEngineConfiguration; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; @@ -18,39 +14,56 @@ import javax.sql.DataSource; @Configuration public class FlowableEngineConfig { + /** + * 1. 创建 ProcessEngineFactoryBean + * Spring 会负责调用 buildProcessEngine() 并缓存实例 + */ @Bean - public SpringProcessEngineConfiguration processEngineConfiguration( - @Qualifier("flowableDataSource") DataSource flowableDataSource, + public ProcessEngineFactoryBean processEngineFactory( + @Qualifier("flowableDataSource") DataSource dataSource, @Qualifier("flowableTransactionManager") PlatformTransactionManager transactionManager) { - SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration(); - config.setDataSource(flowableDataSource); // 👈 指定 Flowable 数据源 - config.setTransactionManager(transactionManager); - config.setDatabaseSchemaUpdate("true"); // 自动建表 - config.setHistoryLevel(HistoryLevel.FULL).setAsyncExecutorActivate(false); // 记录完整历史 - // 暂时关闭异步执行器 + SpringProcessEngineConfiguration cfg = new SpringProcessEngineConfiguration(); + cfg.setDataSource(dataSource); + cfg.setTransactionManager(transactionManager); + cfg.setDatabaseSchemaUpdate("false"); // 自动建/升级表 + cfg.setHistoryLevel(HistoryLevel.FULL); // 记录完整历史 + cfg.setAsyncExecutorActivate(false); // 暂不开启异步执行器 + + ProcessEngineFactoryBean factory = new ProcessEngineFactoryBean(); + factory.setProcessEngineConfiguration(cfg); + return factory; + } + + /* 2. 各类 Service 注入 —— 都取自同一个 ProcessEngine *********************/ - return config; + @Bean + public RepositoryService repositoryService(ProcessEngine processEngine) { + return processEngine.getRepositoryService(); + } + + @Bean + public RuntimeService runtimeService(ProcessEngine processEngine) { + return processEngine.getRuntimeService(); } - // 👇 以下 Service Bean 可选,但推荐注入,方便 Controller 使用 @Bean - public RepositoryService repositoryService(SpringProcessEngineConfiguration config) { - return config.buildProcessEngine().getRepositoryService(); + public TaskService taskService(ProcessEngine processEngine) { + return processEngine.getTaskService(); } @Bean - public RuntimeService runtimeService(SpringProcessEngineConfiguration config) { - return config.buildProcessEngine().getRuntimeService(); + public HistoryService historyService(ProcessEngine processEngine) { + return processEngine.getHistoryService(); } @Bean - public TaskService taskService(SpringProcessEngineConfiguration config) { - return config.buildProcessEngine().getTaskService(); + public ManagementService managementService(ProcessEngine processEngine) { + return processEngine.getManagementService(); } @Bean - public HistoryService historyService(SpringProcessEngineConfiguration config) { - return config.buildProcessEngine().getHistoryService(); + public IdentityService identityService(ProcessEngine processEngine) { + return processEngine.getIdentityService(); } } \ No newline at end of file diff --git a/src/main/java/com/example/demo/controller/cash/CashRefundController.java b/src/main/java/com/example/demo/controller/cash/CashRefundController.java index 07f2bff..eeb36b6 100644 --- a/src/main/java/com/example/demo/controller/cash/CashRefundController.java +++ b/src/main/java/com/example/demo/controller/cash/CashRefundController.java @@ -89,4 +89,8 @@ public class CashRefundController { public Result update(@RequestBody CashCollection cashCollection){ return Result.success(cashRefundServiceImpl.update(cashCollection)); } +// @PostMapping("/local") +// public Result local(@RequestBody CashCollection cashCollection){ +// return Result.success(cashRefundServiceImpl.local(cashCollection)); +// } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 71be8c5..7231556 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -15,8 +15,13 @@ spring: name: demo mybatis: type-handlers-package: com.example.demo.Util - mapper-locations: classpath*:**/*Mapper.xml type-aliases-package: com.example.demo.domain.entity + mapper-locations: + - classpath:mapper/*.xml + - classpath:cashMapper/*.xml + - classpath:jindouMapper/*.xml + - classpath:liveMapper/*.xml + - classpath:paymapper/*.xml configuration: mysql1: map-underscore-to-camel-case: true diff --git a/src/main/resources/processes/work.bpmn20.xml b/src/main/resources/processes/work.bpmn20.xml deleted file mode 100644 index 6fb5574..0000000 --- a/src/main/resources/processes/work.bpmn20.xml +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - - - - - - - - - - - ${status=='12'} - - - ${status=='20'} - - - - - - - - ${status=='22'} - - - - ${status=='30'} - - - - - - - - - - - - - - - - - - - ${status=='40'} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -