数据字典实现中英文切换
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 = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-4
@@ -24,7 +24,7 @@ import java.util.Map;
|
||||
* @since 2018-12-28
|
||||
*/
|
||||
public interface SysDictMapper extends BaseMapper<SysDict> {
|
||||
|
||||
|
||||
/**
|
||||
* 重复检查SQL
|
||||
* @return
|
||||
@@ -32,7 +32,7 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
|
||||
public Long duplicateCheckCountSql(DuplicateCheckVo duplicateCheckVo);
|
||||
|
||||
public Long duplicateCheckCountSqlNoDataId(DuplicateCheckVo duplicateCheckVo);
|
||||
|
||||
|
||||
public List<DictModel> queryDictItemsByCode(@Param("code") String code);
|
||||
|
||||
@Deprecated
|
||||
@@ -47,6 +47,8 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
|
||||
|
||||
public String queryDictTextByKey(@Param("code") String code,@Param("key") String key);
|
||||
|
||||
public String queryDictTextByKeyEn(@Param("code") String code,@Param("key") String key);
|
||||
|
||||
public String queryDictKeyByText(@Param("code") String code,@Param("text") String key);
|
||||
|
||||
@Deprecated
|
||||
@@ -60,13 +62,13 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
|
||||
* @return
|
||||
*/
|
||||
public List<DictModel> queryAllDepartBackDictModel();
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有用户 作为字典信息 username -->value,realname -->text
|
||||
* @return
|
||||
*/
|
||||
public List<DictModel> queryAllUserBackDictModel();
|
||||
|
||||
|
||||
/**
|
||||
* 通过关键字查询出字典表
|
||||
* @param table
|
||||
|
||||
+6
@@ -15,6 +15,12 @@
|
||||
where s.dict_id = (select id from sys_dict where dict_code = #{code})
|
||||
and s.item_value = #{key}
|
||||
</select>
|
||||
<!-- 通过字典code获取字典数据(英文) -->
|
||||
<select id="queryDictTextByKeyEn" parameterType="String" resultType="String">
|
||||
select s.en_name from sys_dict_item s
|
||||
where s.dict_id = (select id from sys_dict where dict_code = #{code})
|
||||
and s.item_value = #{key}
|
||||
</select>
|
||||
|
||||
<!-- 通过字典code获取字典数据 -->
|
||||
<select id="queryDictKeyByText" parameterType="String" resultType="String">
|
||||
|
||||
+1
@@ -33,6 +33,7 @@ public interface ISysDictService extends IService<SysDict> {
|
||||
public List<DictModel> queryTableDictItemsByCodeAndFilter(String table, String text, String code, String filterSql);
|
||||
|
||||
public String queryDictTextByKey(String code, String key);
|
||||
public String queryDictTextByKeyEn(String code, String key,String cut);
|
||||
|
||||
@Deprecated
|
||||
String queryTableDictTextByKey(String table, String text, String code, String key);
|
||||
|
||||
+7
-2
@@ -51,7 +51,7 @@ import java.util.*;
|
||||
/**
|
||||
* @Description: 底层共通业务API,提供其他独立模块调用
|
||||
* @Author: scott
|
||||
* @Date:2019-4-20
|
||||
* @Date:2019-4-20
|
||||
* @Version:V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@@ -118,6 +118,11 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||
return sysDictService.queryDictTextByKey(code, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translateDictEn(String code, String key, String cut) {
|
||||
return sysDictService.queryDictTextByKeyEn(code, key,cut);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysPermissionDataRuleModel> queryPermissionDataRule(String component, String requestPath, String username) {
|
||||
List<SysPermission> currentSyspermission = null;
|
||||
@@ -1015,4 +1020,4 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||
public List<SysDepartTreeModel> listSonDepartsByDepId(String departId) {
|
||||
return sysDepartService.listSonDepartsByDepId(departId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -123,6 +123,12 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
log.debug("无缓存dictText的时候调用这里!");
|
||||
return sysDictMapper.queryDictTextByKey(code, key);
|
||||
}
|
||||
@Override
|
||||
@Cacheable(value = CacheConstant.SYS_DICT_CACHE,key = "#code+':'+#key+#cut")
|
||||
public String queryDictTextByKeyEn(String code, String key,String cut) {
|
||||
log.debug("无缓存dictText的时候调用这里!");
|
||||
return sysDictMapper.queryDictTextByKeyEn(code, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过查询指定table的 text code 获取字典
|
||||
|
||||
-2
@@ -588,8 +588,6 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> getDocumentInfoById(String id, String cut) {
|
||||
LambdaQueryWrapper<BussDocumentLibraryEO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(BussDocumentLibraryEO::getId, id);
|
||||
//字段属性
|
||||
List<OnlCgformField> fieldList = onlCgformFieldService.getFieldList("1");
|
||||
List<OnlCgformField> treeOnlCgformFieldList = fieldList.stream().filter(e -> FieldTypeEnum.TREE.getValue().equals(e.getFieldShowType())).collect(Collectors.toList());
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public class DummyInventoryBaseEOController extends JeroController<DummyInventor
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
Page<DummyInventoryBaseEO> page = new Page<DummyInventoryBaseEO>(pageNo, pageSize);
|
||||
IPage<DummyInventoryBaseEO> pageList = dummyInventoryBaseEOService.getPageInfo(page,queryWrapper);
|
||||
return Result.OK(pageList);
|
||||
return Result.OK(dummyInventoryBaseEO.getCut(),pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user