From 6a0815b2b534dc11b3a58f697ebec6ffae01374a Mon Sep 17 00:00:00 2001 From: hyy Date: Mon, 4 Nov 2024 15:21:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E6=95=B0=E6=8D=AE=E6=BA=90=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 14 ++++++-- .../framework/config/TransactionConfig.java | 32 +++++++++++++++++++ .../tool/gen/service/GenTableServiceImpl.java | 4 +++ src/main/resources/application-dev.yml | 16 +++++----- 4 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/jg/framework/config/TransactionConfig.java diff --git a/pom.xml b/pom.xml index f049195..aff6214 100644 --- a/pom.xml +++ b/pom.xml @@ -5,19 +5,19 @@ com.jg jg-boot - + 4.0.0 jar jg - + JG管理系统 org.springframework.boot spring-boot-starter-parent 2.5.15 - + @@ -37,6 +37,7 @@ 6.5.0 2.3 3.4.2 + 3.3.3 @@ -250,6 +251,13 @@ + + + com.taosdata.jdbc + taos-jdbcdriver + ${taos.version} + + diff --git a/src/main/java/com/jg/framework/config/TransactionConfig.java b/src/main/java/com/jg/framework/config/TransactionConfig.java new file mode 100644 index 0000000..6591b5e --- /dev/null +++ b/src/main/java/com/jg/framework/config/TransactionConfig.java @@ -0,0 +1,32 @@ +package com.jg.framework.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; + +/** + * TransactionConfig + * + * @author huangge1199 + * @since 2024/10/11 13:34:56 + */ +@Configuration +@EnableTransactionManagement +public class TransactionConfig { + + @Bean + public PlatformTransactionManager mysqlTransactionManager(DataSource mysqlDataSource) { + return new DataSourceTransactionManager(mysqlDataSource); + } + + @Bean + public PlatformTransactionManager tdengineTransactionManager(DataSource tdengineDataSource) { + DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(tdengineDataSource); + transactionManager.setRollbackOnCommitFailure(false); // 禁用自动回滚 + return transactionManager; + } +} diff --git a/src/main/java/com/jg/project/tool/gen/service/GenTableServiceImpl.java b/src/main/java/com/jg/project/tool/gen/service/GenTableServiceImpl.java index 53be3df..9916b4c 100644 --- a/src/main/java/com/jg/project/tool/gen/service/GenTableServiceImpl.java +++ b/src/main/java/com/jg/project/tool/gen/service/GenTableServiceImpl.java @@ -11,6 +11,9 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; + +import com.jg.framework.aspectj.lang.annotation.DataSource; +import com.jg.framework.aspectj.lang.enums.DataSourceType; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.velocity.Template; @@ -73,6 +76,7 @@ public class GenTableServiceImpl implements IGenTableService * @return 业务集合 */ @Override + @DataSource(value = DataSourceType.SLAVE) public List selectGenTableList(GenTable genTable) { return genTableMapper.selectGenTableList(genTable); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 213be75..b7954b7 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -2,20 +2,20 @@ spring: datasource: type: com.alibaba.druid.pool.DruidDataSource - driverClassName: com.mysql.cj.jdbc.Driver druid: # 主库数据源 master: - url: jdbc:mysql://localhost:3306/jgwebsite?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + url: jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: 123456 + driver-class-name: com.mysql.cj.jdbc.Driver # 从库数据源 slave: - # 从数据源开关/默认关闭 - enabled: false - url: - username: - password: + enabled: true + url: jdbc:TAOS://localhost:6030/ruoyi + username: root + password: taosdata + driver-class-name: com.taosdata.jdbc.TSDBDriver # 初始连接数 initialSize: 5 # 最小连接池数量 @@ -35,7 +35,7 @@ spring: # 配置一个连接在池中最大生存的时间,单位是毫秒 maxEvictableIdleTimeMillis: 900000 # 配置检测连接是否有效 - validationQuery: SELECT 1 FROM DUAL + validationQuery: SELECT 1 testWhileIdle: true testOnBorrow: false testOnReturn: false