|
|
|
@ -1,14 +1,22 @@
|
|
|
|
|
package cn.estsh.i3plus.core.apiservice.configuration;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemInitService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISystemResourceService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysLocaleLanguage;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysLocaleResource;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description :
|
|
|
|
|
* @Reference :
|
|
|
|
@ -24,9 +32,180 @@ public class AppStartSystemInit implements CommandLineRunner {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISystemInitService systemInitService;
|
|
|
|
|
|
|
|
|
|
@Resource(name="redisRes")
|
|
|
|
|
private ImppRedis redisRes;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
public ISystemResourceService systemResourceService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run(String... args) throws Exception {
|
|
|
|
|
LOGGER.info("【IMPP-Core开始加载基础数据...】");
|
|
|
|
|
LOGGER.info("【IMPP-Core开始绑定资源信息...】");
|
|
|
|
|
packIMPPResources();
|
|
|
|
|
|
|
|
|
|
LOGGER.info("【IMPP-Core开始加载基础信息...】");
|
|
|
|
|
systemInitService.loadAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化资源信息,并缓存
|
|
|
|
|
*/
|
|
|
|
|
public void packIMPPResources(){
|
|
|
|
|
/**
|
|
|
|
|
* 整体数据结构:
|
|
|
|
|
* code <lang : value>
|
|
|
|
|
* 先根据code查询,判断是否存在,然后通过语言获取对应的值
|
|
|
|
|
*/
|
|
|
|
|
HashMap<String,HashMap<String,String>> resMap = new HashMap();
|
|
|
|
|
HashMap<String,String> lanMap = null;
|
|
|
|
|
HashMap<String,HashMap<String,String>> webLangMap = new HashMap<>();
|
|
|
|
|
HashMap<String,String> webResMap;
|
|
|
|
|
|
|
|
|
|
//语言数量
|
|
|
|
|
List<SysLocaleLanguage> langList = systemResourceService.listSysLocaleLanguage(null);
|
|
|
|
|
|
|
|
|
|
//查询所有资源
|
|
|
|
|
List<SysLocaleResource> resourceList = systemResourceService.listSysLocaleResource(null);
|
|
|
|
|
LOGGER.info("【加载平台资源】共有{}个资源,{}种语言。",resourceList.size(),langList.size());
|
|
|
|
|
for(SysLocaleResource res : resourceList) {
|
|
|
|
|
//遍历资源,放入map中
|
|
|
|
|
lanMap = resMap.get(res.getResourceKey());
|
|
|
|
|
//判断是否已存在资源信息
|
|
|
|
|
if(lanMap == null){
|
|
|
|
|
lanMap = new HashMap<String,String>();
|
|
|
|
|
//将key/代码放入
|
|
|
|
|
resMap.put(res.getResourceKey(),lanMap);
|
|
|
|
|
}
|
|
|
|
|
//根据语言放入
|
|
|
|
|
lanMap.put(res.getLanguageCode(),res.getResourceValue());
|
|
|
|
|
|
|
|
|
|
// web 资源
|
|
|
|
|
if(!webLangMap.containsKey(res.getLanguageCode())){
|
|
|
|
|
webLangMap.put(res.getLanguageCode(),new HashMap<>());
|
|
|
|
|
}
|
|
|
|
|
// 放入资源信息
|
|
|
|
|
webResMap = webLangMap.get(res.getLanguageCode());
|
|
|
|
|
webResMap.put(res.getResourceKey(),res.getResourceValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(String key : resMap.keySet()){
|
|
|
|
|
//放入缓存
|
|
|
|
|
redisRes.putHashMap(key,resMap.get(key),0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(String key : webLangMap.keySet()){
|
|
|
|
|
//放入缓存
|
|
|
|
|
redisRes.putHashMap(key,webLangMap.get(key),0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGGER.info("【资源配置文件已全部加载:{}个】",resMap.size());
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//资源集合
|
|
|
|
|
HashMap<String,String> resMap;
|
|
|
|
|
|
|
|
|
|
//模块集合
|
|
|
|
|
HashMap<String,HashMap<String,String>> langModoleMap = new HashMap();
|
|
|
|
|
//功能集合
|
|
|
|
|
HashMap<String,HashMap<String,String>> langMethodMap = new HashMap();
|
|
|
|
|
//按钮集合
|
|
|
|
|
HashMap<String,HashMap<String,String>> langBtnMap = new HashMap();
|
|
|
|
|
//信息集合
|
|
|
|
|
HashMap<String,HashMap<String,String>> langMsgMap = new HashMap();
|
|
|
|
|
//异常集合
|
|
|
|
|
HashMap<String,HashMap<String,String>> langExMap = new HashMap();
|
|
|
|
|
|
|
|
|
|
*//************** 加载国际化 *************//*
|
|
|
|
|
for(SysLocaleLanguage lang : langList) {
|
|
|
|
|
*//************** 加载模块 *************//*
|
|
|
|
|
resource = new SysLocaleResource();
|
|
|
|
|
resource.setResourceType(CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.MODULE.getValue());
|
|
|
|
|
resource.setLanguageCode(lang.getLanguageCode());
|
|
|
|
|
resourceList = systemResourceService.listSysLocaleResource(resource);
|
|
|
|
|
|
|
|
|
|
if(resourceList.size() > 0) {
|
|
|
|
|
LOGGER.info("【{}-{},{}】共有{}个资源。", CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.MODULE.getDescription(),
|
|
|
|
|
lang.getLanguageName(), lang.getLanguageCode(), resourceList.size());
|
|
|
|
|
}
|
|
|
|
|
resMap = new HashMap<String,String>();
|
|
|
|
|
for(SysLocaleResource res : resourceList){
|
|
|
|
|
resMap.put(res.getResourceKey(),res.getResourceValue());
|
|
|
|
|
}
|
|
|
|
|
langModoleMap.put(lang.getLanguageCode(),resMap);
|
|
|
|
|
|
|
|
|
|
*//************** 加载功能 *************//*
|
|
|
|
|
resource = new SysLocaleResource();
|
|
|
|
|
resource.setResourceType(CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.METHOD.getValue());
|
|
|
|
|
resource.setLanguageCode(lang.getLanguageCode());
|
|
|
|
|
resourceList = systemResourceService.listSysLocaleResource(resource);
|
|
|
|
|
|
|
|
|
|
if(resourceList.size() > 0) {
|
|
|
|
|
LOGGER.info("【{}-{},{}】共有{}个资源。",CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.METHOD.getDescription(),
|
|
|
|
|
lang.getLanguageName(),lang.getLanguageCode(),resourceList.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resMap = new HashMap<String,String>();
|
|
|
|
|
for(SysLocaleResource res : resourceList){
|
|
|
|
|
resMap.put(res.getResourceKey(),res.getResourceValue());
|
|
|
|
|
}
|
|
|
|
|
langMethodMap.put(lang.getLanguageCode(),resMap);
|
|
|
|
|
|
|
|
|
|
*//************** 加载按钮 *************//*
|
|
|
|
|
resource = new SysLocaleResource();
|
|
|
|
|
resource.setResourceType(CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.BUTTON.getValue());
|
|
|
|
|
resource.setLanguageCode(lang.getLanguageCode());
|
|
|
|
|
resourceList = systemResourceService.listSysLocaleResource(resource);
|
|
|
|
|
|
|
|
|
|
if(resourceList.size() > 0) {
|
|
|
|
|
LOGGER.info("【{}-{},{}】共有{}个资源。", CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.BUTTON.getDescription(),
|
|
|
|
|
lang.getLanguageName(), lang.getLanguageCode(), resourceList.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resMap = new HashMap<String,String>();
|
|
|
|
|
for(SysLocaleResource res : resourceList){
|
|
|
|
|
resMap.put(res.getResourceKey(),res.getResourceValue());
|
|
|
|
|
}
|
|
|
|
|
langBtnMap.put(lang.getLanguageCode(),resMap);
|
|
|
|
|
|
|
|
|
|
*//************** 加载资源 *************//*
|
|
|
|
|
resource = new SysLocaleResource();
|
|
|
|
|
resource.setResourceType(CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.COMMON.getValue());
|
|
|
|
|
resource.setLanguageCode(lang.getLanguageCode());
|
|
|
|
|
resourceList = systemResourceService.listSysLocaleResource(resource);
|
|
|
|
|
|
|
|
|
|
if(resourceList.size() > 0) {
|
|
|
|
|
LOGGER.info("【{}-{},{}】共有{}个资源。", CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.COMMON.getDescription(),
|
|
|
|
|
lang.getLanguageName(), lang.getLanguageCode(), resourceList.size());
|
|
|
|
|
}
|
|
|
|
|
resMap = new HashMap<String,String>();
|
|
|
|
|
for(SysLocaleResource res : resourceList){
|
|
|
|
|
resMap.put(res.getResourceKey(),res.getResourceValue());
|
|
|
|
|
}
|
|
|
|
|
langMsgMap.put(lang.getLanguageCode(),resMap);
|
|
|
|
|
|
|
|
|
|
*//************** 加载异常 *************//*
|
|
|
|
|
resource = new SysLocaleResource();
|
|
|
|
|
resource.setResourceType(CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.EXCEPTION.getValue());
|
|
|
|
|
resource.setLanguageCode(lang.getLanguageCode());
|
|
|
|
|
resourceList = systemResourceService.listSysLocaleResource(resource);
|
|
|
|
|
|
|
|
|
|
if(resourceList.size() > 0) {
|
|
|
|
|
LOGGER.info("【{}-{},{}】共有{}个资源。", CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.EXCEPTION.getDescription(),
|
|
|
|
|
lang.getLanguageName(), lang.getLanguageCode(), resourceList.size());
|
|
|
|
|
}
|
|
|
|
|
resMap = new HashMap<String,String>();
|
|
|
|
|
for(SysLocaleResource res : resourceList){
|
|
|
|
|
resMap.put(res.getResourceKey(),res.getResourceValue());
|
|
|
|
|
}
|
|
|
|
|
langExMap.put(lang.getLanguageCode(),resMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redisCore.putHashMap(CommonConstWords.RES_PLAT_MODULE,langModoleMap);
|
|
|
|
|
redisCore.putHashMap(CommonConstWords.RES_PLAT_MODULE_METHOD,langMethodMap);
|
|
|
|
|
redisCore.putHashMap(CommonConstWords.RES_PLAT_MODULE_BUTTON,langBtnMap);
|
|
|
|
|
redisCore.putHashMap(CommonConstWords.RES_LANGUAGE_CONVERT,langMsgMap);
|
|
|
|
|
redisCore.putHashMap(CommonConstWords.RES_EXCEPTION_CONVERT,langExMap);
|
|
|
|
|
|
|
|
|
|
LOGGER.info("【资源配置文件已全部加载】");*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|