package com.yuanchu.mom.common;
|
|
import cn.hutool.core.util.StrUtil;
|
import com.yuanchu.mom.annotation.ValueTableShow;
|
import io.swagger.annotations.ApiModelProperty;
|
|
import java.lang.reflect.Field;
|
import java.util.*;
|
|
/*李林
|
* 通过注解快速生成table表头*/
|
|
public class PrintChina {
|
|
public static <T> List<Map<String, Object>> printChina(Class<T> tClass) {
|
//将实体类的属性和注释转换成参数
|
List<Field> fieldList = new ArrayList<>();
|
while (tClass != null){
|
fieldList.addAll(new ArrayList<>(Arrays.asList(tClass.getDeclaredFields())));
|
tClass = (Class<T>) tClass.getSuperclass();
|
}
|
Field[] fields = new Field[fieldList.size()];
|
fieldList.toArray(fields);
|
ArrayList<Map<String, Object>> list = new ArrayList<>();
|
for (Field field : fields) {
|
Map<String, Object> soundVo = new HashMap<>();
|
boolean bool = field.isAnnotationPresent(ApiModelProperty.class);
|
boolean bool2 = field.isAnnotationPresent(ValueTableShow.class);
|
if (bool2) {
|
int order = field.getAnnotation(ValueTableShow.class).value();
|
String value = field.getAnnotation(ValueTableShow.class).name();
|
int width = field.getAnnotation(ValueTableShow.class).width();
|
if (bool){
|
value = value.isEmpty() ? field.getAnnotation(ApiModelProperty.class).value() : value;
|
}
|
soundVo.put("label", field.getName());
|
soundVo.put("value", value);
|
soundVo.put("width", width);
|
soundVo.put("order", order + "");
|
if(list.size() == 0){
|
list.add(soundVo);
|
}else{
|
boolean isAdd = false;
|
for (int i = 0; i < list.size(); i++) {
|
Map<String, Object> map = list.get(i);
|
if(order < Integer.parseInt(map.get("order").toString())){
|
list.add(i, soundVo);
|
isAdd = true;
|
break;
|
}
|
}
|
if (!isAdd) list.add(soundVo);
|
}
|
}
|
}
|
return list;
|
}
|
|
}
|