提交 6ef1753a authored 作者: kxjia's avatar kxjia

修改bug

上级 85d38cf5
...@@ -94,111 +94,111 @@ public class DictAspect { ...@@ -94,111 +94,111 @@ public class DictAspect {
* @param result * @param result
*/ */
private Object parseDictText(Object result) { private Object parseDictText(Object result) {
//if (result instanceof Result) { if (result instanceof Result) {
if (true) { if (true) {
if (((Result) result).getResult() instanceof IPage) { if (((Result) result).getResult() instanceof IPage) {
List<JSONObject> items = new ArrayList<>(); List<JSONObject> items = new ArrayList<>();
//step.1 筛选出加了 Dict 注解的字段列表 //step.1 筛选出加了 Dict 注解的字段列表
List<Field> dictFieldList = new ArrayList<>(); List<Field> dictFieldList = new ArrayList<>();
// 字典数据列表, key = 字典code,value=数据列表 // 字典数据列表, key = 字典code,value=数据列表
Map<String, List<String>> dataListMap = new HashMap<>(5); Map<String, List<String>> dataListMap = new HashMap<>(5);
//取出结果集 //取出结果集
List<Object> records=((IPage) ((Result) result).getResult()).getRecords(); List<Object> records = ((IPage) ((Result) result).getResult()).getRecords();
// 代码逻辑说明: 【VUEN-1230】 判断是否含有字典注解,没有注解返回----- // 代码逻辑说明: 【VUEN-1230】 判断是否含有字典注解,没有注解返回-----
Boolean hasDict= checkHasDict(records); Boolean hasDict = checkHasDict(records);
if(!hasDict){ if (!hasDict) {
return result; return result;
}
log.debug(" __ 进入字典翻译切面 DictAspect —— " );
for (Object record : records) {
String json="{}";
try {
//解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
json = objectMapper.writeValueAsString(record);
} catch (JsonProcessingException e) {
log.error("json解析失败"+e.getMessage(),e);
} }
// 代码逻辑说明: 【issues/3303】restcontroller返回json数据后key顺序错乱 -----
JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
//for (Field field : record.getClass().getDeclaredFields()) { log.debug(" __ 进入字典翻译切面 DictAspect —— ");
// 遍历所有字段,把字典Code取出来,放到 map 里 for (Object record : records) {
for (Field field : oConvertUtils.getAllFields(record)) { String json = "{}";
String value = item.getString(field.getName()); try {
if (oConvertUtils.isEmpty(value)) { //解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
continue; json = objectMapper.writeValueAsString(record);
} catch (JsonProcessingException e) {
log.error("json解析失败" + e.getMessage(), e);
} }
if (field.getAnnotation(Dict.class) != null) { // 代码逻辑说明: 【issues/3303】restcontroller返回json数据后key顺序错乱 -----
if (!dictFieldList.contains(field)) { JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
dictFieldList.add(field);
//for (Field field : record.getClass().getDeclaredFields()) {
// 遍历所有字段,把字典Code取出来,放到 map 里
for (Field field : oConvertUtils.getAllFields(record)) {
String value = item.getString(field.getName());
if (oConvertUtils.isEmpty(value)) {
continue;
} }
String code = field.getAnnotation(Dict.class).dicCode(); if (field.getAnnotation(Dict.class) != null) {
String text = field.getAnnotation(Dict.class).dicText(); if (!dictFieldList.contains(field)) {
String table = field.getAnnotation(Dict.class).dictTable(); dictFieldList.add(field);
// 代码逻辑说明: [issues/#5643]解决分布式下表字典跨库无法查询问题------------ }
String dataSource = field.getAnnotation(Dict.class).ds(); String code = field.getAnnotation(Dict.class).dicCode();
List<String> dataList; String text = field.getAnnotation(Dict.class).dicText();
String dictCode = code; String table = field.getAnnotation(Dict.class).dictTable();
if (!StringUtils.isEmpty(table)) {
// 代码逻辑说明: [issues/#5643]解决分布式下表字典跨库无法查询问题------------ // 代码逻辑说明: [issues/#5643]解决分布式下表字典跨库无法查询问题------------
dictCode = String.format("%s,%s,%s,%s", table, text, code, dataSource); String dataSource = field.getAnnotation(Dict.class).ds();
List<String> dataList;
String dictCode = code;
if (!StringUtils.isEmpty(table)) {
// 代码逻辑说明: [issues/#5643]解决分布式下表字典跨库无法查询问题------------
dictCode = String.format("%s,%s,%s,%s", table, text, code, dataSource);
}
dataList = dataListMap.computeIfAbsent(dictCode, k -> new ArrayList<>());
this.listAddAllDeduplicate(dataList, Arrays.asList(value.split(",")));
} }
dataList = dataListMap.computeIfAbsent(dictCode, k -> new ArrayList<>()); //date类型默认转换string格式化日期
this.listAddAllDeduplicate(dataList, Arrays.asList(value.split(","))); //if (JAVA_UTIL_DATE.equals(field.getType().getName())&&field.getAnnotation(JsonFormat.class)==null&&item.get(field.getName())!=null){
}
//date类型默认转换string格式化日期
//if (JAVA_UTIL_DATE.equals(field.getType().getName())&&field.getAnnotation(JsonFormat.class)==null&&item.get(field.getName())!=null){
//SimpleDateFormat aDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //SimpleDateFormat aDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName())))); // item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName()))));
//} //}
}
items.add(item);
} }
items.add(item);
}
//step.2 调用翻译方法,一次性翻译 //step.2 调用翻译方法,一次性翻译
Map<String, List<DictModel>> translText = this.translateAllDict(dataListMap); Map<String, List<DictModel>> translText = this.translateAllDict(dataListMap);
//step.3 将翻译结果填充到返回结果里 //step.3 将翻译结果填充到返回结果里
for (JSONObject record : items) { for (JSONObject record : items) {
for (Field field : dictFieldList) { for (Field field : dictFieldList) {
String code = field.getAnnotation(Dict.class).dicCode(); String code = field.getAnnotation(Dict.class).dicCode();
String text = field.getAnnotation(Dict.class).dicText(); String text = field.getAnnotation(Dict.class).dicText();
String table = field.getAnnotation(Dict.class).dictTable(); String table = field.getAnnotation(Dict.class).dictTable();
// 自定义的字典表数据源 // 自定义的字典表数据源
String dataSource = field.getAnnotation(Dict.class).ds(); String dataSource = field.getAnnotation(Dict.class).ds();
String fieldDictCode = code; String fieldDictCode = code;
if (!StringUtils.isEmpty(table)) { if (!StringUtils.isEmpty(table)) {
// 代码逻辑说明: [issues/#5643]解决分布式下表字典跨库无法查询问题------------ // 代码逻辑说明: [issues/#5643]解决分布式下表字典跨库无法查询问题------------
fieldDictCode = String.format("%s,%s,%s,%s", table, text, code, dataSource); fieldDictCode = String.format("%s,%s,%s,%s", table, text, code, dataSource);
}
String value = record.getString(field.getName());
if (oConvertUtils.isNotEmpty(value)) {
List<DictModel> dictModels = translText.get(fieldDictCode);
if(dictModels==null || dictModels.size()==0){
continue;
} }
String textValue = this.translDictText(dictModels, value); String value = record.getString(field.getName());
log.debug(" 字典Val : " + textValue); if (oConvertUtils.isNotEmpty(value)) {
log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + ": " + textValue); List<DictModel> dictModels = translText.get(fieldDictCode);
if (dictModels == null || dictModels.size() == 0) {
continue;
}
// TODO-sun 测试输出,待删 String textValue = this.translDictText(dictModels, value);
log.debug(" ---- dictCode: " + fieldDictCode); log.debug(" 字典Val : " + textValue);
log.debug(" ---- value: " + value); log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + ": " + textValue);
log.debug(" ----- text: " + textValue);
log.debug(" ---- dictModels: " + JSON.toJSONString(dictModels));
record.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue); // TODO-sun 测试输出,待删
log.debug(" ---- dictCode: " + fieldDictCode);
log.debug(" ---- value: " + value);
log.debug(" ----- text: " + textValue);
log.debug(" ---- dictModels: " + JSON.toJSONString(dictModels));
record.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
}
} }
} }
}
((IPage) ((Result) result).getResult()).setRecords(items); ((IPage) ((Result) result).getResult()).setRecords(items);
}
} }
} }
return result; return result;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论