update 优化 将logininfor规范化为loginInfo

update 优化 规范DTO命名
add 新增注解类工具
update 优化 使用动态规划优化菜单树的构建
update 更新 统一枚举相关包名为enums
This commit is contained in:
疯狂的狮子Li
2026-03-19 12:03:58 +08:00
parent 6a8ca4a74d
commit e8fc7fb0df
55 changed files with 439 additions and 402 deletions

View File

@@ -10,8 +10,9 @@ import lombok.NoArgsConstructor;
import org.dromara.common.core.utils.reflect.ReflectUtils;
import java.util.List;
import java.util.Objects;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -29,6 +30,23 @@ public class TreeBuildUtils extends TreeUtil {
*/
public static final TreeNodeConfig DEFAULT_CONFIG = TreeNodeConfig.DEFAULT_CONFIG.setNameKey("label");
/**
* 使用动态规划构建树形结构
*
* @param items 节点列表项
* @param parentId 父节点ID
* @param classifier 动态规划表分类函数
* @param action 回溯动作
* @param <K> 节点ID的类型
* @param <T> 输入节点的类型
* @return 构建好的树形结构列表
*/
public static <K, T> List<T> build(List<T> items, K parentId, Function<T, K> classifier, BiConsumer<T, Map<K, List<T>>> action) {
Map<K, List<T>> nodeTreeMaps = items.stream().collect(Collectors.groupingBy(classifier));
items.forEach(item -> action.accept(item, nodeTreeMaps));
return nodeTreeMaps.get(parentId);
}
/**
* 构建树形结构
*
@@ -79,17 +97,8 @@ public class TreeBuildUtils extends TreeUtil {
return CollUtil.newArrayList();
}
// 提取所有节点 ID用于后续判断哪些节点为根节点即 parentId 不在其中)
Set<K> allIds = StreamUtils.toSet(list, getId);
// 筛选出所有 parentId 不在 allIds 中的节点,这些节点的 parentId 可认为是根节点
Set<K> rootParentIds = list.stream()
.map(getParentId)
.filter(Objects::nonNull)
.filter(pid -> !allIds.contains(pid))
.collect(Collectors.toSet());
// 使用流处理,遍历每个顶级 parentId构建对应树并合并为一个列表返回
Set<K> rootParentIds = StreamUtils.toSet(list, getParentId);
rootParentIds.removeAll(StreamUtils.toSet(list, getId));
return rootParentIds.stream()
.flatMap(rootParentId -> TreeUtil.build(list, rootParentId, parser).stream())
.collect(Collectors.toList());

View File

@@ -0,0 +1,59 @@
package org.dromara.common.core.utils.reflect;
import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.lang.Dict;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.Map;
/**
* 注解工具类
*
* @author 秋辞未寒
*/
@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AnnotationUtils extends AnnotationUtil {
/**
* 获取指定注解
*
* @param annotationEle {@link AnnotatedElement}可以是Class、Method、Field、Constructor、ReflectPermission
* @param annotationTypeName 注解类型名称
* @return 注解对象
*/
@SuppressWarnings("unchecked")
public static Annotation getAnnotation(AnnotatedElement annotationEle, String annotationTypeName) {
try {
return AnnotationUtil.getAnnotation(annotationEle, (Class<? extends Annotation>) Class.forName(annotationTypeName));
} catch (final ClassNotFoundException | ClassCastException e) {
log.error("AnnotationUtils.getAnnotation(AnnotatedElement, String) error.", e);
return null;
}
}
/**
* 获取指定注解中所有属性值
*
* @param annotationEle {@link AnnotatedElement}可以是Class、Method、Field、Constructor、ReflectPermission
* @param annotationTypeName 注解类型名称
* @return 注解对象所有属性键值
* @throws UtilException 调用注解中的方法时执行异常
*/
@SuppressWarnings("unchecked")
public static Dict getAnnotationValueMap(AnnotatedElement annotationEle, String annotationTypeName) throws UtilException {
try {
Map<String, Object> annotationValueMap = AnnotationUtil.getAnnotationValueMap(annotationEle, (Class<? extends Annotation>) Class.forName(annotationTypeName));
return new Dict(annotationValueMap);
} catch (final ClassNotFoundException | ClassCastException e) {
log.error("AnnotationUtils.getAnnotationValueMap(AnnotatedElement, String) error.", e);
return null;
}
}
}

View File

@@ -1,4 +1,4 @@
package org.dromara.common.core.validate.enumd;
package org.dromara.common.core.validate.enums;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

View File

@@ -1,4 +1,4 @@
package org.dromara.common.core.validate.enumd;
package org.dromara.common.core.validate.enums;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;