|
|
|
@ -7,13 +7,11 @@ import cn.estsh.i3plus.core.api.iservice.busi.ISystemResourceService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.Pager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysConfig;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysDictionary;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysLocaleLanguage;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysLocaleResource;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysMenu;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.*;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.repository.SysConfigRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.repository.SysDictionaryRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.repository.SysLocaleLanguageRepository;
|
|
|
|
@ -25,6 +23,7 @@ import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
@ -117,79 +116,100 @@ public class SystemInitService implements ISystemInitService {
|
|
|
|
|
@ApiOperation(value = "加载语言数据",notes = "加载语言数据")
|
|
|
|
|
public void putAndLoadSysLocaleLanguage() {
|
|
|
|
|
// Redis 缓存
|
|
|
|
|
if(type == ImppEnumUtil.SYS_CACHE_TYPE.REDIS.getValue()){
|
|
|
|
|
if (type == ImppEnumUtil.SYS_CACHE_TYPE.REDIS.getValue()) {
|
|
|
|
|
/**
|
|
|
|
|
* 整体数据结构:
|
|
|
|
|
* code <lang : value>
|
|
|
|
|
* code <langCode : value>
|
|
|
|
|
* 先根据code查询,判断是否存在,然后通过语言获取对应的值
|
|
|
|
|
*
|
|
|
|
|
* 语言代码 hashMap结构
|
|
|
|
|
* langCode < code : value>
|
|
|
|
|
*
|
|
|
|
|
* 语言代码+模块 hashMap结构
|
|
|
|
|
* langCode + softType < code : value>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
HashMap<String,HashMap<String,String>> webSoftLangMap = new HashMap<>();
|
|
|
|
|
HashMap<String,String> webSoftResMap;
|
|
|
|
|
String softResKey=null;
|
|
|
|
|
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;
|
|
|
|
|
HashMap<String, HashMap<String, String>> webSoftLangMap = new HashMap<>();
|
|
|
|
|
HashMap<String, String> webSoftResMap;
|
|
|
|
|
String softResKey = null;
|
|
|
|
|
Integer resCount = systemResourceService.getSysLocaleResourceCount(null);
|
|
|
|
|
|
|
|
|
|
//语言数量
|
|
|
|
|
List<SysLocaleLanguage> langList = systemResourceService.listSysLocaleLanguage(null);
|
|
|
|
|
|
|
|
|
|
LOGGER.info("【加载平台资源】共有{}个资源,{}种语言。", resCount, langList.size());
|
|
|
|
|
Pager pager = new Pager(resCount, 5000);
|
|
|
|
|
pager.setCurrentPage(0);
|
|
|
|
|
//查询所有资源
|
|
|
|
|
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();
|
|
|
|
|
//将key/代码放入
|
|
|
|
|
resMap.put(res.getResourceKey(), lanMap);
|
|
|
|
|
}
|
|
|
|
|
//根据语言放入
|
|
|
|
|
lanMap.put(res.getLanguageCode(), res.getResourceValue());
|
|
|
|
|
ListPager<SysLocaleResource> resourceList;
|
|
|
|
|
do {
|
|
|
|
|
pager.next();
|
|
|
|
|
resourceList = systemResourceService.listSysLocaleResourceByPager(null, pager);
|
|
|
|
|
resMap = new HashMap();
|
|
|
|
|
webLangMap = new HashMap<>();
|
|
|
|
|
webSoftLangMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
for (SysLocaleResource res : resourceList.getObjectList()) {
|
|
|
|
|
lanMap = resMap.get(res.getResourceKey());
|
|
|
|
|
//判断是否已存在资源信息
|
|
|
|
|
if (lanMap == null) {
|
|
|
|
|
lanMap = new HashMap();
|
|
|
|
|
//将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());
|
|
|
|
|
|
|
|
|
|
// web 模块资源
|
|
|
|
|
softResKey = res.getLanguageCode() + ":" + res.getSoftTypeVal();
|
|
|
|
|
if(!webSoftLangMap.containsKey(softResKey)){
|
|
|
|
|
webSoftLangMap.put(softResKey, new HashMap<>());
|
|
|
|
|
// web 资源
|
|
|
|
|
if (!webLangMap.containsKey(res.getLanguageCode())) {
|
|
|
|
|
webLangMap.put(res.getLanguageCode(), new HashMap<>());
|
|
|
|
|
}
|
|
|
|
|
// 放入资源信息
|
|
|
|
|
webResMap = webLangMap.get(res.getLanguageCode());
|
|
|
|
|
webResMap.put(res.getResourceKey(), res.getResourceValue());
|
|
|
|
|
|
|
|
|
|
// web 模块资源
|
|
|
|
|
softResKey = res.getLanguageCode() + ":" + res.getSoftTypeVal();
|
|
|
|
|
if (!webSoftLangMap.containsKey(softResKey)) {
|
|
|
|
|
webSoftLangMap.put(softResKey, new HashMap<>());
|
|
|
|
|
}
|
|
|
|
|
// 放入模块资源信息
|
|
|
|
|
webSoftResMap = webSoftLangMap.get(softResKey);
|
|
|
|
|
webSoftResMap.put(res.getResourceKey(), res.getResourceValue());
|
|
|
|
|
}
|
|
|
|
|
// 放入模块资源信息
|
|
|
|
|
webSoftResMap = webSoftLangMap.get(softResKey);
|
|
|
|
|
webSoftResMap.put(res.getResourceKey(), res.getResourceValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (String key : resMap.keySet()) {
|
|
|
|
|
//放入缓存
|
|
|
|
|
if(resMap.get(key) != null) {
|
|
|
|
|
redisRes.putHashMap(CommonConstWords.REDIS_PREFIX_CACHE_LANGUAGE + ":" + key, resMap.get(key), 0);
|
|
|
|
|
for (String key : resMap.keySet()) {
|
|
|
|
|
//放入缓存
|
|
|
|
|
if (resMap.get(key) != null) {
|
|
|
|
|
redisRes.putHashMap(CommonConstWords.REDIS_PREFIX_CACHE_LANGUAGE + ":" + key, resMap.get(key), 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(String key : webLangMap.keySet()){
|
|
|
|
|
//放入缓存
|
|
|
|
|
if(webLangMap.get(key) != null){
|
|
|
|
|
redisRes.putHashMap(CommonConstWords.REDIS_PREFIX_CACHE_LANGUAGE_WEB + ":" + key,webLangMap.get(key),0);
|
|
|
|
|
for (String key : webLangMap.keySet()) {
|
|
|
|
|
//放入缓存
|
|
|
|
|
if (webLangMap.get(key) != null) {
|
|
|
|
|
redisRes.putHashMap(CommonConstWords.REDIS_PREFIX_CACHE_LANGUAGE + ":" + key, webLangMap.get(key), 0);
|
|
|
|
|
redisRes.putHashMap(CommonConstWords.REDIS_PREFIX_CACHE_LANGUAGE_WEB + ":" + key, webLangMap.get(key), 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(String key : webSoftLangMap.keySet()){
|
|
|
|
|
//放入缓存
|
|
|
|
|
if(webSoftLangMap.get(key) != null){
|
|
|
|
|
redisRes.putHashMap(CommonConstWords.REDIS_PREFIX_CACHE_LANGUAGE_WEB + ":" + key,webSoftLangMap.get(key),0);
|
|
|
|
|
for (String key : webSoftLangMap.keySet()) {
|
|
|
|
|
//放入缓存
|
|
|
|
|
if (webSoftLangMap.get(key) != null) {
|
|
|
|
|
redisRes.putHashMap(CommonConstWords.REDIS_PREFIX_CACHE_LANGUAGE_WEB + ":" + key, webSoftLangMap.get(key), 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
LOGGER.info("【加载平台资源】加载中 {} / {} ", pager.getEndRow(), pager.getTotalRows());
|
|
|
|
|
} while (pager.hasNext());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOGGER.info("【加载平台资源】加载完成。");
|
|
|
|
|
}
|
|
|
|
|
//加载语言数据
|
|
|
|
|
putAndLoadSysMenu();
|
|
|
|
|
}
|
|
|
|
@ -207,12 +227,11 @@ public class SystemInitService implements ISystemInitService {
|
|
|
|
|
List<SysLocaleResource> insertList = new ArrayList<>();
|
|
|
|
|
Map<String,String> redisCacheMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
if(resource != null && resources.size() > 0){
|
|
|
|
|
if(resources != null && resources.size() > 0){
|
|
|
|
|
resources.forEach(res -> resourceKeyMap.put(StringUtils.join(res.getLanguageCode(),res.getResourceKey()),res));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(menus != null && menus.size() > 0
|
|
|
|
|
&& languages != null && languages.size() > 0){
|
|
|
|
|
if(menus != null && menus.size() > 0 && languages != null && languages.size() > 0){
|
|
|
|
|
for (SysLocaleLanguage language : languages) {
|
|
|
|
|
String redisLanguageKey = CommonConstWords.REDIS_PREFIX_CACHE_LANGUAGE_MENU + ":" + language.getLanguageCode();
|
|
|
|
|
|
|
|
|
|