|
@@ -3,10 +3,12 @@ package com.qmth.boot.tools.excel.model;
|
|
|
import com.qmth.boot.tools.excel.annotation.ExcelColumn;
|
|
|
import com.qmth.boot.tools.excel.convertor.ValueConvertor;
|
|
|
import com.qmth.boot.tools.excel.convertor.ValueConvertors;
|
|
|
+import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
public class ObjectParam extends HashMap<String, FieldParam> {
|
|
|
|
|
@@ -24,6 +26,8 @@ public class ObjectParam extends HashMap<String, FieldParam> {
|
|
|
|
|
|
private String[] columnNames;
|
|
|
|
|
|
+ private List<FieldParam> fieldList;
|
|
|
+
|
|
|
private ObjectParam(Class<?> objectType) {
|
|
|
super();
|
|
|
|
|
@@ -48,12 +52,31 @@ public class ObjectParam extends HashMap<String, FieldParam> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- List<FieldParam> list = new ArrayList<>(values());
|
|
|
- list.sort(Comparator.comparingInt(p -> p.getAnnotation().index()));
|
|
|
- columnNames = list.stream().map(p -> p.getAnnotation().name()).toArray(String[]::new);
|
|
|
+ fieldList = new ArrayList<>(values());
|
|
|
+ fieldList.sort(Comparator.comparingInt(p -> p.getAnnotation().index()));
|
|
|
+ columnNames = fieldList.stream().map(p -> p.getAnnotation().name()).toArray(String[]::new);
|
|
|
}
|
|
|
|
|
|
public String[] getColumnNames() {
|
|
|
return columnNames;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证解析的列名,需要所有非空字段对应的列名存在
|
|
|
+ * 返回缺少的列名,不缺时返回集合为空
|
|
|
+ *
|
|
|
+ * @param columnNames
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Set<String> validate(String[] columnNames) {
|
|
|
+ Set<String> columnSet = fieldList.stream().filter(p -> !p.getAnnotation().nullable())
|
|
|
+ .map(p -> p.getAnnotation().name()).collect(Collectors.toCollection(LinkedHashSet::new));
|
|
|
+ if (ArrayUtils.isEmpty(columnNames)) {
|
|
|
+ return columnSet;
|
|
|
+ }
|
|
|
+ for (String name : columnNames) {
|
|
|
+ columnSet.remove(name);
|
|
|
+ }
|
|
|
+ return columnSet;
|
|
|
+ }
|
|
|
}
|