From 659b8c12e1b655eabf6010a67bdb784a024ab169 Mon Sep 17 00:00:00 2001
From: 11353 <1135361399@qq.com>
Date: Sat, 26 Mar 2022 22:36:37 +0800
Subject: [PATCH] =?UTF-8?q?fix:=E6=89=93=E5=8D=B0sql?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 17 +++++
.../utils/jasyptEncryptUtils.java | 6 ++
.../main/resources/mybatisPlus/JasyptAll.yaml | 7 +-
ruoyi-common/ruoyi-common-log/pom.xml | 14 +++-
.../ruoyi/common/log/p6spy/P6SpyLogger.java | 29 ++++++++
.../ruoyi/common/log/p6spy/StdoutLogger.java | 19 +++++
.../ruoyi/common/log/utils/JansiUtils.java | 73 +++++++++++++++++++
.../src/main/resources/spy.properties | 24 ++++++
ruoyi-modules/ruoyi-system/pom.xml | 11 +++
9 files changed, 196 insertions(+), 4 deletions(-)
create mode 100644 ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/p6spy/P6SpyLogger.java
create mode 100644 ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/p6spy/StdoutLogger.java
create mode 100644 ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/utils/JansiUtils.java
create mode 100644 ruoyi-common/ruoyi-common-log/src/main/resources/spy.properties
diff --git a/pom.xml b/pom.xml
index da39c26a..41a5bc8d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,6 +41,8 @@
8.2.2
4.1.2
3.2.2
+ 3.9.1
+ 2.4.0
2.12.2
@@ -262,6 +264,21 @@
${ruoyi.version}
+
+
+ p6spy
+ p6spy
+ ${p6spy.version}
+
+
+
+
+ org.fusesource.jansi
+ jansi
+ ${fusesource.jansi.version}
+
+
+
diff --git a/ruoyi-common/pinn-common-extend/src/main/java/com/pinn/publicPackage/utils/jasyptEncryptUtils.java b/ruoyi-common/pinn-common-extend/src/main/java/com/pinn/publicPackage/utils/jasyptEncryptUtils.java
index 764b30a3..f23291ca 100644
--- a/ruoyi-common/pinn-common-extend/src/main/java/com/pinn/publicPackage/utils/jasyptEncryptUtils.java
+++ b/ruoyi-common/pinn-common-extend/src/main/java/com/pinn/publicPackage/utils/jasyptEncryptUtils.java
@@ -25,8 +25,10 @@ public class jasyptEncryptUtils {
final static String SUFFIX = "]";
public static void main(String[] args) {
+// p6spy损耗性能 生产不使用
HashMap dataSource = MapUtil.newHashMap();
dataSource.put("url","jdbc:mysql://175.178.38.240:9033/ry_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
+ dataSource.put("p6spyurl","jdbc:p6spy:mysql://175.178.38.240:9033/ry_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
dataSource.put("username","nacos");
dataSource.put("password","nacos2233");
@@ -53,6 +55,7 @@ public class jasyptEncryptUtils {
public static void decryptDataSource(Map dataSource){
String key = AESMybatisPlusUtils.genOrGetKey();
String url = decryptPwd(key,dataSource.get("url"));
+ String p6spyurl = decryptPwd(key,dataSource.get("p6spyurl"));
String username = decryptPwd(key,dataSource.get("username"));
String password = decryptPwd(key,dataSource.get("password"));
@@ -60,6 +63,7 @@ public class jasyptEncryptUtils {
FileWriter writer = new FileWriter(new File(FILE_PATCH_DE), CHARSET_UTF8);
writer.write("key: "+ key + LINE,false);
writer.write("url: " +url + LINE,true);
+ writer.write("p6spyurl: " + PREFIX +p6spyurl + SUFFIX + LINE,true);
writer.write("username: " +username + LINE,true);
writer.write("password: " +password + LINE,true);
}
@@ -71,12 +75,14 @@ public class jasyptEncryptUtils {
public static void encryptionDataSource(Map dataSource){
String key = AESMybatisPlusUtils.genOrGetKey();
String url = encryptPwd(key,dataSource.get("url"));
+ String p6spyurl = encryptPwd(key,dataSource.get("p6spyurl"));
String username = encryptPwd(key,dataSource.get("username"));
String password = encryptPwd(key,dataSource.get("password"));
//保存在目录下
FileWriter writer = new FileWriter(new File(FILE_PATCH_ALL), CHARSET_UTF8);
writer.write("key: "+ key + LINE,false);
writer.write("url: " + PREFIX +url + SUFFIX + LINE,true);
+ writer.write("p6spyurl: " + PREFIX +p6spyurl + SUFFIX + LINE,true);
writer.write("username: " + PREFIX +username + SUFFIX + LINE,true);
writer.write("password: " + PREFIX +password + SUFFIX + LINE,true);
}
diff --git a/ruoyi-common/pinn-common-extend/src/main/resources/mybatisPlus/JasyptAll.yaml b/ruoyi-common/pinn-common-extend/src/main/resources/mybatisPlus/JasyptAll.yaml
index 1eb7f74e..b98f5319 100644
--- a/ruoyi-common/pinn-common-extend/src/main/resources/mybatisPlus/JasyptAll.yaml
+++ b/ruoyi-common/pinn-common-extend/src/main/resources/mybatisPlus/JasyptAll.yaml
@@ -1,4 +1,5 @@
key: aa78fcbe21d77af8
-url: PINN@[b43OeNppIVyLnbWEybBFR7ilgcIOkQz5Mkb2tWtOuugrQoTxjpf3hozwU8LRSpboCAOf4WSAB9eknmbS15qX42/e6g1XmmJCsSAwx3TswOjX9x6BgjcDiWrUcYx4ZiNS9wO79ieCkLdeWRW1AZ6msuFV0JGRQNMpsLaJjwra2BZ4Hldq88EDjyZntBvT2s58EXM/bjMKIQhynkUibEbAhw==]
-username: PINN@[WEciwJ1eT6ZjAMncoppuow==]
-password: PINN@[YZXfQ+pMtdFaMCxbKy5ey5BfxIG2RQnZ]
+url: PINN@[DeBx+L2NxMoLVRK5aFJal930HSNKNRDjyw8k9SfphiNauMBtB0BVeigeVoA4zncZl8KklrjYq6r7yvnGN/54eCZSa+/ZisvGO8LLywPKP9XXEPs0Ar4cMvX3EDMDgJsitmOUNID4VD7a4tBOEXituKYdBt2d97etv3F2SV6PUALj7i11qqI0sPWmgLcRohpWdZ8heJAmZcRKNGySQLpwWQ==]
+p6spyurl: PINN@[wwmRkyryca6C99kAK/fCHtJBxYLY++/PKLOLI/ZDZ1v1+2G9qIqtc3jN/WTBbj0vAoITV16e/f/NQ19hu970+zGfVMN37bB0kDfNQ8Jc5qDH0OOfFR1MGL231clxmCUe4TNSyIHh4ti+IiAnaeUPXNWJAxxd/oWQeaKw96GT9F9UlF0upolfNwhhigeQpFLWEC5l6k9B7/2sNAscxoeBQoQEnl8ON7rR]
+username: PINN@[cftYM6QehEHfdIe8DCLqxw==]
+password: PINN@[Yf+zXisp7902VzH2hoHqyvJD5GINf7Xh]
diff --git a/ruoyi-common/ruoyi-common-log/pom.xml b/ruoyi-common/ruoyi-common-log/pom.xml
index 5dc1f8e4..0310aa49 100644
--- a/ruoyi-common/ruoyi-common-log/pom.xml
+++ b/ruoyi-common/ruoyi-common-log/pom.xml
@@ -22,6 +22,18 @@
com.ruoyi
ruoyi-common-security
-
+
+
+
+ p6spy
+ p6spy
+
+
+
+
+ org.fusesource.jansi
+ jansi
+
+
\ No newline at end of file
diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/p6spy/P6SpyLogger.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/p6spy/P6SpyLogger.java
new file mode 100644
index 00000000..fa03f2fa
--- /dev/null
+++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/p6spy/P6SpyLogger.java
@@ -0,0 +1,29 @@
+package com.ruoyi.common.log.p6spy;
+
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
+
+/**
+ * P6spy SQL 打印策略
+ *
+ * @author hubin
+ * @since 2019-02-20
+ */
+public class P6SpyLogger implements MessageFormattingStrategy {
+
+ @Override
+ public String formatMessage(int connectionId, String now, long elapsed, String category,
+ String prepared, String sql, String url) {
+ return StringUtils.isNotBlank(sql)
+ ?
+ "\n Consume Time:"
+ + elapsed +
+ " ms "
+ + now +
+ "\n Execute SQL:"
+ +"\n\t\t"+ sql.replaceAll("[\\s]+", " ")
+ + "\n Execution Result ↓↓↓"
+ :
+ "Not Sql Info \n";
+ }
+}
diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/p6spy/StdoutLogger.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/p6spy/StdoutLogger.java
new file mode 100644
index 00000000..9508aac4
--- /dev/null
+++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/p6spy/StdoutLogger.java
@@ -0,0 +1,19 @@
+package com.ruoyi.common.log.p6spy;
+
+import com.ruoyi.common.log.aspect.LogAspect;
+import com.ruoyi.common.log.utils.JansiUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 输出 SQL 日志
+ *
+ * @author hubin
+ * @since 2019-02-20
+ */
+public class StdoutLogger extends com.p6spy.engine.spy.appender.StdoutLogger {
+ @Override
+ public void logText(String text) {
+ JansiUtils.info(text);
+ }
+}
diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/utils/JansiUtils.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/utils/JansiUtils.java
new file mode 100644
index 00000000..e089a64d
--- /dev/null
+++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/utils/JansiUtils.java
@@ -0,0 +1,73 @@
+package com.ruoyi.common.log.utils;
+
+import com.ruoyi.common.log.aspect.LogAspect;
+import org.fusesource.jansi.Ansi;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.fusesource.jansi.Ansi.*;
+import static org.fusesource.jansi.Ansi.Color.*;
+
+public class JansiUtils {
+ private static final Logger log = LoggerFactory.getLogger(LogAspect.class);
+
+ public static void info(String text){
+ info(text,null);
+ }
+ public static void debug(String text){
+ debug(text,null);
+ }
+ public static void warn(String text){
+ warn(text,null);
+ }
+ public static void err(String text){
+ err(text,null);
+ }
+ public static void trace(String text){
+ trace(text,null);
+ }
+
+
+
+ public static void info(String text,Object o){
+ setColor(BLUE);
+ log.info(text,o);
+ reset();
+ }
+ public static void debug(String text,Object o){
+ setColor(GREEN);
+ log.debug(text,o);
+ reset();
+ }
+ public static void warn(String text,Object o){
+ setColor(YELLOW);
+ log.warn(text,o);
+ reset();
+ }
+ public static void err(String text,Object o){
+ setColor(RED);
+ log.error(text,o);
+ reset();
+ }
+ public static void trace(String text,Object o){
+ setColor(CYAN);
+ log.trace(text,o);
+ reset();
+ }
+
+
+ /**
+ * 设置颜色
+ * @param color
+ */
+ private static void setColor(Ansi.Color color){
+ System.out.print(ansi().eraseScreen().fg(color));
+ }
+
+ /**
+ * 关闭颜色输出
+ */
+ private static void reset(){
+ System.out.print(ansi().eraseScreen().reset());
+ }
+}
diff --git a/ruoyi-common/ruoyi-common-log/src/main/resources/spy.properties b/ruoyi-common/ruoyi-common-log/src/main/resources/spy.properties
new file mode 100644
index 00000000..72429012
--- /dev/null
+++ b/ruoyi-common/ruoyi-common-log/src/main/resources/spy.properties
@@ -0,0 +1,24 @@
+#3.2.1????
+modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory
+#3.2.1?????????
+#modulelist=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
+# ???????
+logMessageFormat=com.ruoyi.common.log.p6spy.P6SpyLogger
+#????????
+appender=com.ruoyi.common.log.p6spy.StdoutLogger
+# ???????? sql
+# appender=com.p6spy.engine.spy.appender.Slf4JLogger
+# ?? p6spy driver ??
+deregisterdrivers=true
+# ??JDBC URL??
+useprefix=true
+# ???? Log ??,????????error,info,batch,debug,statement,commit,rollback,result,resultset.
+excludecategories=info,debug,result,commit,resultset
+# ????
+dateformat=yyyy-MM-dd HH:mm:ss
+# ???????
+#driverlist=org.h2.Driver
+# ?????SQL??
+outagedetection=true
+# ?SQL???? 2 ?
+outagedetectioninterval=2
\ No newline at end of file
diff --git a/ruoyi-modules/ruoyi-system/pom.xml b/ruoyi-modules/ruoyi-system/pom.xml
index 4e1c7336..a76e4362 100644
--- a/ruoyi-modules/ruoyi-system/pom.xml
+++ b/ruoyi-modules/ruoyi-system/pom.xml
@@ -89,6 +89,17 @@
mybatis-plus-boot-starter
+
+ p6spy
+ p6spy
+
+
+
+
+ org.fusesource.jansi
+ jansi
+
+