@@ -3,7 +3,7 @@ package com.zyplayer.doc.manage.framework.config;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import com.zyplayer.doc.manage.framework.interceptor.MoudleMissingInterceptor;
|
||||
import com.zyplayer.doc.manage.framework.interceptor.ModuleMissingInterceptor;
|
||||
import com.zyplayer.doc.manage.framework.interceptor.UserLoginInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -35,7 +35,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
@Resource
|
||||
UserLoginInterceptor userLoginInterceptor;
|
||||
@Resource
|
||||
MoudleMissingInterceptor moudleMissingInterceptor;
|
||||
ModuleMissingInterceptor moduleMissingInterceptor;
|
||||
|
||||
@Override
|
||||
public void addFormatters(FormatterRegistry registry) {
|
||||
@@ -69,7 +69,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
registry.addInterceptor(userLoginInterceptor)
|
||||
.excludePathPatterns("/", "/doc-wiki", "/doc-db", "/doc-swagger-plus")
|
||||
.excludePathPatterns("/**/*.js", "/**/*.css", "/**/*.png", "/**/*.gif", "/**/*.jpg", "/**/*.jpeg", "/**/fonts/*");
|
||||
registry.addInterceptor(moudleMissingInterceptor)
|
||||
registry.addInterceptor(moduleMissingInterceptor)
|
||||
.excludePathPatterns("/", "/doc-wiki", "/doc-db", "/doc-swagger-plus")
|
||||
.excludePathPatterns("/**/*.js", "/**/*.css", "/**/*.png", "/**/*.gif", "/**/*.jpg", "/**/*.jpeg", "/**/fonts/*");
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ import java.util.HashMap;
|
||||
* @since 2023年6月15日
|
||||
*/
|
||||
@Configuration
|
||||
public class ZyplayerMoudleKeeper implements ApplicationContextAware {
|
||||
HashMap<String, Boolean> moudleInfo = new HashMap<>();
|
||||
public class ZyplayerModuleKeeper implements ApplicationContextAware {
|
||||
HashMap<String, Boolean> moduleInfo = new HashMap<>();
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
@@ -25,29 +25,29 @@ public class ZyplayerMoudleKeeper implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
//获取模块是否启动
|
||||
public boolean isMoudleStarted(Class<?> clazz) {
|
||||
if (moudleInfo.size() < 1) {
|
||||
getMoudleInfo();
|
||||
public boolean ismoduleStarted(Class<?> clazz) {
|
||||
if (moduleInfo.size() < 1) {
|
||||
getmoduleInfo();
|
||||
}
|
||||
return moudleInfo.get(clazz.getName().split("\\$")[1]);
|
||||
return moduleInfo.get(clazz.getName().split("\\$")[1]);
|
||||
}
|
||||
|
||||
//提供模块开启状态数组,给前端控制页面展示
|
||||
public HashMap<String, Boolean> getMoudleInfo() {
|
||||
if (moudleInfo.size() < 1) {
|
||||
synchronized (ZyplayerMoudleKeeper.class) {
|
||||
public HashMap<String, Boolean> getmoduleInfo() {
|
||||
if (moduleInfo.size() < 1) {
|
||||
synchronized (ZyplayerModuleKeeper.class) {
|
||||
Class<? extends ZyplayerDocConfig> clazz = ZyplayerDocConfig.class;
|
||||
Class<?>[] innerClasses = clazz.getClasses();
|
||||
for (Class<?> innerClass : innerClasses) {
|
||||
moudleInfo.put(innerClass.getName().split("\\$")[1], isMoudleConfigLoadUp(innerClass));
|
||||
moduleInfo.put(innerClass.getName().split("\\$")[1], ismoduleConfigLoadUp(innerClass));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return moudleInfo;
|
||||
return moduleInfo;
|
||||
}
|
||||
|
||||
private Boolean isMoudleConfigLoadUp(Class<?> innerClass) {
|
||||
private Boolean ismoduleConfigLoadUp(Class<?> innerClass) {
|
||||
Object bean = null;
|
||||
try {
|
||||
bean = applicationContext.getBean(innerClass);
|
||||
@@ -20,7 +20,7 @@ public class ApplicationInfoConsolePrint implements IConsolePrint {
|
||||
Environment environment;
|
||||
|
||||
@Override
|
||||
public void buildPrintInfo(StringBuffer printInfo) throws Exception {
|
||||
public void buildPrintInfo(StringBuilder printInfo) throws Exception {
|
||||
String contextPath = environment.getProperty("server.servlet.context-path");
|
||||
contextPath = Optional.ofNullable(contextPath).orElse("").replaceFirst("/", "");
|
||||
contextPath = (contextPath.length() <= 0 || contextPath.endsWith("/")) ? contextPath : contextPath + "/";
|
||||
|
||||
@@ -12,5 +12,5 @@ import java.net.UnknownHostException;
|
||||
* @since 2023年6月16日
|
||||
*/
|
||||
public interface IConsolePrint extends Ordered {
|
||||
public void buildPrintInfo(StringBuffer printInfo) throws Exception;
|
||||
public void buildPrintInfo(StringBuilder printInfo) throws Exception;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.zyplayer.doc.manage.framework.console;
|
||||
|
||||
import com.zyplayer.doc.manage.framework.config.ZyplayerModuleKeeper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 启动后打印模块信息
|
||||
*
|
||||
* @author Sh1yu
|
||||
* @since 2023年6月16日
|
||||
*/
|
||||
@Component
|
||||
public class ModuleInfoConsolePrint implements IConsolePrint {
|
||||
@Resource
|
||||
ZyplayerModuleKeeper moduleKeeper;
|
||||
|
||||
@Override
|
||||
public void buildPrintInfo(StringBuilder printInfo) throws Exception {
|
||||
printInfo.append("\n\n\t\t\t\t↓zyplayer-doc模块的启动情况\n")
|
||||
.append("\t\t\t\t------------------------\n");
|
||||
HashMap<String, Boolean> moduleInfoMap = moduleKeeper.getmoduleInfo();
|
||||
for (Map.Entry<String, Boolean> moduleInfo : moduleInfoMap.entrySet()) {
|
||||
printInfo.append(getPerfectPosString(moduleInfo.getKey()))
|
||||
.append("模块启动情况为:")
|
||||
.append(moduleInfo.getValue() ? "启动成功\n" : "未启动\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getPerfectPosString(String beforeOption) {
|
||||
final int rightOffsetMax = 19;
|
||||
String afterOption = beforeOption.replace("enable", "");
|
||||
int length = afterOption.length();
|
||||
int rightOffset = rightOffsetMax - length;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < rightOffset; i++) {
|
||||
stringBuilder.append(" ");
|
||||
}
|
||||
stringBuilder.append(afterOption);
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.zyplayer.doc.manage.framework.console;
|
||||
|
||||
import com.zyplayer.doc.manage.framework.config.ZyplayerMoudleKeeper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 启动后打印模块信息
|
||||
*
|
||||
* @author Sh1yu
|
||||
* @since 2023年6月16日
|
||||
*/
|
||||
@Component
|
||||
public class MoudleInfoConsolePrint implements IConsolePrint {
|
||||
@Resource
|
||||
ZyplayerMoudleKeeper moudleKeeper;
|
||||
|
||||
@Override
|
||||
public void buildPrintInfo(StringBuffer printInfo) throws Exception {
|
||||
printInfo.append("\n\n\t\t\t\t↓zyplayer-doc模块的启动情况\n")
|
||||
.append("\t\t\t\t------------------------\n");
|
||||
HashMap<String, Boolean> moudleInfos = moudleKeeper.getMoudleInfo();
|
||||
for (Map.Entry<String, Boolean> moudleInfo : moudleInfos.entrySet()) {
|
||||
printInfo.append(getPerfectPosString(moudleInfo.getKey()))
|
||||
.append("模块启动情况为:")
|
||||
.append(false == moudleInfo.getValue() ? "未启动\n" : "启动成功\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getPerfectPosString(String beforeString) {
|
||||
final int pointLeft = 19;
|
||||
String afterOptin = beforeString.replace("enable", "");
|
||||
int length = afterOptin.length();
|
||||
int rightOffset = pointLeft - length;
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int i = 0; i < rightOffset; i++) {
|
||||
stringBuffer.append(" ");
|
||||
}
|
||||
stringBuffer.append(afterOptin);
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -7,52 +7,47 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 程序启动后内容打印,新增打印内容只需要继承IConsolePrint
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @author Sh1yu
|
||||
* @since 2023年6月15日
|
||||
* @See IConsolePrint
|
||||
* @since 2023年6月15日
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class ZyplayerConsolePrint implements CommandLineRunner {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ZyplayerConsolePrint.class);
|
||||
StringBuffer logInfoHolder = new StringBuffer();
|
||||
StringBuilder logInfoHolder = new StringBuilder();
|
||||
|
||||
@Autowired
|
||||
ObjectProvider<List<IConsolePrint>> print;
|
||||
@Resource
|
||||
ObjectProvider<List<IConsolePrint>> consolePrintListProvider;
|
||||
|
||||
public void run(String... args) throws Exception {
|
||||
if (logger.isInfoEnabled()) {
|
||||
List<IConsolePrint> prints = print.getIfAvailable();
|
||||
if (prints.size() < 1) {
|
||||
if (!logger.isInfoEnabled()) {
|
||||
return;
|
||||
}
|
||||
List<IConsolePrint> consolePrintList = consolePrintListProvider.getIfAvailable();
|
||||
if (consolePrintList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
logInfoHolder.append("\n--------------------------------------------------------------\n\t");
|
||||
List<IConsolePrint> collect = prints.stream().sorted((a, b) -> {
|
||||
int aOrder = a.getOrder();
|
||||
int bOrder = b.getOrder();
|
||||
if (aOrder > bOrder) {
|
||||
return 1;
|
||||
}
|
||||
if (aOrder < bOrder) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}).collect(Collectors.toList());
|
||||
List<IConsolePrint> collect = consolePrintList.stream()
|
||||
.sorted(Comparator.comparingInt(IConsolePrint::getOrder))
|
||||
.collect(Collectors.toList());
|
||||
for (IConsolePrint consolePrint : collect) {
|
||||
consolePrint.buildPrintInfo(logInfoHolder);
|
||||
}
|
||||
logInfoHolder.append("--------------------------------------------------------------\n\t");
|
||||
logger.info(logInfoHolder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.zyplayer.doc.manage.framework.interceptor;
|
||||
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.manage.framework.config.ZyplayerDocConfig;
|
||||
import com.zyplayer.doc.manage.framework.config.ZyplayerModuleKeeper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 模块未开启时判定失败响应拦截器
|
||||
*
|
||||
* @author Sh1yu
|
||||
* @since 2023年6月15日
|
||||
*/
|
||||
@Component
|
||||
public class ModuleMissingInterceptor implements HandlerInterceptor {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ModuleMissingInterceptor.class);
|
||||
|
||||
|
||||
private static boolean enableWiki = true;
|
||||
private static boolean enableDb = true;
|
||||
private static boolean enableApi = true;
|
||||
|
||||
public ModuleMissingInterceptor(ZyplayerModuleKeeper zyplayerModuleKeeper){
|
||||
enableWiki= zyplayerModuleKeeper.ismoduleStarted(ZyplayerDocConfig.enableWiki.class);
|
||||
enableDb= zyplayerModuleKeeper.ismoduleStarted(ZyplayerDocConfig.enableWiki.class);
|
||||
enableApi= zyplayerModuleKeeper.ismoduleStarted(ZyplayerDocConfig.enableWiki.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
String requestURI = request.getRequestURI();
|
||||
String simplemoduleUri = requestURI.replace("/zyplayer-doc/", "");
|
||||
if (simplemoduleUri.startsWith("zyplayer-doc-wiki") && !enableWiki) {
|
||||
doFailResponse(response, "wiki模块未开启,无法提供相应功能");
|
||||
return false;
|
||||
}
|
||||
if (simplemoduleUri.startsWith("zyplayer-doc-db") && !enableDb) {
|
||||
doFailResponse(response, "db模块未开启,无法提供相应功能");
|
||||
return false;
|
||||
}
|
||||
if (simplemoduleUri.startsWith("zyplayer-doc-api") && !enableApi) {
|
||||
doFailResponse(response, "api模块未开启,无法提供相应功能");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean validate(String simpleModuleUri,String uriPrefix,boolean moduleEnabled,HttpServletResponse response,String failMsg){
|
||||
if (simpleModuleUri.startsWith(uriPrefix) && !moduleEnabled) {
|
||||
doFailResponse(response, failMsg);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void doFailResponse(HttpServletResponse response, String msg) {
|
||||
DocResponseJson.warn(msg).send(response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.zyplayer.doc.manage.framework.interceptor;
|
||||
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.manage.framework.config.ZyplayerDocConfig;
|
||||
import com.zyplayer.doc.manage.framework.config.ZyplayerMoudleKeeper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 模块未开启时判定失败响应拦截器
|
||||
*
|
||||
* @author Sh1yu
|
||||
* @since 2023年6月15日
|
||||
*/
|
||||
@Component
|
||||
public class MoudleMissingInterceptor implements HandlerInterceptor {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MoudleMissingInterceptor.class);
|
||||
|
||||
@Resource
|
||||
ZyplayerMoudleKeeper moudleKeeper;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
String requestURI = request.getRequestURI();
|
||||
String simpleMoudleUri = requestURI.replace("/zyplayer-doc/", "");
|
||||
if (simpleMoudleUri.startsWith("zyplayer-doc-wiki") && !moudleKeeper.isMoudleStarted(ZyplayerDocConfig.enableWiki.class)) {
|
||||
doFailResponse(response, "wiki模块未启动,无法提供相应功能");
|
||||
return false;
|
||||
}
|
||||
if (simpleMoudleUri.startsWith("zyplayer-doc-db") && !moudleKeeper.isMoudleStarted(ZyplayerDocConfig.enableDb.class)) {
|
||||
doFailResponse(response, "db模块未启动,无法提供相应功能");
|
||||
return false;
|
||||
}
|
||||
if (simpleMoudleUri.startsWith("zyplayer-doc-api") && !moudleKeeper.isMoudleStarted(ZyplayerDocConfig.enableApi.class)) {
|
||||
doFailResponse(response, "api模块未启动,无法提供相应功能");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void doFailResponse(HttpServletResponse response, String msg) {
|
||||
DocResponseJson.warn(msg).send(response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.zyplayer.doc.manage.web;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.manage.framework.config.ZyplayerDocConfig;
|
||||
import com.zyplayer.doc.manage.framework.config.ZyplayerMoudleKeeper;
|
||||
import com.zyplayer.doc.manage.framework.config.ZyplayerModuleKeeper;
|
||||
import com.zyplayer.doc.manage.framework.upgrade.UpgradeUtil;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -24,16 +24,16 @@ import javax.annotation.Resource;
|
||||
public class SystemInfoController {
|
||||
|
||||
@Resource
|
||||
ZyplayerMoudleKeeper moudleKeeper;
|
||||
ZyplayerModuleKeeper moduleKeeper;
|
||||
|
||||
@PostMapping("/upgrade")
|
||||
public ResponseJson<Object> upgradeInfo() {
|
||||
return DocResponseJson.ok(UpgradeUtil.upgradeInfo);
|
||||
}
|
||||
|
||||
@GetMapping("/moudle")
|
||||
public ResponseJson<Object> moudleInfo() {
|
||||
return DocResponseJson.ok(moudleKeeper.getMoudleInfo());
|
||||
@GetMapping("/module")
|
||||
public ResponseJson<Object> moduleInfo() {
|
||||
return DocResponseJson.ok(moduleKeeper.getmoduleInfo());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-console.png><title>文档管理系统</title><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=css/index.d05463e0.css rel=preload as=style><link href=js/chunk-vendors.cdec70f7.js rel=preload as=script><link href=js/index.8c8d6867.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/index.d05463e0.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-console-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.cdec70f7.js></script><script src=js/index.8c8d6867.js></script></body></html>
|
||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-console.png><title>文档管理系统</title><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=css/index.d05463e0.css rel=preload as=style><link href=js/chunk-vendors.cdec70f7.js rel=preload as=script><link href=js/index.3d3ddeef.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/index.d05463e0.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-console-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.cdec70f7.js></script><script src=js/index.3d3ddeef.js></script></body></html>
|
||||
File diff suppressed because one or more lines are too long
@@ -6,6 +6,6 @@ export default {
|
||||
return request({url: '/system/info/upgrade', method: 'post', data: Qs.stringify(data)});
|
||||
},
|
||||
fetchMoudleData: data => {
|
||||
return request({url: '/system/info/moudle', method: 'get', data: Qs.stringify(data)});
|
||||
return request({url: '/system/info/module', method: 'get', data: Qs.stringify(data)});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user