数据字典

This commit is contained in:
zhn
2022-04-14 17:50:33 +08:00
parent 23ed92b7c7
commit 2c4bd9543b
@@ -84,13 +84,29 @@ public class DictAspect {
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);
items.add(item);
}
((IPage) ((Result) result).getResult()).setRecords(items);
}else if(((Result) result).getResult() instanceof List){
List<JSONObject> items = new ArrayList<>();
for (Object record : (List)((Result) result).getResult()) {
JSONObject item = getJsonObject(record);
items.add(item);
}
((Result) result).setResult(items);
}
}
}
private JSONObject getJsonObject(Object record) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
String json="{}"; String json = "{}";
try { try {
//解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat //解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
json = mapper.writeValueAsString(record); json = mapper.writeValueAsString(record);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
log.error("json解析失败"+e.getMessage(),e); log.error("json解析失败" + e.getMessage(), e);
} }
JSONObject item = JSONObject.parseObject(json); JSONObject item = JSONObject.parseObject(json);
//update-begin--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------ //update-begin--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------
@@ -106,22 +122,17 @@ public class DictAspect {
//翻译字典值对应的txt //翻译字典值对应的txt
String textValue = translateDictValue(code, text, table, key); String textValue = translateDictValue(code, text, table, key);
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);
item.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue); item.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
} }
//date类型默认转换string格式化日期 //date类型默认转换string格式化日期
if (field.getType().getName().equals("java.util.Date")&&field.getAnnotation(JsonFormat.class)==null&&item.get(field.getName())!=null){ if (field.getType().getName().equals("java.util.Date") && 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); return item;
}
((IPage) ((Result) result).getResult()).setRecords(items);
}
}
} }
/** /**