数据字典实现中英文切换
This commit is contained in:
+5
@@ -229,6 +229,11 @@ public class SysBaseAPIFallback implements ISysBaseAPI {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translateDictEn(String code, String key, String cut) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysPermissionDataRuleModel> queryPermissionDataRule(String component, String requestPath, String username) {
|
||||
return null;
|
||||
|
||||
+8
@@ -64,6 +64,14 @@ public interface CommonAPI {
|
||||
*/
|
||||
String translateDict(String code, String key);
|
||||
|
||||
/**
|
||||
* 数据字典英文
|
||||
* @param code
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
String translateDictEn(String code, String key,String cut);
|
||||
|
||||
/**
|
||||
* 8查询数据权限
|
||||
* @return
|
||||
|
||||
+17
-7
@@ -3,6 +3,7 @@ package com.jero.common.api.vo;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.jero.common.constant.enums.CutEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
@@ -31,18 +32,24 @@ public class Result<T> implements Serializable {
|
||||
@ApiModelProperty(value = "返回处理消息")
|
||||
private String message = "操作成功!";
|
||||
|
||||
/**
|
||||
* 返回处理消息
|
||||
*/
|
||||
@ApiModelProperty(value = "中英文切换标识")
|
||||
private String cut = "操作成功!";
|
||||
|
||||
/**
|
||||
* 返回代码
|
||||
*/
|
||||
@ApiModelProperty(value = "返回代码")
|
||||
private Integer code = 0;
|
||||
|
||||
|
||||
/**
|
||||
* 返回数据对象 data
|
||||
*/
|
||||
@ApiModelProperty(value = "返回数据对象")
|
||||
private T result;
|
||||
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
@@ -50,9 +57,9 @@ public class Result<T> implements Serializable {
|
||||
private long timestamp = System.currentTimeMillis();
|
||||
|
||||
public Result() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Result<T> success(String message) {
|
||||
this.message = message;
|
||||
this.code = CommonConstant.SC_OK_200;
|
||||
@@ -108,14 +115,17 @@ public class Result<T> implements Serializable {
|
||||
r.setSuccess(true);
|
||||
r.setCode(CommonConstant.SC_OK_200);
|
||||
r.setMessage(msg);
|
||||
if(CutEnum.CN.getValue().equals(msg) || CutEnum.EN.getValue().equals(msg)){
|
||||
r.setCut(msg);
|
||||
}
|
||||
r.setResult(data);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
public static Result<Object> error(String msg) {
|
||||
return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
|
||||
}
|
||||
|
||||
|
||||
public static Result<Object> error(int code, String msg) {
|
||||
Result<Object> r = new Result<Object>();
|
||||
r.setCode(code);
|
||||
@@ -140,4 +150,4 @@ public class Result<T> implements Serializable {
|
||||
@JsonIgnore
|
||||
private String onlTable;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+15
-6
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jero.common.constant.enums.CutEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
@@ -80,11 +81,12 @@ public class DictAspect {
|
||||
* @param result
|
||||
*/
|
||||
private void parseDictText(Object result) {
|
||||
String cut = ((Result) result).getCut();
|
||||
if (result instanceof Result) {
|
||||
if (((Result) result).getResult() instanceof IPage) {
|
||||
List<JSONObject> items = new ArrayList<>();
|
||||
for (Object record : ((IPage) ((Result) result).getResult()).getRecords()) {
|
||||
JSONObject item = getJsonObject(record);
|
||||
JSONObject item = getJsonObject(record,cut);
|
||||
items.add(item);
|
||||
}
|
||||
((IPage) ((Result) result).getResult()).setRecords(items);
|
||||
@@ -94,7 +96,7 @@ public class DictAspect {
|
||||
if(!"java.util.LinkedHashMap".equals(name) && !"java.util.HashMap".equals(name)){
|
||||
List<JSONObject> items = new ArrayList<>();
|
||||
for (Object record : (List)((Result) result).getResult()) {
|
||||
JSONObject item = getJsonObject(record);
|
||||
JSONObject item = getJsonObject(record,cut);
|
||||
items.add(item);
|
||||
}
|
||||
((Result) result).setResult(items);
|
||||
@@ -103,7 +105,7 @@ public class DictAspect {
|
||||
}
|
||||
}
|
||||
|
||||
private JSONObject getJsonObject(Object record) {
|
||||
private JSONObject getJsonObject(Object record,String cut) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String json = "{}";
|
||||
try {
|
||||
@@ -124,7 +126,7 @@ public class DictAspect {
|
||||
String key = String.valueOf(item.get(field.getName()));
|
||||
|
||||
//翻译字典值对应的txt
|
||||
String textValue = translateDictValue(code, text, table, key);
|
||||
String textValue = translateDictValue(code, text, table, key,cut);
|
||||
|
||||
log.debug(" 字典Val : " + textValue);
|
||||
log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + ": " + textValue);
|
||||
@@ -147,7 +149,7 @@ public class DictAspect {
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
private String translateDictValue(String code, String text, String table, String key) {
|
||||
private String translateDictValue(String code, String text, String table, String key,String cut) {
|
||||
if(oConvertUtils.isEmpty(key)) {
|
||||
return null;
|
||||
}
|
||||
@@ -163,13 +165,20 @@ public class DictAspect {
|
||||
log.debug("--DictAspect------dicTable="+ table+" ,dicText= "+text+" ,dicCode="+code);
|
||||
tmpValue= commonAPI.translateDictFromTable(table,text,code,k.trim());
|
||||
}else {
|
||||
tmpValue = commonAPI.translateDict(code, k.trim());
|
||||
if(CutEnum.CN.getValue().equals(cut)){
|
||||
tmpValue = commonAPI.translateDict(code, k.trim());
|
||||
}else if(CutEnum.EN.getValue().equals(cut)){
|
||||
tmpValue = commonAPI.translateDictEn(code, k.trim(),cut);
|
||||
}
|
||||
|
||||
}
|
||||
if (tmpValue != null) {
|
||||
if (!"".equals(textValue.toString())) {
|
||||
textValue.append(",");
|
||||
}
|
||||
textValue.append(tmpValue);
|
||||
}else{
|
||||
tmpValue = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user