Commit b4d2d076 authored by Menethil's avatar Menethil
Browse files

增加系统启动初始化类,增加系统启动信息打印类

parent 3af6d8c3
......@@ -33,6 +33,11 @@ class ConfigService {
systemConfigService.inistConfigs();
}
/**
* 根据 prefix 重置该 prefix 下所有设置
*
* @param prefix
*/
public void reloadConfig(String prefix) {
List<LitemallSystem> list = litemallSystemConfigService.queryAll();
for (LitemallSystem item : list) {
......
......@@ -3,9 +3,8 @@ package org.linlinjava.litemall.core.system;
import java.math.BigDecimal;
/**
* 系统设置
* 系统设置,其他配置请参考该类的实现
*/
public class SystemConfig extends BaseConfig {
public static final String PRE_FIX = "litemall.system.";
......
package org.linlinjava.litemall.core.system;
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()) {
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 (head.startsWith(CREATE_PART_COPPER)) {
System.out.println("");
System.out.println(" [[ " + line + " ]]");
System.out.println("");
} else {
System.out.println(" " + head + " -> " + line);
}
}
}
package org.linlinjava.litemall.wx.service;
import org.linlinjava.litemall.core.system.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.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@Component
public class SystemInistService {
private SystemInistService systemInistService;
@Autowired
private Environment environment;
@PostConstruct
public void inist() {
systemInistService = this;
SystemInfoPrinter.printInfo("WX-API 初始化信息", getSystemInfo());
}
private Map<String, String> getSystemInfo() {
Map<String, String> infos = new LinkedHashMap<>();
infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 0, "系统信息");
// 测试获取application-db.yml配置信息
infos.put("数据库USER", environment.getProperty("spring.datasource.druid.username"));
infos.put("数据库地址", environment.getProperty("spring.datasource.druid.url"));
// 测试获取application.yml配置信息
infos.put("调试级别", environment.getProperty("logging.level.org.linlinjava.litemall.wx"));
infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 1, "模块状态");
infos.put("邮件", environment.getProperty("litemall.notify.mail.enable"));
infos.put("短信", environment.getProperty("litemall.notify.sms.enable"));
infos.put("模版消息", environment.getProperty("litemall.notify.wx.enable"));
infos.put("快递信息", environment.getProperty("litemall.express.enable"));
// 测试获取application-core.yml配置信息
infos.put("快递鸟ID", environment.getProperty("litemall.express.appId"));
infos.put("对象存储", environment.getProperty("litemall.storage.active"));
infos.put("本地对象存储路径", environment.getProperty("litemall.storage.local.storagePath"));
infos.put("本地对象访问地址", environment.getProperty("litemall.storage.local.address"));
infos.put("本地对象访问端口", environment.getProperty("litemall.storage.local.port"));
infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 2, "微信相关");
// 测试获取application-wx.yml配置信息
infos.put("微信APP KEY", environment.getProperty("litemall.wx.app-id"));
// 测试获取application-wx.yml配置信息
infos.put("微信APP-SECRET", environment.getProperty("litemall.wx.app-secret"));
// 测试获取application-wx.yml配置信息
infos.put("微信支付MCH-ID", environment.getProperty("litemall.wx.mch-id"));
// 测试获取application-wx.yml配置信息
infos.put("微信支付MCH-KEY", environment.getProperty("litemall.wx.mch-key"));
// 测试获取application-wx.yml配置信息
infos.put("微信支付通知地址", environment.getProperty("litemall.wx.notify-url"));
return infos;
}
}
......@@ -25,6 +25,8 @@ public class WxConfigTest {
System.out.println(environment.getProperty("spring.datasource.druid.url"));
// 测试获取application-wx.yml配置信息
System.out.println(environment.getProperty("litemall.wx.app-id"));
// 测试获取application-wx.yml配置信息
System.out.println(environment.getProperty("litemall.wx.notify-url"));
// 测试获取application.yml配置信息
System.out.println(environment.getProperty("logging.level.org.linlinjava.litemall.wx"));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment