feat: 继承类问题修改
This commit is contained in:
parent
beeadfc35c
commit
68f9c8b9db
|
|
@ -9,6 +9,7 @@ import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
|
@ -34,7 +35,7 @@ public class EncryptUtil {
|
|||
return data;
|
||||
}
|
||||
try {
|
||||
List<Field> fieldList = Arrays.stream(clazz.getDeclaredFields()).filter(field -> field.isAnnotationPresent(Encrypt.class)).collect(Collectors.toList());
|
||||
List<Field> fieldList = getFields(clazz);
|
||||
if (CollectionUtils.isNotEmpty(fieldList)) {
|
||||
for (Field field : fieldList) {
|
||||
Field declaredField = data.getClass().getDeclaredField(field.getName());
|
||||
|
|
@ -53,6 +54,24 @@ public class EncryptUtil {
|
|||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static <T> List<Field> getFields(Class<T> clazz) {
|
||||
List<Class<?>> allClasses = new ArrayList<Class<?>>();
|
||||
allClasses.add(clazz);
|
||||
Class<?> superClazz;
|
||||
while ((superClazz = clazz.getSuperclass()) != null) {
|
||||
if (superClazz != Object.class) {
|
||||
allClasses.add(superClazz);
|
||||
}
|
||||
}
|
||||
List<Field> fieldList =
|
||||
allClasses.stream()
|
||||
.map(Class::getDeclaredFields)
|
||||
.flatMap(Arrays::stream)
|
||||
.filter(field -> field.isAnnotationPresent(Encrypt.class)).collect(Collectors.toList());
|
||||
return fieldList;
|
||||
}
|
||||
|
||||
public <T> List<T> encryptList(List<T> dataList, Class<T> clazz) {
|
||||
if (CollectionUtils.isEmpty(dataList) || clazz == null) {
|
||||
return dataList;
|
||||
|
|
@ -62,7 +81,7 @@ public class EncryptUtil {
|
|||
return dataList;
|
||||
}
|
||||
try {
|
||||
List<Field> fieldList = Arrays.stream(clazz.getDeclaredFields()).filter(field -> field.isAnnotationPresent(Encrypt.class)).collect(Collectors.toList());
|
||||
List<Field> fieldList = getFields(clazz);
|
||||
if (CollectionUtils.isNotEmpty(fieldList)) {
|
||||
List<Map<String, String>> values = new ArrayList<>();
|
||||
for (T data : dataList) {
|
||||
|
|
@ -94,7 +113,7 @@ public class EncryptUtil {
|
|||
return data;
|
||||
}
|
||||
try {
|
||||
List<Field> fieldList = Arrays.stream(clazz.getDeclaredFields()).filter(field -> field.isAnnotationPresent(Encrypt.class)).collect(Collectors.toList());
|
||||
List<Field> fieldList = getFields(clazz);
|
||||
if (CollectionUtils.isNotEmpty(fieldList)) {
|
||||
for (Field field : fieldList) {
|
||||
Field declaredField = data.getClass().getDeclaredField(field.getName());
|
||||
|
|
@ -122,7 +141,7 @@ public class EncryptUtil {
|
|||
return dataList;
|
||||
}
|
||||
try {
|
||||
List<Field> fieldList = Arrays.stream(clazz.getDeclaredFields()).filter(field -> field.isAnnotationPresent(Encrypt.class)).collect(Collectors.toList());
|
||||
List<Field> fieldList = getFields(clazz);
|
||||
if (CollectionUtils.isNotEmpty(fieldList)) {
|
||||
for (T data : dataList) {
|
||||
for (Field field : fieldList) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue