调解系统整理
This commit is contained in:
+32
-19
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.common.handler;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@@ -17,9 +18,11 @@ import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
/**
|
||||
@@ -39,18 +42,27 @@ public class ResponseBodyAdviceHandler implements ResponseBodyAdvice {
|
||||
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object body, MethodParameter methodParameter, MediaType mediaType, Class aClass, ServerHttpRequest request, ServerHttpResponse serverHttpResponse) {
|
||||
if (body instanceof String) {
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
try {
|
||||
return om.writeValueAsString(AjaxResult.success(body));
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("JsonProcessingException e:{}", e);
|
||||
|
||||
if (body instanceof AjaxResult) {
|
||||
AjaxResult result = (AjaxResult) body;
|
||||
if (ObjectUtil.isNotEmpty(result.get("data"))) {
|
||||
//判断类型,然后转换字典
|
||||
turnType(body);
|
||||
return body;
|
||||
}
|
||||
} else if (body instanceof TableDataInfo) {
|
||||
TableDataInfo pageRes = (TableDataInfo) body;
|
||||
List list = pageRes.getRows();
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
//判断类型,然后转换字典
|
||||
turnType(body);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
//判断类型,然后转换字典
|
||||
turnType(body);
|
||||
AjaxResult result = AjaxResult.success(body);
|
||||
return result;
|
||||
return body;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,17 +73,17 @@ public class ResponseBodyAdviceHandler implements ResponseBodyAdvice {
|
||||
private void turnType(Object body) {
|
||||
if (body instanceof AjaxResult) {
|
||||
AjaxResult result = (AjaxResult) body;
|
||||
if(result.isSuccess()){
|
||||
if (result.isSuccess()) {
|
||||
Object data = result.get("data");
|
||||
if(data!=null){
|
||||
if(data instanceof List){
|
||||
if (data != null) {
|
||||
if (data instanceof List) {
|
||||
List list = (List) data;
|
||||
convertList(list);
|
||||
}else if(data instanceof TableDataInfo){
|
||||
} else if (data instanceof TableDataInfo) {
|
||||
TableDataInfo pageRes = (TableDataInfo) data;
|
||||
List list = pageRes.getRows();
|
||||
convertList(list);
|
||||
}else{
|
||||
} else {
|
||||
loopTurn(data);
|
||||
}
|
||||
}
|
||||
@@ -185,20 +197,20 @@ public class ResponseBodyAdviceHandler implements ResponseBodyAdvice {
|
||||
if (targetField != null) {
|
||||
targetField.setAccessible(true);
|
||||
String dictType = dictConvert.dictType();
|
||||
if(StrUtil.isEmpty(dictType)){
|
||||
if (StrUtil.isEmpty(dictType)) {
|
||||
return;
|
||||
}
|
||||
//单个字典时直接设置值
|
||||
if (!dictConvert.isMultiple()) {
|
||||
|
||||
targetField.set(obj, ObjectUtil.isNotEmpty( DictUtils.getDictLabel(dictType,key)) ? DictUtils.getDictLabel(dictType,key):null);
|
||||
targetField.set(obj, ObjectUtil.isNotEmpty(DictUtils.getDictLabel(dictType, key)) ? DictUtils.getDictLabel(dictType, key) : null);
|
||||
} else {
|
||||
//多个字典时,用逗号拼接值
|
||||
List<String> textList = new ArrayList<>();
|
||||
String[] ids = key.split(dictConvert.separator());
|
||||
for (String id : ids) {
|
||||
if (ObjectUtil.isNotEmpty(DictUtils.getDictLabel(dictType,id))&&StrUtil.isNotEmpty(DictUtils.getDictLabel(dictType,id))) {
|
||||
textList.add(DictUtils.getDictLabel(dictType,id));
|
||||
if (ObjectUtil.isNotEmpty(DictUtils.getDictLabel(dictType, id)) && StrUtil.isNotEmpty(DictUtils.getDictLabel(dictType, id))) {
|
||||
textList.add(DictUtils.getDictLabel(dictType, id));
|
||||
}
|
||||
}
|
||||
targetField.set(obj, StrUtil.join(dictConvert.separator(), textList));
|
||||
@@ -210,6 +222,7 @@ public class ResponseBodyAdviceHandler implements ResponseBodyAdvice {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取目标属性
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user