From 7a8e71f91eb3f39bd478cfcbed582ff84719894e Mon Sep 17 00:00:00 2001 From: hetianchen <604582768@qq.com> Date: Wed, 16 Dec 2020 22:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=97=B6=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../log/service/SystemInistService.java | 71 ++++++++++++++++++ .../common/log/utils/SystemInfoPrinter.java | 72 +++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/SystemInistService.java create mode 100644 ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/utils/SystemInfoPrinter.java diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/SystemInistService.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/SystemInistService.java new file mode 100644 index 00000000..3edfb66e --- /dev/null +++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/SystemInistService.java @@ -0,0 +1,71 @@ +package com.ruoyi.common.log.service; + +import com.ruoyi.common.log.utils.SystemInfoPrinter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * 系统启动服务,用于检查系统状态及打印系统信息 + */ + +@SuppressWarnings("unused") +@Component +class SystemInistService { + private SystemInistService systemInistService; + + @Autowired + private Environment environment; + + @PostConstruct + private void inist() { + systemInistService = this; + + try { + SystemInfoPrinter.printInfo("dts 初始化信息", getSystemInfo()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private Map getSystemInfo() { + + Map infos = new LinkedHashMap<>(); + + infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 0, "系统信息"); + // 测试获取application-db.yml配置信息 + infos.put("服务器端口", environment.getProperty("server.port")); + infos.put("数据库USER", environment.getProperty("spring.datasource.druid.username")); + infos.put("数据库地址", environment.getProperty("spring.datasource.druid.url")); + infos.put("调试级别", environment.getProperty("logging.level.com.qiguliuxing.dts.wx")); + + // 测试获取application-core.yml配置信息 + infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 1, "模块状态"); + infos.put("邮件", environment.getProperty("dts.notify.mail.enable")); + infos.put("短信", environment.getProperty("dts.notify.sms.enable")); + infos.put("模版消息", environment.getProperty("dts.notify.wx.enable")); + infos.put("快递信息", environment.getProperty("dts.express.enable")); + infos.put("快递鸟ID", environment.getProperty("dts.express.appId")); + infos.put("对象存储", environment.getProperty("dts.storage.active")); + infos.put("本地对象存储路径", environment.getProperty("dts.storage.local.storagePath")); + infos.put("本地对象访问地址", environment.getProperty("dts.storage.local.address")); + infos.put("本地对象访问端口", environment.getProperty("dts.storage.local.port")); + + // 微信相关信息,屏蔽打印控制台 + infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 2, "微信相关"); + infos.put("微信APP KEY", environment.getProperty("dts.wx.app-id")); + infos.put("微信APP-SECRET", environment.getProperty("dts.wx.app-secret")); + infos.put("微信支付MCH-ID", environment.getProperty("dts.wx.mch-id")); + infos.put("微信支付MCH-KEY", environment.getProperty("dts.wx.mch-key")); + infos.put("微信支付通知地址", environment.getProperty("dts.wx.notify-url")); + + // 测试获取System表配置信息 + infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 3, "系统设置"); + + return infos; + } +} diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/utils/SystemInfoPrinter.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/utils/SystemInfoPrinter.java new file mode 100644 index 00000000..fd36cd31 --- /dev/null +++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/utils/SystemInfoPrinter.java @@ -0,0 +1,72 @@ +package com.ruoyi.common.log.utils; + +import java.util.Map; + +public class SystemInfoPrinter { + public static final String CREATE_PART_COPPER = "XOXOXOXOX"; + + private static int maxSize = 0; + + public static void printInfo(String title, Map infos) { + setMaxSize(infos); + + printHeader(title); + + for (Map.Entry entry : infos.entrySet()) { + printLine(entry.getKey(), entry.getValue()); + } + + printEnd(); + } + + private static void setMaxSize(Map infos) { + for (Map.Entry entry : infos.entrySet()) { + if (entry.getValue() == null) { + continue; + } + + int size = entry.getKey().length() + entry.getValue().length(); + + if (size > maxSize) { + maxSize = size; + } + } + + maxSize = maxSize + 30; + } + + private static void printHeader(String title) { + System.out.println(getLineCopper()); + System.out.println(""); + System.out.println(" " + title); + System.out.println(""); + } + + private static void printEnd() { + System.out.println(" "); + System.out.println(getLineCopper()); + } + + private static String getLineCopper() { + String copper = ""; + for (int i = 0; i < maxSize; i++) { + copper += "="; + } + + return copper; + } + + private static void printLine(String head, String line) { + if (line == null) { + return; + } + + if (head.startsWith(CREATE_PART_COPPER)) { + System.out.println(""); + System.out.println(" [[ " + line + " ]]"); + System.out.println(""); + } else { + System.out.println(" " + head + " -> " + line); + } + } +}