数据字典实现中英文切换

This commit is contained in:
zhn
2022-04-15 15:41:37 +08:00
parent c724bc3cd0
commit 00ab8406d8
11 changed files with 72 additions and 22 deletions
@@ -229,6 +229,11 @@ public class SysBaseAPIFallback implements ISysBaseAPI {
return null; return null;
} }
@Override
public String translateDictEn(String code, String key, String cut) {
return null;
}
@Override @Override
public List<SysPermissionDataRuleModel> queryPermissionDataRule(String component, String requestPath, String username) { public List<SysPermissionDataRuleModel> queryPermissionDataRule(String component, String requestPath, String username) {
return null; return null;
@@ -64,6 +64,14 @@ public interface CommonAPI {
*/ */
String translateDict(String code, String key); String translateDict(String code, String key);
/**
* 数据字典英文
* @param code
* @param key
* @return
*/
String translateDictEn(String code, String key,String cut);
/** /**
* 8查询数据权限 * 8查询数据权限
* @return * @return
@@ -3,6 +3,7 @@ package com.jero.common.api.vo;
import java.io.Serializable; import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jero.common.constant.enums.CutEnum;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import com.jero.common.constant.CommonConstant; import com.jero.common.constant.CommonConstant;
@@ -31,18 +32,24 @@ public class Result<T> implements Serializable {
@ApiModelProperty(value = "返回处理消息") @ApiModelProperty(value = "返回处理消息")
private String message = "操作成功!"; private String message = "操作成功!";
/**
* 返回处理消息
*/
@ApiModelProperty(value = "中英文切换标识")
private String cut = "操作成功!";
/** /**
* 返回代码 * 返回代码
*/ */
@ApiModelProperty(value = "返回代码") @ApiModelProperty(value = "返回代码")
private Integer code = 0; private Integer code = 0;
/** /**
* 返回数据对象 data * 返回数据对象 data
*/ */
@ApiModelProperty(value = "返回数据对象") @ApiModelProperty(value = "返回数据对象")
private T result; private T result;
/** /**
* 时间戳 * 时间戳
*/ */
@@ -50,9 +57,9 @@ public class Result<T> implements Serializable {
private long timestamp = System.currentTimeMillis(); private long timestamp = System.currentTimeMillis();
public Result() { public Result() {
} }
public Result<T> success(String message) { public Result<T> success(String message) {
this.message = message; this.message = message;
this.code = CommonConstant.SC_OK_200; this.code = CommonConstant.SC_OK_200;
@@ -108,14 +115,17 @@ public class Result<T> implements Serializable {
r.setSuccess(true); r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200); r.setCode(CommonConstant.SC_OK_200);
r.setMessage(msg); r.setMessage(msg);
if(CutEnum.CN.getValue().equals(msg) || CutEnum.EN.getValue().equals(msg)){
r.setCut(msg);
}
r.setResult(data); r.setResult(data);
return r; return r;
} }
public static Result<Object> error(String msg) { public static Result<Object> error(String msg) {
return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg); return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
} }
public static Result<Object> error(int code, String msg) { public static Result<Object> error(int code, String msg) {
Result<Object> r = new Result<Object>(); Result<Object> r = new Result<Object>();
r.setCode(code); r.setCode(code);
@@ -140,4 +150,4 @@ public class Result<T> implements Serializable {
@JsonIgnore @JsonIgnore
private String onlTable; private String onlTable;
} }
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.jero.common.constant.enums.CutEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
@@ -80,11 +81,12 @@ public class DictAspect {
* @param result * @param result
*/ */
private void parseDictText(Object result) { private void parseDictText(Object result) {
String cut = ((Result) result).getCut();
if (result instanceof Result) { if (result instanceof Result) {
if (((Result) result).getResult() instanceof IPage) { if (((Result) result).getResult() instanceof IPage) {
List<JSONObject> items = new ArrayList<>(); List<JSONObject> items = new ArrayList<>();
for (Object record : ((IPage) ((Result) result).getResult()).getRecords()) { for (Object record : ((IPage) ((Result) result).getResult()).getRecords()) {
JSONObject item = getJsonObject(record); JSONObject item = getJsonObject(record,cut);
items.add(item); items.add(item);
} }
((IPage) ((Result) result).getResult()).setRecords(items); ((IPage) ((Result) result).getResult()).setRecords(items);
@@ -94,7 +96,7 @@ public class DictAspect {
if(!"java.util.LinkedHashMap".equals(name) && !"java.util.HashMap".equals(name)){ if(!"java.util.LinkedHashMap".equals(name) && !"java.util.HashMap".equals(name)){
List<JSONObject> items = new ArrayList<>(); List<JSONObject> items = new ArrayList<>();
for (Object record : (List)((Result) result).getResult()) { for (Object record : (List)((Result) result).getResult()) {
JSONObject item = getJsonObject(record); JSONObject item = getJsonObject(record,cut);
items.add(item); items.add(item);
} }
((Result) result).setResult(items); ((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(); ObjectMapper mapper = new ObjectMapper();
String json = "{}"; String json = "{}";
try { try {
@@ -124,7 +126,7 @@ public class DictAspect {
String key = String.valueOf(item.get(field.getName())); String key = String.valueOf(item.get(field.getName()));
//翻译字典值对应的txt //翻译字典值对应的txt
String textValue = translateDictValue(code, text, table, key); String textValue = translateDictValue(code, text, table, key,cut);
log.debug(" 字典Val : " + textValue); log.debug(" 字典Val : " + textValue);
log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + " " + textValue); log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + " " + textValue);
@@ -147,7 +149,7 @@ public class DictAspect {
* @param key * @param key
* @return * @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)) { if(oConvertUtils.isEmpty(key)) {
return null; return null;
} }
@@ -163,13 +165,20 @@ public class DictAspect {
log.debug("--DictAspect------dicTable="+ table+" ,dicText= "+text+" ,dicCode="+code); log.debug("--DictAspect------dicTable="+ table+" ,dicText= "+text+" ,dicCode="+code);
tmpValue= commonAPI.translateDictFromTable(table,text,code,k.trim()); tmpValue= commonAPI.translateDictFromTable(table,text,code,k.trim());
}else { }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 (tmpValue != null) {
if (!"".equals(textValue.toString())) { if (!"".equals(textValue.toString())) {
textValue.append(","); textValue.append(",");
} }
textValue.append(tmpValue); textValue.append(tmpValue);
}else{
tmpValue = "";
} }
} }
@@ -24,7 +24,7 @@ import java.util.Map;
* @since 2018-12-28 * @since 2018-12-28
*/ */
public interface SysDictMapper extends BaseMapper<SysDict> { public interface SysDictMapper extends BaseMapper<SysDict> {
/** /**
* 重复检查SQL * 重复检查SQL
* @return * @return
@@ -32,7 +32,7 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
public Long duplicateCheckCountSql(DuplicateCheckVo duplicateCheckVo); public Long duplicateCheckCountSql(DuplicateCheckVo duplicateCheckVo);
public Long duplicateCheckCountSqlNoDataId(DuplicateCheckVo duplicateCheckVo); public Long duplicateCheckCountSqlNoDataId(DuplicateCheckVo duplicateCheckVo);
public List<DictModel> queryDictItemsByCode(@Param("code") String code); public List<DictModel> queryDictItemsByCode(@Param("code") String code);
@Deprecated @Deprecated
@@ -47,6 +47,8 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
public String queryDictTextByKey(@Param("code") String code,@Param("key") String key); 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); public String queryDictKeyByText(@Param("code") String code,@Param("text") String key);
@Deprecated @Deprecated
@@ -60,13 +62,13 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
* @return * @return
*/ */
public List<DictModel> queryAllDepartBackDictModel(); public List<DictModel> queryAllDepartBackDictModel();
/** /**
* 查询所有用户 作为字典信息 username -->value,realname -->text * 查询所有用户 作为字典信息 username -->value,realname -->text
* @return * @return
*/ */
public List<DictModel> queryAllUserBackDictModel(); public List<DictModel> queryAllUserBackDictModel();
/** /**
* 通过关键字查询出字典表 * 通过关键字查询出字典表
* @param table * @param table
@@ -15,6 +15,12 @@
where s.dict_id = (select id from sys_dict where dict_code = #{code}) where s.dict_id = (select id from sys_dict where dict_code = #{code})
and s.item_value = #{key} and s.item_value = #{key}
</select> </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获取字典数据 --> <!-- 通过字典code获取字典数据 -->
<select id="queryDictKeyByText" parameterType="String" resultType="String"> <select id="queryDictKeyByText" parameterType="String" resultType="String">
@@ -33,6 +33,7 @@ public interface ISysDictService extends IService<SysDict> {
public List<DictModel> queryTableDictItemsByCodeAndFilter(String table, String text, String code, String filterSql); public List<DictModel> queryTableDictItemsByCodeAndFilter(String table, String text, String code, String filterSql);
public String queryDictTextByKey(String code, String key); public String queryDictTextByKey(String code, String key);
public String queryDictTextByKeyEn(String code, String key,String cut);
@Deprecated @Deprecated
String queryTableDictTextByKey(String table, String text, String code, String key); String queryTableDictTextByKey(String table, String text, String code, String key);
@@ -51,7 +51,7 @@ import java.util.*;
/** /**
* @Description: 底层共通业务API,提供其他独立模块调用 * @Description: 底层共通业务API,提供其他独立模块调用
* @Author: scott * @Author: scott
* @Date:2019-4-20 * @Date:2019-4-20
* @Version:V1.0 * @Version:V1.0
*/ */
@Slf4j @Slf4j
@@ -118,6 +118,11 @@ public class SysBaseApiImpl implements ISysBaseAPI {
return sysDictService.queryDictTextByKey(code, key); return sysDictService.queryDictTextByKey(code, key);
} }
@Override
public String translateDictEn(String code, String key, String cut) {
return sysDictService.queryDictTextByKeyEn(code, key,cut);
}
@Override @Override
public List<SysPermissionDataRuleModel> queryPermissionDataRule(String component, String requestPath, String username) { public List<SysPermissionDataRuleModel> queryPermissionDataRule(String component, String requestPath, String username) {
List<SysPermission> currentSyspermission = null; List<SysPermission> currentSyspermission = null;
@@ -1015,4 +1020,4 @@ public class SysBaseApiImpl implements ISysBaseAPI {
public List<SysDepartTreeModel> listSonDepartsByDepId(String departId) { public List<SysDepartTreeModel> listSonDepartsByDepId(String departId) {
return sysDepartService.listSonDepartsByDepId(departId); return sysDepartService.listSonDepartsByDepId(departId);
} }
} }
@@ -123,6 +123,12 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
log.debug("无缓存dictText的时候调用这里!"); log.debug("无缓存dictText的时候调用这里!");
return sysDictMapper.queryDictTextByKey(code, key); 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 获取字典 * 通过查询指定table的 text code 获取字典
@@ -588,8 +588,6 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
*/ */
@Override @Override
public List<Map<String, Object>> getDocumentInfoById(String id, String cut) { 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> fieldList = onlCgformFieldService.getFieldList("1");
List<OnlCgformField> treeOnlCgformFieldList = fieldList.stream().filter(e -> FieldTypeEnum.TREE.getValue().equals(e.getFieldShowType())).collect(Collectors.toList()); List<OnlCgformField> treeOnlCgformFieldList = fieldList.stream().filter(e -> FieldTypeEnum.TREE.getValue().equals(e.getFieldShowType())).collect(Collectors.toList());
@@ -59,7 +59,7 @@ public class DummyInventoryBaseEOController extends JeroController<DummyInventor
queryWrapper.orderByDesc("create_time"); queryWrapper.orderByDesc("create_time");
Page<DummyInventoryBaseEO> page = new Page<DummyInventoryBaseEO>(pageNo, pageSize); Page<DummyInventoryBaseEO> page = new Page<DummyInventoryBaseEO>(pageNo, pageSize);
IPage<DummyInventoryBaseEO> pageList = dummyInventoryBaseEOService.getPageInfo(page,queryWrapper); IPage<DummyInventoryBaseEO> pageList = dummyInventoryBaseEOService.getPageInfo(page,queryWrapper);
return Result.OK(pageList); return Result.OK(dummyInventoryBaseEO.getCut(),pageList);
} }
/** /**