|
|
|
@ -8,14 +8,15 @@ import cn.hutool.core.util.ReflectUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.alibaba.excel.annotation.ExcelProperty;
|
|
|
|
|
import com.ibeetl.admin.core.entity.BaseEntity;
|
|
|
|
|
import org.springframework.core.annotation.AnnotationUtils;
|
|
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
import org.springframework.util.MultiValueMapAdapter;
|
|
|
|
|
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
|
import java.lang.annotation.Annotation;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
@ -104,23 +105,29 @@ public class BeanUtil extends cn.hutool.core.bean.BeanUtil {
|
|
|
|
|
* value只支持单个
|
|
|
|
|
* 只用到 value和 index
|
|
|
|
|
*
|
|
|
|
|
* @param object
|
|
|
|
|
* @param clazz
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static <T extends BaseEntity> void processExcelAnnotation(@NotNull Class<T> object) {
|
|
|
|
|
Map<String, String> result = new TreeMap<>();
|
|
|
|
|
public static <T extends BaseEntity> Map<String, String> processExcelAnnotationToMap(@NotNull Class<T> clazz) {
|
|
|
|
|
Map<String, String> result = new ConcurrentHashMap<>(16);
|
|
|
|
|
|
|
|
|
|
for (Field declaredField : object.getDeclaredFields()) {
|
|
|
|
|
Annotation[] declaredAnnotations = declaredField.getDeclaredAnnotations();
|
|
|
|
|
for (Annotation declaredAnnotation : declaredAnnotations) {
|
|
|
|
|
// 判断是否是easyExcel 的注解
|
|
|
|
|
if (declaredAnnotation instanceof ExcelProperty) {
|
|
|
|
|
ExcelProperty excelProperty = (ExcelProperty) declaredAnnotation;
|
|
|
|
|
String title = excelProperty.value()[0];
|
|
|
|
|
int index = excelProperty.index();
|
|
|
|
|
result.put(declaredField.getName(), title);
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 过滤有指定注解的属性
|
|
|
|
|
Set<Field> filterFields = 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()))
|
|
|
|
|
.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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|