Commit ba505a4a LN

系统设置中:暂停自动任务改为开启自动任务。

1 个父辈 b3f39fa3
......@@ -232,14 +232,15 @@ public class DataInitManager {
Menu sysSetting = new Menu(new ArrayList<Menu>(), 1, "barcode", "条码设置", 1, "barcodeSetting", "system/barcodeSetting/index", "", 0, "database");
Menu outSet = new Menu(new ArrayList<Menu>(), 1, "outSetting", "出库策略", 1, "outSetting", "system/outSetting/index", "", 0, "outSet");
Menu sysSet = new Menu(new ArrayList<Menu>(), 1, "sysSetting", "系统设置", 1, "sysSetting", "system/sysSetting/index", "", 0, "sysSet");
Menu translationSet = new Menu(new ArrayList<Menu>(), 1, "translation", "资源翻译", 1, "translation", "system/translation/index", "", 0, "sysSet");
Menu translationSet = new Menu(new ArrayList<Menu>(), 1, "translation", "资源翻译", 1, "translation", "system/translation/index", "", 0, "translation");
Menu orderSet = new Menu(new ArrayList<Menu>(), 1, "orderSetting", "工单设置", 1, "orderSetting", "system/orderSetting/index", "", 0, "sysSet");
menuMenu.setHidden(true);
outSet.setHidden(true);
sysSet.setHidden(true);
// menuMenu.setHidden(true);
// sysSetting.setHidden(true);
menus.addAll(createMenus(poutSet, menuStorage, menuStoragePos, menuMenu, sysSetting,outSet,sysSet,translationSet));
menus.addAll(createMenus(poutSet, menuStorage, menuStoragePos, menuMenu, sysSetting,outSet,sysSet,translationSet,orderSet));
//用户管理:用户管理,角色管理
......
......@@ -94,10 +94,16 @@ public class Constants {
* 准备进行更新,不允许需求单出库
*/
public static final String CACHE_StopOut="stopOut";
/**
* 停止定时器任务
* 开启自动任务
*/
public static final String CACHE_StopJob="stopJob";
public static final String CACHE_StartJob="startJob";
//
// /**
// * 停止定时器任务
// */
// public static final String CACHE_StopJob="stopJob";
/**
*出库策略配置: 出库方式类型
......@@ -110,6 +116,11 @@ public class Constants {
public static final String CACHE_msdSetting="msdSetting";
/**
*工单设置
*/
public static final String CACHE_OrderSetting="orderSetting";
/**
* 客户端自定义配置
*/
public static final String CACHE_clientSetting="clientSetting";
......
......@@ -86,8 +86,8 @@ public class DataCache {
if (cacheMap.get(Constants.CACHE_StopOut) == null) {
updateCache(Constants.CACHE_StopOut, false);
}
if (cacheMap.get(Constants.CACHE_StopJob) == null) {
updateCache(Constants.CACHE_StopJob, false);
if (cacheMap.get(Constants.CACHE_StartJob) == null) {
updateCache(Constants.CACHE_StartJob, false);
}
}
......
......@@ -12,9 +12,9 @@ import com.neotel.smfcore.core.language.rest.bean.dto.LanguageResourceDto;
import com.neotel.smfcore.core.language.rest.bean.mapstruct.LanguageMsgMapper;
import com.neotel.smfcore.core.language.rest.bean.query.LanguageMsgCriteria;
import com.neotel.smfcore.core.language.service.bean.Content;
import com.neotel.smfcore.core.language.service.bean.LanguageInfo;
import com.neotel.smfcore.core.language.service.nanager.ILanguageMsgManager;
import com.neotel.smfcore.core.language.service.po.LanguageMsg;
import com.neotel.smfcore.core.language.util.MessageService;
import com.neotel.smfcore.core.language.util.MessageUtils;
import com.neotel.smfcore.security.annotation.AnonymousAccess;
import com.neotel.smfcore.security.bean.FileProperties;
......@@ -48,23 +48,16 @@ public class LanguageMsgController {
@Autowired
LanguageMsgMapper languageMsgMapper;
@Autowired
MessageService messageService;
@Autowired
private final FileProperties properties;
@Autowired
DataCache dataCache;
public List<String> getAllLanList() {
List<LanguageInfo> lanList = dataCache.getLanguageList();
List<String> list = new ArrayList<>();
for (LanguageInfo lan : lanList
) {
list.add(lan.getLanCode());
}
return list;
}
@ApiOperation("导入资源文件")
@PostMapping(value = "/upload")
......@@ -88,15 +81,15 @@ public class LanguageMsgController {
String lanType = getLanTypeByFileName(uploadFile.getOriginalFilename());
if (smfclientType.contains(fileType)) {
//客户端js文件处理
Map<String, String> proMap = MessageUtils.readJsFile(file);
resultMsg = ResourceUpload(uploadFile.getOriginalFilename(), proMap, lanType, "smfclient");
Map<String, String> proMap = messageService.readJsFile(file);
resultMsg =messageService.resourceUpload(uploadFile.getOriginalFilename(), proMap, lanType, "smfclient");
} else if (smfcoreType.contains(fileType)) {
Map<String, String> proMap = MessageUtils.readPropertiesFile(file);
resultMsg = ResourceUpload(uploadFile.getOriginalFilename(), proMap, lanType, "");
Map<String, String> proMap = messageService.readPropertiesFile(file);
resultMsg = messageService.resourceUpload(uploadFile.getOriginalFilename(), proMap, lanType, "");
}
if(csvType.equals(fileType)){
List<LanguageMsg> list=MessageUtils.readCsvFile(file.getAbsolutePath(),dataCache.getLanguageList());
msgListUpload(list);
List<LanguageMsg> list=messageService.readCsvFile(file.getAbsolutePath(),dataCache.getLanguageList());
messageService.msgListUpload(file.getName(), list);
}
return ResultBean.newOkResult(resultMsg);
}
......@@ -106,7 +99,7 @@ public class LanguageMsgController {
@GetMapping(value = "/download")
public void download(HttpServletResponse response, LanguageMsgCriteria criteria) throws Exception {
Query query = QueryHelp.getQuery(criteria);
int languageSize=getAllLanList().size();
int languageSize=messageService.getAllLanList().size();
if (criteria.getTranslationState() != null) {
if (criteria.getTranslationState() == 1) {
// db.getCollection('languageMsg').find({contentList:{$elemMatch:{lanCode:"en-US"}}})
......@@ -133,7 +126,7 @@ public class LanguageMsgController {
List<String> typeList=languageMsgManager.findTypeList();
int languageSize=getAllLanList().size();
int languageSize=messageService.getAllLanList().size();
Query query= QueryHelp.getQuery(criteria);
if (criteria.getTranslationState() != null) {
if (criteria.getTranslationState() == 1) {
......@@ -190,7 +183,7 @@ public class LanguageMsgController {
lanCode=lanCode.replace("_","-");
List<LanguageMsg> msgList=MessageUtils.getLanMsgByType(type);
Map<String,Map<String,String>> resourceMap=new HashMap<>();
List<String> allLantypeList=getAllLanList();
List<String> allLantypeList=messageService.getAllLanList();
for (LanguageMsg msg :
msgList) {
for (Content con :
......@@ -235,7 +228,7 @@ public class LanguageMsgController {
String type = paramsMap.get("type").toString();
List<String> lanList = getAllLanList();
List<String> lanList =messageService.getAllLanList();
for (String key :
paramsMap.keySet()) {
if (key.toString().equals("type")) {
......@@ -262,7 +255,7 @@ public class LanguageMsgController {
lanResourceMap.put(resKey,resValue.toString());
}
}
ResourceUpload("接口上传", lanResourceMap, lanType, type);
messageService.resourceUpload("接口上传", lanResourceMap, lanType, type);
}
return ResultBean.newOkResult("ok");
}
......@@ -294,7 +287,7 @@ public class LanguageMsgController {
private String getLanTypeByFileName(String orgFilename) {
String tname = orgFilename.replace('_', '-');
for (String lanType :
getAllLanList()) {
messageService.getAllLanList()) {
if(tname.contains(lanType)){
return lanType;
}
......@@ -303,126 +296,5 @@ public class LanguageMsgController {
return "";
}
private String ResourceUpload(String orgFileName,Map<String, String> proMap ,String lanCode, String type) {
List<LanguageMsg> newLanguageList = new ArrayList<>();
List<LanguageMsg> updateLanguageList = new ArrayList<>();
if (proMap != null && proMap.size() > 0) {
for (String key :
proMap.keySet()) {
String msgStr = proMap.get(key);
LanguageMsg msg = MessageUtils.getMsg(type,key);
//导入时只能新增不能修改
if (msg == null) {
msg = new LanguageMsg(key, msgStr,type);
msg.setContent(lanCode, msgStr);
newLanguageList.add(msg);
} else {
String oldMsg = msg.getContent(lanCode);
// if (!oldMsg.equals(msgStr)) {
if(ObjectUtil.isEmpty(oldMsg)){
msg.setContent(lanCode, msgStr);
//内容默认更改为中文
if(lanCode.equals(MessageUtils.ZH_CN)){
if(!msg.getMsg().equals(msgStr)){
msg.setMsg(msgStr);
}
}
updateLanguageList.add(msg);
languageMsgManager.save(msg);
MessageUtils.updateMsg(msg);
}
}
}
}
if (newLanguageList.size() > 0) {
languageMsgManager.insertAll(newLanguageList);
for (LanguageMsg msg :
newLanguageList) {
MessageUtils.updateMsg(msg);
}
}
log.info("导入资源[" + orgFileName + "]["+type+"]["+lanCode+"],共["+proMap.size()+"]条数据,共更新[" + updateLanguageList.size() + "]条资源,新增[" + newLanguageList.size() + "]条资源");
return "ok";
}
private void msgListUpload( List<LanguageMsg> msgList) {
List<LanguageMsg> newLanguageList = new ArrayList<>();
List<LanguageMsg> updateLanguageList = new ArrayList<>();
for (LanguageMsg msg :
msgList) {
if(ObjectUtil.isEmpty(msg.getCode())) {
//code不能为空
continue;
}
if(ObjectUtil.isEmpty(msg.getMsg())){
//内容不能为空
continue;
} if(ObjectUtil.isEmpty(msg.getType())){
//内容不能为空
continue;
}
List<Content> contentList = new ArrayList<>();
for (Content con :
msg.getContentList()) {
if (ObjectUtil.isEmpty(con.getLanCode()) || ObjectUtil.isEmpty(con.getMsg())) {
continue;
}
contentList.add(con);
}
//判断是否是新增
LanguageMsg oldMsg=MessageUtils.getMsg(msg.getType(), msg.getCode());
if(oldMsg==null){
newLanguageList.add(msg);
}
else{
boolean isUpdate=false;
//只新增不修改
List<String> allLanList=getAllLanList();
for (String lanType :
allLanList) {
String oldValue= oldMsg.getContent(lanType);
if(ObjectUtil.isEmpty(oldValue)){
oldMsg.setContent(lanType,msg.getContent(lanType));
isUpdate=true;
//内容默认更改为中文
if(lanType.equals(MessageUtils.ZH_CN)){
if(!oldMsg.getMsg().equals(oldValue)){
oldMsg.setMsg(oldValue);
}
}
}
}
if(isUpdate){
updateLanguageList.add(oldMsg);
languageMsgManager.save(oldMsg);
MessageUtils.updateMsg(oldMsg);
}
}
}
if (newLanguageList.size() > 0) {
languageMsgManager.insertAll(newLanguageList);
for (LanguageMsg msg :
newLanguageList) {
MessageUtils.updateMsg(msg);
}
}
log.info("导入csv资源,共["+msgList.size()+"]条数据,共更新[" + updateLanguageList.size() + "]条资源,新增[" + newLanguageList.size() + "]条资源");
}
}
package com.neotel.smfcore.core.language.util;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.csv.CsvReader;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.language.service.bean.Content;
import com.neotel.smfcore.core.language.service.bean.LanguageInfo;
import com.neotel.smfcore.core.language.service.nanager.ILanguageMsgManager;
import com.neotel.smfcore.core.language.service.po.LanguageMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class MessageService {
@Autowired
ILanguageMsgManager languageMsgManager;
@Autowired
DataCache dataCache;
public Map<String,Map<String, LanguageMsg>> loadMsgMap() {
Map<String,Map<String, LanguageMsg>> resourceMap=new HashMap<>();
List<LanguageMsg> msgs = languageMsgManager.findByQuery(new Query());
for (LanguageMsg msg :
msgs) {
if(msg.getCode().startsWith("smfcode.")||msg.getType().equals("smfcode")){
String newCode=msg.getCode().replace("smfcode.","smfcore.");
msg.setCode(newCode);
msg.setType("smfcore");
languageMsgManager.save(msg);
}
Map<String, LanguageMsg> typeMap = resourceMap.get(msg.getType());
if(typeMap==null){
typeMap=new HashMap<>();
}
typeMap.put(msg.getCode(),msg);
resourceMap.put(msg.getType(), typeMap);
}
log.info("loadMsgMap 共加载到" + msgs.size() + "条Msg");
return resourceMap;
}
public void autoImportCsvFile(){
String fielPath = "D:\\resources\\";
File file = new File(fielPath); //需要获取的文件的路径
List<LanguageInfo> languageInfoList=dataCache.getLanguageList();
if (file.exists() && file.isDirectory()) {
String[] fileNameLists = file.list(); //存储文件名的String数组
File[] filePathLists = file.listFiles(); //存储文件路径的String数组
for (int i = 0; i < filePathLists.length; i++) {
//只读取后缀名为csv的
if (filePathLists[i].isFile()) {
String fileName = filePathLists[i].getName();
if (fileName.endsWith(".csv")) {
try {
List<LanguageMsg> msgList=readCsvFile(filePathLists[i].getAbsolutePath(),languageInfoList);
if(msgList.size()>0){
msgListUpload(fileName, msgList);
}
}catch (Exception ex){
log.info("autoImportCsvFile 读取文件"+fileName+"错误:"+ex.toString());
}
}
}
}
}
}
public void autoImportProperties() {
String fielPath = "D:\\resources";
File file = new File(fielPath); //需要获取的文件的路径
if (file.exists() && file.isDirectory()) {
String[] fileNameLists = file.list(); //存储文件名的String数组
File[] filePathLists = file.listFiles(); //存储文件路径的String数组
Map<String, String> defaultLanMap = new HashMap<>();
Map<String, Map<String, String>> lanMsgMap = new HashMap<>();
for (int i = 0; i < filePathLists.length; i++) {
if (filePathLists[i].isFile()) {
String fileName = filePathLists[i].getName();
if (fileName.endsWith(".properties")) {
String lanType = fileName.replace("messages", "").replace(".properties", "");
if (ObjectUtil.isEmpty(lanType)) {
defaultLanMap = readPropertiesFile(filePathLists[i]);
log.info("MessageCache 从文件[" + fileName + "]中导入[" + defaultLanMap.size() + "]条默认资源");
} else {
String lan = lanType.substring(1);
lan = lan.replace('_', '-');
Map<String, String> map = readPropertiesFile(filePathLists[i]);
lanMsgMap.put(lan, map);
log.info("MessageCache 从文件[" + fileName + "]中导入[" + defaultLanMap.size() + "]条[" + lan + "]资源");
}
}
}
}
List<LanguageMsg> languageMsgs = new ArrayList<>();
for (String code :
defaultLanMap.keySet()) {
String defMsg = defaultLanMap.get(code);
LanguageMsg msg = new LanguageMsg(code, defMsg, "");
for (String lan :
lanMsgMap.keySet()) {
if (lanMsgMap.get(lan).containsKey(code)) {
String lanMsg = lanMsgMap.get(lan).get(code);
msg.setContent(lan, lanMsg);
}
}
languageMsgs.add(msg);
}
languageMsgManager.insertAll(languageMsgs);
}
}
public List<String> getAllLanList() {
List<LanguageInfo> lanList = dataCache.getLanguageList();
List<String> list = new ArrayList<>();
for (LanguageInfo lan : lanList
) {
list.add(lan.getLanCode());
}
return list;
}
public String resourceUpload(String orgFileName, Map<String, String> proMap , String lanCode, String type) {
List<LanguageMsg> newLanguageList = new ArrayList<>();
List<LanguageMsg> updateLanguageList = new ArrayList<>();
if (proMap != null && proMap.size() > 0) {
for (String key :
proMap.keySet()) {
String msgStr = proMap.get(key);
LanguageMsg msg = MessageUtils.getMsg(type,key);
//导入时只能新增不能修改
if (msg == null) {
msg = new LanguageMsg(key, msgStr,type);
msg.setContent(lanCode, msgStr);
newLanguageList.add(msg);
} else {
String oldMsg = msg.getContent(lanCode);
// if (!oldMsg.equals(msgStr)) {
if(ObjectUtil.isEmpty(oldMsg)){
msg.setContent(lanCode, msgStr);
//内容默认更改为中文
if(lanCode.equals(MessageUtils.ZH_CN)){
if(!msg.getMsg().equals(msgStr)){
msg.setMsg(msgStr);
}
}
updateLanguageList.add(msg);
languageMsgManager.save(msg);
MessageUtils.updateMsg(msg);
}
}
}
}
if (newLanguageList.size() > 0) {
languageMsgManager.insertAll(newLanguageList);
for (LanguageMsg msg :
newLanguageList) {
MessageUtils.updateMsg(msg);
}
}
log.info("导入资源[" + orgFileName + "]["+type+"]["+lanCode+"],共["+proMap.size()+"]条数据,共更新[" + updateLanguageList.size() + "]条资源,新增[" + newLanguageList.size() + "]条资源");
return "ok";
}
public void msgListUpload(String fileName, List<LanguageMsg> msgList) {
List<LanguageMsg> newLanguageList = new ArrayList<>();
List<LanguageMsg> updateLanguageList = new ArrayList<>();
for (LanguageMsg msg :
msgList) {
if(ObjectUtil.isEmpty(msg.getCode())) {
//code不能为空
continue;
}
if(ObjectUtil.isEmpty(msg.getMsg())){
//内容不能为空
continue;
} if(ObjectUtil.isEmpty(msg.getType())){
//内容不能为空
continue;
}
List<Content> contentList = new ArrayList<>();
for (Content con :
msg.getContentList()) {
if (ObjectUtil.isEmpty(con.getLanCode()) || ObjectUtil.isEmpty(con.getMsg())) {
continue;
}
contentList.add(con);
}
//判断是否是新增
LanguageMsg oldMsg=MessageUtils.getMsg(msg.getType(), msg.getCode());
if(oldMsg==null){
newLanguageList.add(msg);
}
else{
boolean isUpdate=false;
//只新增不修改
List<String> allLanList=getAllLanList();
for (String lanType :
allLanList) {
String oldValue= oldMsg.getContent(lanType);
if(ObjectUtil.isEmpty(oldValue)){
oldMsg.setContent(lanType,msg.getContent(lanType));
isUpdate=true;
//内容默认更改为中文
if(lanType.equals(MessageUtils.ZH_CN)){
if(!oldMsg.getMsg().equals(oldValue)){
oldMsg.setMsg(oldValue);
}
}
}
}
if(isUpdate){
updateLanguageList.add(oldMsg);
languageMsgManager.save(oldMsg);
MessageUtils.updateMsg(oldMsg);
}
}
}
if (newLanguageList.size() > 0) {
languageMsgManager.insertAll(newLanguageList);
for (LanguageMsg msg :
newLanguageList) {
MessageUtils.updateMsg(msg);
}
}
log.info("导入csv["+fileName+"]资源,共["+msgList.size()+"]条数据,共更新[" + updateLanguageList.size() + "]条资源,新增[" + newLanguageList.size() + "]条资源");
}
public Map<String, String> readPropertiesFile(File file) {
Map<String, String> map = new HashMap<>();
try (FileInputStream fis = new FileInputStream(file.getPath());
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr)
) {
String line;
//网友推荐更加简洁的写法
while ((line = br.readLine()) != null) {
// 一次读入一行数据
// System.out.println(line);
String[] array = line.split("=");
if (array.length == 2) {
map.put(array[0].trim(), array[1].trim());
}
}
} catch (IOException e) {
log.error("ReadPropertiesFile 出错:" + e.toString());
e.printStackTrace();
}
return map;
}
public List<LanguageMsg> readCsvFile(String fileURL , List<LanguageInfo> languageInfos) throws Exception{
CsvReader csvRead = CsvReader.newReader(fileURL,"编号","code");
int codeIndex = csvRead.getCsvIndex("编号","code");
int typeIndex = csvRead.getCsvIndex("类型","type");
int msgIndex = csvRead.getCsvIndex("内容","msg");
Map<String,Integer> lanCodeIndex=new HashMap<>() ;
// List<LanguageInfo> languageInfos=dataCache.getLanguageList();
for (LanguageInfo lan:languageInfos
) {
int lanIndex = csvRead.getCsvIndex(lan.getLanCode(),lan.getLanName());
if(lanIndex>=0){
lanCodeIndex.put(lan.getLanCode(),lanIndex);
}
}
int row = 1;
int newRowCount = 0;
int updateRowCount = 0;
String msg="";
List<LanguageMsg> list=new ArrayList<>();
while(csvRead.readRecord()) {
row++;
String[] lineValues = csvRead.getValues();
LanguageMsg languageMsg=new LanguageMsg();
String code = lineValues[codeIndex];
String type = lineValues[typeIndex];
String msgStr = lineValues[msgIndex];
if (code.isEmpty() || type.isEmpty() || msgStr.isEmpty()) {
log.warn("第" + row + "行中有空白内容,此行忽略");
continue;
}
languageMsg.setMsg(msgStr);
languageMsg.setCode(code);
languageMsg.setType(type);
for (String lan :
lanCodeIndex.keySet()) {
int lanIndex=lanCodeIndex.get(lan);
String lanMsg=lineValues[lanIndex];
if(!lanMsg.isEmpty()){
languageMsg.setContent(lan,lanMsg);
}
}
list.add(languageMsg);
}
return list;
}
public Map<String,String> readJsFile(File file){
Map<String,String> map=new HashMap<>();
try (FileInputStream fis = new FileInputStream(file.getPath());
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr)
) {
String line;
//网友推荐更加简洁的写法
int lineIndex=-1;
String currNodeName="";
while ((line = br.readLine()) != null) {
lineIndex++;
// if(lineIndex==0){
// continue;
// }
if(ObjectUtil.isEmpty(line)){
continue;
}
if (line.contains("{")){
if(line.contains("=")){
currNodeName="";
}else{
int dendIndex=line.indexOf(':');
String lineNode=line.substring(0,dendIndex).trim();
if(ObjectUtil.isEmpty(currNodeName)){
currNodeName=lineNode;
}else{
//节点名称+
currNodeName=currNodeName+"."+lineNode;
}
}
}else if(line.contains("}")){
//节点名称-
if(currNodeName.contains(".")){
int endIndex=currNodeName.lastIndexOf(".");
currNodeName=currNodeName.substring(0,endIndex );
}else{
currNodeName="";
}
}
else if(line .contains(":")){
if(line.endsWith(",")){
line=line.substring(0,line.length()-1);
}
String[] array=line.replace("'","").replace("\"","").split(":");
if(array.length==2){
String linekey=array[0].trim();
String lineValue=array[1].trim();
map.put(currNodeName+"."+linekey,lineValue);
}
}
}
} catch (IOException e) {
log.error("readJsFile 出错:"+e.toString());
e.printStackTrace();
}
return map;
}
}
......@@ -2,6 +2,7 @@ package com.neotel.smfcore.core.language.util;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.csv.CsvReader;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.language.service.bean.Content;
import com.neotel.smfcore.core.language.service.bean.LanguageInfo;
import com.neotel.smfcore.core.language.service.nanager.ILanguageMsgManager;
......@@ -65,7 +66,11 @@ public class MessageUtils {
@Autowired
ILanguageMsgManager languageMsgManager;
@Autowired
DataCache dataCache;
@Autowired
MessageService messageService;
public static final String ZH_CN = "zh-CN";
public static final String ZH_TW = "zh-TW";
......@@ -82,6 +87,20 @@ public class MessageUtils {
}
private void initLanguageMsgList() {
msgMap =messageService.loadMsgMap();
if (msgMap.size() > 0) {
return;
}
//自动导入CSV内容
messageService.autoImportCsvFile();
messageService.autoImportProperties();
msgMap = messageService.loadMsgMap();
}
//-----------------以下为从缓存读取资源-------------------------------------
public static Locale getDefaultLocal(){
return new Locale("zh-CH");
......@@ -160,36 +179,8 @@ public class MessageUtils {
if(typeMap!=null){
msgList=new ArrayList<>(typeMap.values());
}
// for (LanguageMsg msg :
// msgMap.values()) {
// if(msg.getType().equals(type)){
// msgList.add(msg);
// }
// }
return msgList;
}
private Map<String,Map<String, LanguageMsg>> loadMsgMap() {
Map<String,Map<String, LanguageMsg>> resourceMap=new HashMap<>();
List<LanguageMsg> msgs = languageMsgManager.findByQuery(new Query());
for (LanguageMsg msg :
msgs) {
if(msg.getCode().startsWith("smfcode.")||msg.getType().equals("smfcode")){
String newCode=msg.getCode().replace("smfcode.","smfcore.");
msg.setCode(newCode);
msg.setType("smfcore");
languageMsgManager.save(msg);
}
Map<String, LanguageMsg> typeMap = resourceMap.get(msg.getType());
if(typeMap==null){
typeMap=new HashMap<>();
}
typeMap.put(msg.getCode(),msg);
resourceMap.put(msg.getType(), typeMap);
}
log.info("MessageCache共加载到" + msgs.size() + "条Msg");
return resourceMap;
}
public static List<LanguageInfo> getDefaultLanList() {
List<LanguageInfo> lanList = new ArrayList<>();
......@@ -205,217 +196,4 @@ public class MessageUtils {
private void initLanguageMsgList() {
msgMap = loadMsgMap();
if (msgMap.size() > 0) {
return;
}
//自动导入CSV内容
autoImportCsvFile();
autoImportProperties();
msgMap = loadMsgMap();
}
private void autoImportCsvFile(){
}
private void autoImportProperties() {
String fielPath = "D:\\resources";
File file = new File(fielPath); //需要获取的文件的路径
if (file.exists() && file.isDirectory()) {
String[] fileNameLists = file.list(); //存储文件名的String数组
File[] filePathLists = file.listFiles(); //存储文件路径的String数组
Map<String, String> defaultLanMap = new HashMap<>();
Map<String, Map<String, String>> lanMsgMap = new HashMap<>();
for (int i = 0; i < filePathLists.length; i++) {
if (filePathLists[i].isFile()) {
String fileName = filePathLists[i].getName();
if (fileName.endsWith(".properties")) {
String lanType = fileName.replace("messages", "").replace(".properties", "");
if (ObjectUtil.isEmpty(lanType)) {
defaultLanMap = readPropertiesFile(filePathLists[i]);
log.info("MessageCache 从文件[" + fileName + "]中导入[" + defaultLanMap.size() + "]条默认资源");
} else {
String lan = lanType.substring(1);
lan = lan.replace('_', '-');
Map<String, String> map = readPropertiesFile(filePathLists[i]);
lanMsgMap.put(lan, map);
log.info("MessageCache 从文件[" + fileName + "]中导入[" + defaultLanMap.size() + "]条[" + lan + "]资源");
}
}
}
}
List<LanguageMsg> languageMsgs = new ArrayList<>();
for (String code :
defaultLanMap.keySet()) {
String defMsg = defaultLanMap.get(code);
LanguageMsg msg = new LanguageMsg(code, defMsg, "");
for (String lan :
lanMsgMap.keySet()) {
if (lanMsgMap.get(lan).containsKey(code)) {
String lanMsg = lanMsgMap.get(lan).get(code);
msg.setContent(lan, lanMsg);
}
}
languageMsgs.add(msg);
}
languageMsgManager.insertAll(languageMsgs);
}
}
public static Map<String, String> readPropertiesFile(File file) {
Map<String, String> map = new HashMap<>();
try (FileInputStream fis = new FileInputStream(file.getPath());
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr)
) {
String line;
//网友推荐更加简洁的写法
while ((line = br.readLine()) != null) {
// 一次读入一行数据
// System.out.println(line);
String[] array = line.split("=");
if (array.length == 2) {
map.put(array[0].trim(), array[1].trim());
}
}
} catch (IOException e) {
log.error("ReadPropertiesFile 出错:" + e.toString());
e.printStackTrace();
}
return map;
}
public static List<LanguageMsg> readCsvFile(String fileURL , List<LanguageInfo> languageInfos) throws Exception{
CsvReader csvRead = CsvReader.newReader(fileURL,"编号","code");
int codeIndex = csvRead.getCsvIndex("编号","code");
int typeIndex = csvRead.getCsvIndex("类型","type");
int msgIndex = csvRead.getCsvIndex("内容","msg");
Map<String,Integer> lanCodeIndex=new HashMap<>() ;
// List<LanguageInfo> languageInfos=dataCache.getLanguageList();
for (LanguageInfo lan:languageInfos
) {
int lanIndex = csvRead.getCsvIndex(lan.getLanCode(),lan.getLanName());
if(lanIndex>=0){
lanCodeIndex.put(lan.getLanCode(),lanIndex);
}
}
int row = 1;
int newRowCount = 0;
int updateRowCount = 0;
String msg="";
List<LanguageMsg> list=new ArrayList<>();
while(csvRead.readRecord()) {
row++;
String[] lineValues = csvRead.getValues();
LanguageMsg languageMsg=new LanguageMsg();
String code = lineValues[codeIndex];
String type = lineValues[typeIndex];
String msgStr = lineValues[msgIndex];
if (code.isEmpty() || type.isEmpty() || msgStr.isEmpty()) {
log.warn("第" + row + "行中有空白内容,此行忽略");
continue;
}
languageMsg.setMsg(msgStr);
languageMsg.setCode(code);
languageMsg.setType(type);
for (String lan :
lanCodeIndex.keySet()) {
int lanIndex=lanCodeIndex.get(lan);
String lanMsg=lineValues[lanIndex];
if(!lanMsg.isEmpty()){
languageMsg.setContent(lan,lanMsg);
}
}
list.add(languageMsg);
}
return list;
}
public static Map<String,String> readJsFile(File file){
Map<String,String> map=new HashMap<>();
try (FileInputStream fis = new FileInputStream(file.getPath());
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr)
) {
String line;
//网友推荐更加简洁的写法
int lineIndex=-1;
String currNodeName="";
while ((line = br.readLine()) != null) {
lineIndex++;
// if(lineIndex==0){
// continue;
// }
if(ObjectUtil.isEmpty(line)){
continue;
}
if (line.contains("{")){
if(line.contains("=")){
currNodeName="";
}else{
int dendIndex=line.indexOf(':');
String lineNode=line.substring(0,dendIndex).trim();
if(ObjectUtil.isEmpty(currNodeName)){
currNodeName=lineNode;
}else{
//节点名称+
currNodeName=currNodeName+"."+lineNode;
}
}
}else if(line.contains("}")){
//节点名称-
if(currNodeName.contains(".")){
int endIndex=currNodeName.lastIndexOf(".");
currNodeName=currNodeName.substring(0,endIndex );
}else{
currNodeName="";
}
}
else if(line .contains(":")){
if(line.endsWith(",")){
line=line.substring(0,line.length()-1);
}
String[] array=line.replace("'","").replace("\"","").split(":");
if(array.length==2){
String linekey=array[0].trim();
String lineValue=array[1].trim();
map.put(currNodeName+"."+linekey,lineValue);
}
}
}
} catch (IOException e) {
log.error("readJsFile 出错:"+e.toString());
e.printStackTrace();
}
return map;
}
}
......@@ -97,9 +97,9 @@ public class LiteOrderCache implements ITaskListener {
if(!isProcessTimer){
isProcessTimer = true;
try {
boolean stopJob = dataCache.getCache(Constants.CACHE_StopJob);
boolean startJob = dataCache.getCache(Constants.CACHE_StartJob);
if(!stopJob){
if(startJob){
//定时执行工单任务
executeOrderTask();
}
......
......@@ -180,7 +180,7 @@ public class StoragePosManagerImpl implements IStoragePosManager {
@Override
public void delete(StoragePos object) throws ValidateException {
storagePosDao.removeOneById(object.getId());
}
@Override
......
......@@ -13,6 +13,6 @@ public class SysSettingsDto implements Serializable {
@ApiModelProperty("准备进行更新,不允许需求单出库")
private boolean stopOut = false;
@ApiModelProperty("停止定时器任务")
private boolean stopJob = false;
@ApiModelProperty("开启自动任务")
private boolean startJob = false;
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!