启动时打印环境配置信息
This commit is contained in:
parent
e7d29757d2
commit
7a8e71f91e
|
|
@ -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<String, String> getSystemInfo() {
|
||||||
|
|
||||||
|
Map<String, String> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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<String, String> infos) {
|
||||||
|
setMaxSize(infos);
|
||||||
|
|
||||||
|
printHeader(title);
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> entry : infos.entrySet()) {
|
||||||
|
printLine(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
printEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setMaxSize(Map<String, String> infos) {
|
||||||
|
for (Map.Entry<String, String> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue