|
@@ -71,7 +71,7 @@ public class DictAspect {
|
|
|
* sex:1,
|
|
|
* sex_dictText:"男"
|
|
|
* }
|
|
|
- * 前端直接取值sext_dictText在table里面无需再进行前端的字典转换了
|
|
|
+ * 前端直接取值sext_dict在table里面无需再进行前端的字典转换了
|
|
|
* customRender:function (text) {
|
|
|
* if(text==1){
|
|
|
* return "男";
|
|
@@ -85,45 +85,49 @@ public class DictAspect {
|
|
|
* @param result
|
|
|
*/
|
|
|
private void parseDictText(Object result) {
|
|
|
- if (result instanceof AjaxMessage) {
|
|
|
- if (((AjaxMessage) result).getData() instanceof Pagination) {
|
|
|
- List<JSONObject> items = new ArrayList<>();
|
|
|
- for (Object record : ((Pagination) ((AjaxMessage) result).getData()).getList()) {
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- String json = "{}";
|
|
|
- try {
|
|
|
- //解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
|
|
|
- json = mapper.writeValueAsString(record);
|
|
|
- } catch (JsonProcessingException e) {
|
|
|
- log.error("json解析失败" + e.getMessage(), e);
|
|
|
- }
|
|
|
- JSONObject item = JSONObject.parseObject(json);
|
|
|
- for (Field field : getAllFields(record)) {
|
|
|
- if (field.getAnnotation(Dict.class) != null) {
|
|
|
- String code = field.getAnnotation(Dict.class).dicCode();
|
|
|
- String text = field.getAnnotation(Dict.class).dicText();
|
|
|
- String table = field.getAnnotation(Dict.class).dictTable();
|
|
|
- String key = String.valueOf(item.get(field.getName()));
|
|
|
-
|
|
|
- //翻译字典值对应的txt
|
|
|
- String textValue = translateDictValue(code, text, table, key);
|
|
|
-
|
|
|
- log.debug(" 字典Val : " + textValue);
|
|
|
- log.debug(" __翻译字典字段__ " + field.getName() + DICT_TEXT_SUFFIX + ": " + textValue);
|
|
|
- item.put(field.getName() + DICT_TEXT_SUFFIX, textValue);
|
|
|
- }
|
|
|
- //date类型默认转换string格式化日期
|
|
|
- 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");
|
|
|
- //解决日期较小的情况下被解析为Integer,最后导致导致强转为Long的报错问题
|
|
|
- item.put(field.getName(), aDate.format(new Date(Long.valueOf(String.valueOf(item.get(field.getName()))))));
|
|
|
- }
|
|
|
- }
|
|
|
- items.add(item);
|
|
|
+ if (!(result instanceof AjaxMessage)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!(((AjaxMessage) result).getData() instanceof Pagination)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<JSONObject> items = new ArrayList<>();
|
|
|
+ List dataList = ((Pagination) ((AjaxMessage) result).getData()).getList();
|
|
|
+ for (Object record : dataList) {
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ String json = "{}";
|
|
|
+ try {
|
|
|
+ //解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
|
|
|
+ json = mapper.writeValueAsString(record);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ log.error("json解析失败" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ JSONObject item = JSONObject.parseObject(json);
|
|
|
+ for (Field field : getAllFields(record)) {
|
|
|
+ if (field.getAnnotation(Dict.class) != null) {
|
|
|
+ String code = field.getAnnotation(Dict.class).dicCode();
|
|
|
+ String text = field.getAnnotation(Dict.class).dicText();
|
|
|
+ String table = field.getAnnotation(Dict.class).dictTable();
|
|
|
+ String key = String.valueOf(item.get(field.getName()));
|
|
|
+
|
|
|
+ //翻译字典值对应的txt
|
|
|
+ String textValue = translateDictValue(code, text, table, key);
|
|
|
+
|
|
|
+ log.debug(" 字典Val : " + textValue);
|
|
|
+ log.debug(" __翻译字典字段__ " + field.getName() + DICT_TEXT_SUFFIX + ": " + textValue);
|
|
|
+ item.put(field.getName() + DICT_TEXT_SUFFIX, textValue);
|
|
|
+ }
|
|
|
+ //date类型默认转换string格式化日期
|
|
|
+ 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");
|
|
|
+ //解决日期较小的情况下被解析为Integer,最后导致导致强转为Long的报错问题
|
|
|
+ item.put(field.getName(), aDate.format(new Date(Long.valueOf(String.valueOf(item.get(field.getName()))))));
|
|
|
}
|
|
|
- ((Pagination) ((AjaxMessage) result).getData()).setList(items);
|
|
|
}
|
|
|
+ items.add(item);
|
|
|
}
|
|
|
+ ((Pagination) ((AjaxMessage) result).getData()).setList(items);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -145,7 +149,7 @@ public class DictAspect {
|
|
|
String tmpValue = null;
|
|
|
log.debug(" 字典 key : " + k);
|
|
|
if (k.trim().length() == 0) {
|
|
|
- continue; //跳过循环
|
|
|
+ continue;
|
|
|
}
|
|
|
tmpValue = dictUtil.getDictName(code, Integer.parseInt(k.trim()));
|
|
|
if (tmpValue != null) {
|