|
|
|
@ -16,7 +16,6 @@ import javax.validation.constraints.NotNull;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
@ -111,21 +110,16 @@ public class BeanUtil extends cn.hutool.core.bean.BeanUtil {
|
|
|
|
|
public static <T extends BaseEntity> Map<String, String> processExcelAnnotationToMap(@NotNull Class<T> clazz) {
|
|
|
|
|
Map<String, String> result = new ConcurrentHashMap<>(16);
|
|
|
|
|
|
|
|
|
|
// 过滤有指定注解的属性
|
|
|
|
|
Set<Field> filterFields = Arrays.stream(clazz.getDeclaredFields())
|
|
|
|
|
Arrays.stream(clazz.getDeclaredFields())
|
|
|
|
|
// 过滤有指定注解的属性
|
|
|
|
|
.filter(declaredField -> ObjectUtil.isNotNull(AnnotationUtils.findAnnotation(declaredField, ExcelProperty.class)))
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
// 根据index属性排序,并放置到Map的返回值中
|
|
|
|
|
filterFields.stream().sorted(Comparator.comparingInt(o -> AnnotationUtils.findAnnotation(o, ExcelProperty.class).index()))
|
|
|
|
|
// 根据index属性排序,并放置到Map的返回值中
|
|
|
|
|
.sorted(Comparator.comparingInt(o -> AnnotationUtils.findAnnotation(o, ExcelProperty.class).index()))
|
|
|
|
|
// 有序执行
|
|
|
|
|
.forEachOrdered(field -> {
|
|
|
|
|
ExcelProperty annotation = AnnotationUtils.findAnnotation(field, ExcelProperty.class);
|
|
|
|
|
String title = annotation.value()[0];
|
|
|
|
|
String name = field.getName();
|
|
|
|
|
// 防止覆盖
|
|
|
|
|
if (!result.containsKey(name)) {
|
|
|
|
|
result.put(name, title);
|
|
|
|
|
}
|
|
|
|
|
result.put(field.getName(), title);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|