From 9f4991f32f73b5eebe2acf799de51171eead7d34 Mon Sep 17 00:00:00 2001 From: dataprince Date: Sat, 13 Jan 2024 08:56:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0SQL=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.yml | 44 +++++++++++++++++++ .../src/main/resources/application-prod.yml | 4 ++ .../src/main/resources/application.yml | 2 +- .../common/orm/config/MyBatisFlexConfig.java | 27 +++++++++--- 4 files changed, 69 insertions(+), 8 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index e792ca4..b594f2a 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -18,6 +18,10 @@ spring: # 多久检查一次连接的活性 keepaliveTime: 30000 mybatis-flex: + # sql审计 + audit_enable: true + # sql打印 + sql_print: true datasource: # 数据源-1 ds1: @@ -113,3 +117,43 @@ powerjob: allow-lazy-connect-server: false max-appended-wf-context-length: 4096 max-result-length: 4096 + +--- # sms 短信 支持 华为 阿里云 腾讯云 等等各式各样的短信服务商 +# https://sms4j.com/doc3/ 文档地址 各个厂商可同时使用 +sms: + # 标注从yml读取配置 + config-type: yaml + is-print: true + blends: + # 自定义的标识,也就是configId这里可以是任意值(最好不要是中文) + tx1: + #厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分 + supplier: tencent + #您的accessKey + access-key-id: 您的accessKey + #您的accessKeySecret + access-key-secret: 您的accessKeySecret + #您的短信签名 + signature: 您的短信签名 + #模板ID 非必须配置,如果使用sendMessage的快速发送需此配置 + template-id: xxxxxxxx + #短信自动重试间隔时间 默认五秒 + retry-interval: 5 + # 短信重试次数,默认0次不重试,如果你需要短信重试则根据自己的需求修改值即可 + max-retries: 0 + #您的sdkAppId + sdk-app-id: 您的sdkAppId + # 自定义的标识,也就是configId这里可以是任意值(最好不要是中文) + tx2: + #厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分 + supplier: tencent + #您的accessKey + access-key-id: 您的accessKey + #您的accessKeySecret + access-key-secret: 您的accessKeySecret + #您的短信签名 + signature: 您的短信签名 + #模板ID 非必须配置,如果使用sendMessage的快速发送需此配置 + template-id: xxxxxxxx + #您的sdkAppId + sdk-app-id: 您的sdkAppId diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index b3afd6d..f8afca2 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -18,6 +18,10 @@ spring: # 多久检查一次连接的活性 keepaliveTime: 30000 mybatis-flex: + # sql审计 + audit_enable: false + # sql打印 + sql_print: false datasource: # 数据源-1 ds1: diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index de81957..2bb5756 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -134,7 +134,7 @@ mybatis-flex: # 关闭日志记录 org.apache.ibatis.logging.nologging.NoLoggingImpl # 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl #log_impl: org.apache.ibatis.logging.stdout.StdOutImpl - logImpl: org.apache.ibatis.logging.stdout.StdOutImpl + logImpl: org.apache.ibatis.logging.nologging.NoLoggingImpl cacheEnabled: true global-config: # 是否控制台打印 MyBatis-Flex 的 LOGO 及版本号 diff --git a/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/config/MyBatisFlexConfig.java b/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/config/MyBatisFlexConfig.java index 739b21b..1fedd5b 100644 --- a/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/config/MyBatisFlexConfig.java +++ b/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/config/MyBatisFlexConfig.java @@ -3,6 +3,7 @@ package com.ruoyi.common.orm.config; import com.mybatisflex.core.FlexGlobalConfig; import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.audit.ConsoleMessageCollector; +import com.mybatisflex.core.audit.MessageCollector; import com.mybatisflex.core.datasource.DataSourceDecipher; import com.mybatisflex.core.mybatis.FlexConfiguration; import com.mybatisflex.spring.boot.ConfigurationCustomizer; @@ -12,11 +13,11 @@ import com.ruoyi.common.orm.decipher.Decipher; import com.ruoyi.common.orm.listener.EntityInsertListener; import com.ruoyi.common.orm.listener.EntityUpdateListener; import org.apache.ibatis.logging.stdout.StdOutImpl; -import org.mybatis.spring.annotation.MapperScan; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.beans.factory.annotation.Value; /** @@ -29,6 +30,12 @@ public class MyBatisFlexConfig implements ConfigurationCustomizer, MyBatisFlexCu private static final Logger logger = LoggerFactory.getLogger("mybatis-flex-sql"); + @Value("${mybatis-flex.audit_enable}") + private Boolean enableAudit = false; + + @Value("${mybatis-flex.sql_print}") + private Boolean sqlPrint = false; + /** * 数据源解密 */ @@ -40,8 +47,10 @@ public class MyBatisFlexConfig implements ConfigurationCustomizer, MyBatisFlexCu @Override public void customize(FlexConfiguration configuration) { - //mybatis实现的打印sql到控制台,便于调试 - configuration.setLogImpl(StdOutImpl.class); + //mybatis实现的打印详细sql及返回结果到控制台,便于调试 + if (sqlPrint) { + configuration.setLogImpl(StdOutImpl.class); + } } /** @@ -56,10 +65,14 @@ public class MyBatisFlexConfig implements ConfigurationCustomizer, MyBatisFlexCu globalConfig.registerUpdateListener(new EntityUpdateListener(), BaseEntity.class); // 开启审计功能 - AuditManager.setAuditEnable(true); -// AuditManager.setMessageFactory(new AuditMessageFactory()); - // 设置 SQL 审计收集器 - AuditManager.setMessageCollector(new ConsoleMessageCollector()); + AuditManager.setAuditEnable(enableAudit); + if (sqlPrint) { + // 开启sql打印默认会开启sql审计 + AuditManager.setAuditEnable(true); + //设置 SQL 审计收集器 + MessageCollector collector = new ConsoleMessageCollector(); + AuditManager.setMessageCollector(collector); + } } }