Commit 13011d6e LN

资源上传下载功能。语言设置功能

1 个父辈 917b02b8
......@@ -109,7 +109,15 @@ public class Constants {
*/
public static final String CACHE_msdSetting="msdSetting";
/**
* 客户端自定义配置
*/
public static final String CACHE_clientSetting="clientSetting";
/**
* 语言列表配置
*/
public static final String CACHE_languageType="CACHE_languageType";
}
package com.neotel.smfcore.core.language.rest;
import com.alibaba.fastjson.JSONObject;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.FileUtil;
import com.neotel.smfcore.common.utils.QueryHelp;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.language.rest.bean.dto.LanguageMsgDto;
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.nanager.ILanguageMsgManager;
import com.neotel.smfcore.core.language.service.po.LanguageMsg;
import com.neotel.smfcore.core.language.util.MessageUtils;
import com.neotel.smfcore.security.annotation.AnonymousAccess;
import com.neotel.smfcore.security.bean.FileProperties;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -25,7 +29,6 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -47,20 +50,72 @@ public class LanguageMsgController {
LanguageMsgMapper languageMsgMapper;
@Autowired
private final FileProperties properties;
@ApiOperation("导出数据")
@Autowired
DataCache dataCache;
public List<String> getAllLanList() {
List<String> lanList = dataCache.getCache(Constants.CACHE_languageType);
if (lanList == null || lanList.size() <= 0) {
lanList = new ArrayList<>();
lanList.add(MessageUtils.ZH_CN);
lanList.add(MessageUtils.ZH_TW);
lanList.add(MessageUtils.EN_US);
lanList.add(MessageUtils.JA_JP);
dataCache.updateCache(Constants.CACHE_languageType, lanList);
}
return lanList;
}
@ApiOperation("导入资源文件")
@PostMapping(value = "/upload")
public ResultBean upload(@RequestParam MultipartFile uploadFile) throws Exception {
// 验证文件上传的格式
String smfcodeType = "properties";
String smfclientType = "js";
String fileType = FileUtil.getExtensionName(uploadFile.getOriginalFilename());
if (fileType == null) {
throw new ValidateException("smfcode.feleFormatError", "文件格式错误!, 仅支持{0}格式", new String[]{smfclientType + "/" + smfcodeType});
}
if ((!smfclientType.contains(fileType)) && !smfcodeType.contains(fileType)) {
throw new ValidateException("smfcode.feleFormatError", "文件格式错误!, 仅支持{0}格式", new String[]{smfclientType + "/" + smfcodeType});
}
File folder = new File(properties.getPath(), "resource");
File file = FileUtil.upload(uploadFile, folder.getAbsolutePath());
String resultMsg = "";
//只能新增不能修改
String lanType = getLanTypeByFileName(uploadFile.getOriginalFilename());
if (smfclientType.contains(fileType)) {
//客户端js文件处理
Map<String, String> proMap = readJsFile(file);
resultMsg = ResourceUpload(uploadFile.getOriginalFilename(), proMap, lanType, "smfclient");
} else if (smfcodeType.contains(fileType)) {
Map<String, String> proMap = MessageUtils.ReadPropertiesFile(file);
resultMsg = ResourceUpload(uploadFile.getOriginalFilename(), proMap, lanType, "");
}
return ResultBean.newOkResult(resultMsg);
}
@ApiOperation("导出资源文件")
@GetMapping(value = "/download")
public void download(HttpServletResponse response, LanguageMsgCriteria criteria) throws Exception {
Query query = QueryHelp.getQuery(criteria);
int languageSize=getAllLanList().size();
if (criteria.getTranslationState() != null) {
if (criteria.getTranslationState() == 1) {
// db.getCollection('languageMsg').find({contentList:{$elemMatch:{lanCode:"en-US"}}})
// query.addCriteria(Criteria.where("contentList").elemMatch(Criteria.where("lanCode").is(MessageUtils.EN_US)));
// db.getCollection('languageMsg').find({contentList:{"$size":4}})
query.addCriteria(Criteria.where("contentList").size(4));
query.addCriteria(Criteria.where("contentList").size(languageSize));
} else if (criteria.getTranslationState() == 2) {
// db.getCollection("Array").find({ $where: "this.vendor.length <= 0" })//数组length<= 0
query.addCriteria(Criteria.where("this.contentList.length").lt(4));
String proName="contentList."+(languageSize-1);
query.addCriteria(Criteria.where(proName).exists(false));
}
}
List<LanguageMsg> list = languageMsgManager.findByQuery(query);
......@@ -72,14 +127,18 @@ public class LanguageMsgController {
@GetMapping
@PreAuthorize("@el.check('translation')")
public PageData<LanguageMsgDto> query(LanguageMsgCriteria criteria, Pageable pageable){
List<String> typeList=languageMsgManager.findTypeList();
int languageSize=getAllLanList().size();
Query query= QueryHelp.getQuery(criteria);
if (criteria.getTranslationState() != null) {
if (criteria.getTranslationState() == 1) {
query.addCriteria(Criteria.where("contentList").size(4));
query.addCriteria(Criteria.where("contentList").size(languageSize));
} else if (criteria.getTranslationState() == 2) {
query.addCriteria(Criteria.where("this.contentList.length").lte(3));
// db.getCollection('languageMsg').find({ "contentList.3" : { "$exists" : 0 } })
String proName="contentList."+(languageSize-1);
query.addCriteria(Criteria.where(proName).exists(false));
}
}
PageData<LanguageMsg> barcodes=languageMsgManager.findByPage(query,pageable);
......@@ -89,7 +148,7 @@ public class LanguageMsgController {
@ApiOperation("新增资源")
@PostMapping
@PreAuthorize("@el.check('translation')")
public ResponseEntity<Object> create(@Validated @RequestBody LanguageMsgDto resources) {
public ResponseEntity<Object> create( @RequestBody LanguageMsgDto resources) {
LanguageMsg msg=languageMsgMapper.toEntity(resources);
languageMsgManager.saveMsg(msg);
return new ResponseEntity<>(HttpStatus.CREATED);
......@@ -98,7 +157,7 @@ public class LanguageMsgController {
@ApiOperation("修改资源")
@PutMapping
@PreAuthorize("@el.check('translation')")
public ResponseEntity<Object> update(@Validated @RequestBody LanguageMsgDto resources) {
public ResponseEntity<Object> update( @RequestBody LanguageMsgDto resources) {
LanguageMsg msg=languageMsgMapper.toEntity(resources);
if (msg.getId() == null) {
throw new ValidateException("smfcode.valueCanotNull","{0}不能为空",new String[]{"ID"});
......@@ -120,6 +179,106 @@ public class LanguageMsgController {
return new ResponseEntity<>(HttpStatus.OK);
}
@ApiOperation("客户端获取资源列表")
@GetMapping(value = "/resource")
@AnonymousAccess
public List<LanguageResourceDto> resourceDownload(String type,String lanCode ) {
lanCode=lanCode.replace("_","-");
List<LanguageMsg> msgList=MessageUtils.getLanMsgByType(type);
Map<String,Map<String,String>> resourceMap=new HashMap<>();
List<String> allLantypeList=getAllLanList();
for (LanguageMsg msg :
msgList) {
for (Content con :
msg.getContentList()) {
if (ObjectUtil.isEmpty(con.getLanCode()) || ObjectUtil.isEmpty(con.getMsg())) {
continue;
}
if (ObjectUtil.isNotEmpty(lanCode) && (!lanCode.equals(con.getLanCode()))) {
continue;
}
if(!allLantypeList.contains(con.getLanCode())){
continue;
}
Map<String, String> valueMap = resourceMap.get(con.getLanCode());
if (valueMap == null) {
valueMap = new HashMap<>();
}
valueMap.put(msg.getCode(), con.getMsg());
resourceMap.put(con.getLanCode(), valueMap);
}
}
List<LanguageResourceDto> list=new ArrayList<>();
for (String key :
resourceMap.keySet()) {
Map<String, String> valueMap = resourceMap.get(key);
if(valueMap!=null&&valueMap.size()>0){
LanguageResourceDto dto=new LanguageResourceDto(key,valueMap);
list.add(dto);
}
}
return list;
}
@ApiOperation("客户端提交资源列表:只增加不修改")
@PostMapping(value = "/resource")
@AnonymousAccess
public ResultBean resourceUpload(@RequestBody Map<String,Object> paramsMap ) {
String type = paramsMap.get("type").toString();
List<String> lanList = getAllLanList();
for (String key :
paramsMap.keySet()) {
if (key.toString().equals("type")) {
continue;
}
Object value = paramsMap.get(key);
// log.info("收到客户端上传资源类型[" + type + "],语言[" + key + "],值[" + value.toString() + "]");
String lanType = key.replace("_", "-");
if (!lanList.contains(lanType)) {
log.info("收到客户端上传资源,未找到指定语言:类型[" + type + "],语言[" + key + "] ");
continue;
}
log.info("收到客户端上传资源类型[" + type + "],语言[" + key + "]");
Map<String, String> lanResourceMap = new HashMap<>();
Map<String, Object> reMap = (Map<String, Object>) value;
for (String resKey :
reMap.keySet()) {
Object resValue = reMap.get(resKey);
if(resValue instanceof Map){
processResourceMap(resKey, resValue, lanResourceMap);
}else{
lanResourceMap.put(resKey,resValue.toString());
}
}
ResourceUpload("接口上传", lanResourceMap, lanType, type);
}
return ResultBean.newOkResult("ok");
}
private void processResourceMap(String codeKey,Object value,Map<String,String> lanResourceMap){
if(value instanceof Map){
Map<String,Object> valueMap=(Map<String,Object>)value;
for (String vkey :
valueMap.keySet()) {
Object vValue=valueMap.get(vkey);
String code=codeKey+"."+vkey;
processResourceMap(code,vValue,lanResourceMap);
}
}else{
lanResourceMap.put(codeKey,value.toString());
}
}
@ApiOperation("获取资源类型集合")
@GetMapping(value = "/typeList")
@PreAuthorize("@el.check('translation')")
......@@ -128,45 +287,13 @@ public class LanguageMsgController {
List<String> typeList=languageMsgManager.findTypeList();
return typeList;
}
@ApiOperation("上传资源列表")
@PostMapping(value = "/upload")
public ResultBean upload(@RequestParam MultipartFile uploadFile) throws Exception {
// 验证文件上传的格式
String smfcodeType = "properties";
String smfclientType = "js";
String fileType = FileUtil.getExtensionName(uploadFile.getOriginalFilename());
if (fileType == null) {
throw new ValidateException("smfcode.feleFormatError", "文件格式错误!, 仅支持{0}格式", new String[]{smfclientType + "/" + smfcodeType});
}
if ((!smfclientType.contains(fileType)) && !smfcodeType.contains(fileType)) {
throw new ValidateException("smfcode.feleFormatError", "文件格式错误!, 仅支持{0}格式", new String[]{smfclientType + "/" + smfcodeType});
}
File folder = new File(properties.getPath(), "resource");
File file = FileUtil.upload(uploadFile, folder.getAbsolutePath());
String resultMsg = "";
String lanType = getLanTypeByFileName(uploadFile.getOriginalFilename());
if (smfclientType.contains(fileType)) {
//客户端js文件处理
Map<String, String> proMap = readJsFile(file);
resultMsg = ResourceUpload(uploadFile.getOriginalFilename(), proMap, lanType, "smfclient");
} else if (smfcodeType.contains(fileType)) {
Map<String, String> proMap = MessageUtils.ReadPropertiesFile(file);
resultMsg = ResourceUpload(uploadFile.getOriginalFilename(), proMap, lanType, "");
}
return ResultBean.newOkResult(resultMsg);
}
private String getLanTypeByFileName(String orgFilename) {
String tname = orgFilename.replace('_', '-');
if (tname.contains(MessageUtils.EN_US)) {
return MessageUtils.EN_US;
} else if (tname.contains(MessageUtils.JA_JP)) {
return MessageUtils.JA_JP;
} else if (tname.contains(MessageUtils.ZH_CH)) {
return MessageUtils.ZH_CH;
} else if (tname.contains(MessageUtils.ZH_TW)) {
return MessageUtils.ZH_TW;
for (String lanType :
getAllLanList()) {
if(tname.contains(lanType)){
return lanType;
}
}
return "";
......@@ -183,13 +310,15 @@ public class LanguageMsgController {
String msgStr = proMap.get(key);
LanguageMsg msg = MessageUtils.getMsg(key);
//导入时只能新增不能修改
if (msg == null) {
msg = new LanguageMsg(key, msgStr,"smfclient");
msg.setContent(lanCode, msgStr);
newLanguageList.add(msg);
} else {
String oldMsg = msg.getContent(lanCode);
if (!oldMsg.equals(msgStr)) {
// if (!oldMsg.equals(msgStr)) {
if(ObjectUtil.isEmpty(oldMsg)){
msg.setContent(lanCode, msgStr);
updateLanguageList.add(msg);
languageMsgManager.save(msg);
......@@ -206,29 +335,13 @@ public class LanguageMsgController {
MessageUtils.updateMsg(msg);
}
}
log.info("导入资源文件[" + orgFileName + "]共更新[" + updateLanguageList.size() + "]条资源,新增[" + newLanguageList.size() + "]条资源");
log.info("导入资源[" + orgFileName + "]["+type+"]["+lanCode+"]共更新[" + updateLanguageList.size() + "]条资源,新增[" + newLanguageList.size() + "]条资源");
return "ok";
}
private Map<String,String> readJsFile(File file){
Map<String,String> map=new HashMap<>();
// Long fileLengthLong = file.length();
// byte[] fileContent = new byte[fileLengthLong.intValue()];
// try {
// FileInputStream inputStream = new FileInputStream(file);
// inputStream.read(fileContent);
// inputStream.close();
// String string = new String(fileContent);
// JSONObject jsonObject= JSONObject.parseObject(string);
// for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
// System.out.println("key值="+entry.getKey());
// System.out.println("对应key值的value="+entry.getValue());
// }
// } catch (Exception e) {
// log.error("readJsFile 出错:"+e.toString());
// e.printStackTrace();
// }
private 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");
......@@ -236,19 +349,55 @@ public class LanguageMsgController {
) {
String line;
//网友推荐更加简洁的写法
int lineIndex=0;
int lineIndex=-1;
String currNodeName="";
while ((line = br.readLine()) != null) {
if(lineIndex==0){
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);
}
}
}
// JSONObject jsonObject= JSONObject.parseObject(br.toString());
// for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
// System.out.println("key值="+entry.getKey());
// System.out.println("对应key值的value="+entry.getValue());
// }
} catch (IOException e) {
log.error("readJsFile 出错:"+e.toString());
......@@ -256,36 +405,58 @@ public class LanguageMsgController {
}
return map;
}
// //服务端properties文件处理
// private String propertiesResourceUpload(String orgFileName,File file) {
// private void msgListUpload(String type, List<LanguageMsg> msgList) {
//
// String lanType = getLanTypeByFileName(orgFileName);
// List<LanguageMsg> newLanguageList = new ArrayList<>();
// List<LanguageMsg> updateLanguageList = new ArrayList<>();
// for (LanguageMsg msg :
// msgList) {
// msg.setType(type);
// if(ObjectUtil.isEmpty(msg.getCode())) {
// //code不能为空
// continue;
// }
// if(ObjectUtil.isEmpty(msg.getMsg())){
// //内容不能为空
// continue;
// }
//
// Map<String, String> proMap = MessageUtils.ReadPropertiesFile(file);
// if (proMap != null && proMap.size() > 0) {
// for (String key :
// proMap.keySet()) {
// String msgStr = proMap.get(key);
// List<Content> contentList = new ArrayList<>();
// for (Content con :
// msg.getContentList()) {
// if (ObjectUtil.isEmpty(con.getLanCode()) || ObjectUtil.isEmpty(con.getMsg())) {
// continue;
// }
// contentList.add(con);
// }
//
// LanguageMsg msg = MessageUtils.getMsg(key);
// if (msg == null) {
// msg = new LanguageMsg(key, msgStr,"");
// msg.setContent(lanType, msgStr);
// newLanguageList.add(msg);
// } else {
// String oldMsg = msg.getContent(lanType);
// if (!oldMsg.equals(msgStr)) {
// msg.setContent(lanType, msgStr);
// updateLanguageList.add(msg);
// languageMsgManager.save(msg);
// MessageUtils.updateMsg(msg);
//
// //判断是否是新增
// LanguageMsg oldMsg=MessageUtils.getMsg(msg.getCode());
// if(oldMsg==null){
// newLanguageList.add(msg);
// }
// else{
// //只新增不修改
// List<String> allLanList=getAllLanList();
// for (String lanType :
// allLanList) {
// String oldValue= oldMsg.getContent(lanType);
// if(ObjectUtil.isEmpty(oldValue)){
// oldMsg.setContent(lanType,msg.getContent(lanType));
// }
// }
// updateLanguageList.add(oldMsg);
// languageMsgManager.save(oldMsg);
// MessageUtils.updateMsg(oldMsg);
// }
//
// }
//
//
//
// if (newLanguageList.size() > 0) {
// languageMsgManager.insertAll(newLanguageList);
// for (LanguageMsg msg :
......@@ -293,7 +464,9 @@ public class LanguageMsgController {
// MessageUtils.updateMsg(msg);
// }
// }
// log.info("导入资源文件[" + orgFileName + "]共更新[" + updateLanguageList.size() + "]条资源,新增[" + newLanguageList.size() + "]条资源");
// return "ok";
// log.info("导入[" + type + "]类型的资源列表,共更新[" + updateLanguageList.size() + "]条资源,新增[" + newLanguageList.size() + "]条资源");
//
// }
}
package com.neotel.smfcore.core.language.rest;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.SecurityUtils;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.language.util.MessageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "设置:语言设置")
@RequestMapping("api/language")
public class LanguageSetController {
@Autowired
DataCache dataCache;
public List<String> getAllLanList() {
List<String> lanList = dataCache.getCache(Constants.CACHE_languageType);
if (lanList == null || lanList.size() <= 0) {
lanList=new ArrayList<>();
lanList.add(MessageUtils.ZH_CN);
lanList.add(MessageUtils.ZH_TW);
lanList.add(MessageUtils.EN_US);
lanList.add(MessageUtils.JA_JP);
dataCache.updateCache(Constants.CACHE_languageType, lanList);
}
return lanList;
}
@ApiOperation("获取语言列表")
@GetMapping
@PreAuthorize("@el.check('translation')")
public List<String> getList(){
return getAllLanList();
}
@ApiOperation("新增语言")
@PostMapping
@PreAuthorize("@el.check('translation')")
public ResponseEntity<Object> create( @RequestBody String languageType) {
//判断是否是admin
String userName= SecurityUtils.getCurrentUsername();
if(!userName.equals(Constants.SUPER_USERNAME)){
throw new ValidateException("smfcode.noLanguageSetAccess","没有编辑语言的权限");
}
if(languageType==null ){
throw new ValidateException("smfcode.languageCanotNull","语言类型不能为空" );
}
List<String> languageTypeList =getAllLanList();
if(!languageTypeList.contains(languageType)){
log.info("用户["+SecurityUtils.getCurrentUsername()+"] 新增语言:"+languageType);
languageTypeList.add(languageType);
dataCache.updateCache(Constants.CACHE_languageType, languageTypeList);
}
return new ResponseEntity<>(HttpStatus.CREATED);
}
@ApiOperation("删除指定语言")
@DeleteMapping
@PreAuthorize("@el.check('translation')")
public ResponseEntity<Object> delete(@RequestBody Set<String> languageTypes) {
//判断是否是admin
String userName = SecurityUtils.getCurrentUsername();
if (!userName.equals(Constants.SUPER_USERNAME)) {
throw new ValidateException("smfcode.noLanguageSetAccess", "没有编辑语言的权限");
}
List<String> languageTypeList = getAllLanList();
for (String type : languageTypes) {
if (type == null) {
throw new ValidateException("smfcode.languageCanotNull", "语言类型不能为空");
}
languageTypeList.remove(type);
log.info("用户["+SecurityUtils.getCurrentUsername()+"] 删除语言:"+type);
}
if (languageTypeList == null || languageTypeList.size() <= 0) {
throw new ValidateException("smfcode.languageCanotRemoveAll", "不能删除所有语言");
}
dataCache.updateCache(Constants.CACHE_languageType, languageTypeList);
return new ResponseEntity<>(HttpStatus.OK);
}
// @ApiOperation("修改语言列表")
// @PostMapping
// @PreAuthorize("@el.check('translation')")
// public ResultBean create(@RequestBody List<String> languageTypeList) {
// if(languageTypeList==null||languageTypeList.size()<=0){
// throw new ValidateException("smfcode.languageCanotNull","语言类型不能为空" );
// }
//
// //判断是否是admin
// String userName= SecurityUtils.getCurrentUsername();
// if(!userName.equals(Constants.SUPER_USERNAME)){
// throw new ValidateException("smfcode.noLanguageSetAccess","没有修改语言的权限");
// }
// dataCache.updateCache(Constants.CACHE_languageType, languageTypeList);
//
// return ResultBean.newOkResult("ok");
// }
}
package com.neotel.smfcore.core.language.rest.bean.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.HashMap;
import java.util.Map;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LanguageResourceDto {
@ApiModelProperty("语言类型")
private String lanCode;
@ApiModelProperty("资源集合,key=code")
private Map<String,String> resourceMap=new HashMap<>();
}
......@@ -3,9 +3,11 @@ package com.neotel.smfcore.core.language.service.nanager.impl;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.FileUtil;
import com.neotel.smfcore.core.barcode.bean.PlateSizeBean;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.language.service.bean.Content;
import com.neotel.smfcore.core.language.service.dao.ILanguageMsgDao;
import com.neotel.smfcore.core.language.service.nanager.ILanguageMsgManager;
......@@ -59,7 +61,21 @@ public class LanguageMsgManagerImpl implements ILanguageMsgManager {
public List<LanguageMsg> findByQuery(Query query) {
return languageMsgDao.findByQuery(query);
}
@Autowired
DataCache dataCache;
public List<String> getAllLanList(){
List<String> lanList=dataCache.getCache(Constants.CACHE_languageType);
if(lanList==null||lanList.size()<=0){
lanList.add(MessageUtils. ZH_CN);
lanList.add(MessageUtils.ZH_TW);
lanList.add(MessageUtils.EN_US);
lanList.add(MessageUtils.JA_JP);
dataCache.updateCache(Constants.CACHE_languageType,lanList);
}
return lanList;
}
@Override
public void download(List<LanguageMsg> msgList, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
......@@ -68,10 +84,15 @@ public class LanguageMsgManagerImpl implements ILanguageMsgManager {
map.put("编号", msg.getCode());
map.put("类型", msg.getType());
map.put("默认值", msg.getMsg());
map.put("简体中文", msg.getContent(MessageUtils.ZH_CH));
map.put("繁体中文", msg.getContent(MessageUtils.ZH_TW));
map.put("英文", msg.getContent(MessageUtils.EN_US));
map.put("日文", msg.getContent(MessageUtils.JA_JP));
List<String> lanList=getAllLanList();
for (String lanType :
lanList) {
map.put(lanType,msg.getContent(lanType));
}
// map.put("简体中文", msg.getContent(MessageUtils.ZH_CN));
// map.put("繁体中文", msg.getContent(MessageUtils.ZH_TW));
// map.put("英文", msg.getContent(MessageUtils.EN_US));
// map.put("日文", msg.getContent(MessageUtils.JA_JP));
list.add(map);
}
FileUtil.downloadExcel(list, response);
......
......@@ -3,19 +3,15 @@ package com.neotel.smfcore.core.language.util;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.core.language.service.bean.Content;
import com.neotel.smfcore.core.language.service.nanager.ILanguageMsgManager;
import com.neotel.smfcore.core.language.service.nanager.impl.LanguageMsgManagerImpl;
import com.neotel.smfcore.core.language.service.po.LanguageMsg;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.jni.Directory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import javax.annotation.PostConstruct;
import java.io.*;
import java.text.MessageFormat;
import java.util.*;
/**
......@@ -67,16 +63,28 @@ public class MessageUtils {
@Autowired
ILanguageMsgManager languageMsgManager;
public static final String ZH_CH = "zh-CH";
public static final String ZH_CN = "zh-CN";
public static final String ZH_TW = "zh-TW";
public static final String EN_US = "en-US";
public static final String JA_JP = "ja-JP";
@PostConstruct
public void initialize() {
initLanguageMsgList();
}
// public static List<String> getAllLanList(){
//
//
// List<String> lanList=new ArrayList<>();
// lanList.add(ZH_CN);
// lanList.add(ZH_TW);
// lanList.add(EN_US);
// lanList.add(JA_JP);
// return lanList;
// }
// public static Locale getDefaultLocal(){
// return new Locale("zh-CH");
......@@ -134,6 +142,16 @@ public class MessageUtils {
return msgMap.get(code);
}
public static List<LanguageMsg> getLanMsgByType(String type) {
List<LanguageMsg> msgList=new ArrayList<>();
for (LanguageMsg msg :
msgMap.values()) {
if(msg.getType().equals(type)){
msgList.add(msg);
}
}
return msgList;
}
private Map<String, LanguageMsg> loadMsgMap() {
Map<String, LanguageMsg> msgMap = new HashMap<>();
List<LanguageMsg> msgs = languageMsgManager.findByQuery(new Query());
......
......@@ -139,5 +139,7 @@ smfcore.msd=MSD\u7BA1\u7406
smfcore.msdManage=MSD\u5E93\u5B58
smfcore.msdData=MSD\u8FFD\u6EAF\u6027
smfcore.msdSetting=MSD\u8BBE\u7F6E
smfcore.translation=\u8D44\u6E90\u7FFB\u8BD1
smfcode.languageCanotNull=\u8BED\u8A00\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A
smfcode.noLanguageSetAccess=\u6CA1\u6709\u7F16\u8F91\u8BED\u8A00\u7684\u6743\u9650
smfcode.languageCanotRemoveAll=\u4E0D\u80FD\u5220\u9664\u6240\u6709\u8BED\u8A00
\ No newline at end of file
......@@ -139,3 +139,7 @@ smfcore.msd=MSD Management
smfcore.msdManage=MSD Inventory
smfcore.msdData=MSD Traceability
smfcore.msdSetting=MSD Setting
smfcore.translation=Resource Translation
smfcode.languageCanotNull=Language type cannot be empty
smfcode.noLanguageSetAccess=No permission to edit the language
smfcode.languageCanotRemoveAll=Cannot delete all languages
......@@ -138,4 +138,8 @@ smfcode.label.noReel=\u6750\u6599\u304C\u898B\u3064\u304B\u3089\u306A\u3044
smfcore.msd=MSD\u7BA1\u7406
smfcore.msdManage=MSD\u5E93\u5B58
smfcore.msdData=MSD\u8FFD\u6EAF\u6027
smfcore.msdSetting=MSD\u8BBE\u7F6E
\ No newline at end of file
smfcore.msdSetting=MSD\u8BBE\u7F6E
smfcore.translation=\u30EA\u30BD\u30FC\u30B9\u306E\u7FFB\u8A33
smfcode.languageCanotNull=\u8A00\u8A9E\u30BF\u30A4\u30D7\u306F\u7A7A\u3067\u306F\u3042\u308A\u307E\u305B\u3093
smfcode.noLanguageSetAccess=\u8A00\u8A9E\u3092\u7DE8\u96C6\u3059\u308B\u6A29\u9650\u304C\u306A\u3044
smfcode.languageCanotRemoveAll=\u3059\u3079\u3066\u306E\u8A00\u8A9E\u3092\u524A\u9664\u3067\u304D\u306A\u3044
\ No newline at end of file
......@@ -138,4 +138,8 @@ smfcode.label.noReel=\u672A\u627E\u5230\u53EF\u51FA\u5E93\u7684\u7269\u6599
smfcore.msd=MSD\u7BA1\u7406
smfcore.msdManage=MSD\u5E93\u5B58
smfcore.msdData=MSD\u8FFD\u6EAF\u6027
smfcore.msdSetting=MSD\u8BBE\u7F6E
\ No newline at end of file
smfcore.msdSetting=MSD\u8BBE\u7F6E
smfcore.translation=\u8D44\u6E90\u7FFB\u8BD1
smfcode.languageCanotNull=\u8BED\u8A00\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A
smfcode.noLanguageSetAccess=\u6CA1\u6709\u7F16\u8F91\u8BED\u8A00\u7684\u6743\u9650
smfcode.languageCanotRemoveAll=\u4E0D\u80FD\u5220\u9664\u6240\u6709\u8BED\u8A00
\ No newline at end of file
......@@ -138,4 +138,8 @@ smfcode.label.noReel=\u672A\u627E\u5230\u53EF\u51FA\u5EAB\u7684\u7269\u6599
smfcore.msd=MSD\u7BA1\u7406
smfcore.msdManage=MSD\u5E93\u5B58
smfcore.msdData=MSD\u8FFD\u6EAF\u6027
smfcore.msdSetting=MSD\u8A2D\u7F6E
\ No newline at end of file
smfcore.msdSetting=MSD\u8A2D\u7F6E
smfcore.translation=\u8CC7\u6E90\u7FFB\u8B6F
smfcode.languageCanotNull=\u8A9E\u8A00\u985E\u578B\u4E0D\u80FD\u70BA\u7A7A
smfcode.noLanguageSetAccess=\u6C92\u6709\u7DE8\u8F2F\u8A9E\u8A00\u7684\u6B0A\u9650
smfcode.languageCanotRemoveAll=\u4E0D\u80FD\u522A\u9664\u6240\u6709\u8A9E\u8A00
\ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!