diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/config/SwaggerConfiguration.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/config/SwaggerConfiguration.java index 7ae747fa4..c972b97ff 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/config/SwaggerConfiguration.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/config/SwaggerConfiguration.java @@ -21,8 +21,7 @@ import java.util.List; /** * @Author haoxr - * @Date 2021-02-25 15:36 - * @Version 1.0.0 + * @Date 2021/02/25 */ @Configuration @EnableSwagger2WebMvc diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/config/PasswordEncoderConfig.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/config/PasswordEncoderConfig.java index 581ef1366..48b75c585 100644 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/config/PasswordEncoderConfig.java +++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/config/PasswordEncoderConfig.java @@ -7,6 +7,9 @@ import org.springframework.security.crypto.password.PasswordEncoder; /** * 密码编码器 + * + * @author haoxr + * @date 2022/10/21 */ @Configuration public class PasswordEncoderConfig { diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/config/SwaggerConfiguration.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/config/SwaggerConfiguration.java index 3f58f72e7..a4bf56c09 100644 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/config/SwaggerConfiguration.java +++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/config/SwaggerConfiguration.java @@ -61,8 +61,6 @@ public class SwaggerConfiguration { List securityContexts = Lists.newArrayList(securityContext); return new Docket(DocumentationType.SWAGGER_2) .select() - // .apis(RequestHandlerSelectors.basePackage("com.youlai.admin.controller")) - // .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .apis(RequestHandlerSelectors.withClassAnnotation(Api.class)) .paths(PathSelectors.any()) .build() diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/converter/DeptConverter.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/converter/DeptConverter.java index 6530ca2eb..923bd82ff 100644 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/converter/DeptConverter.java +++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/converter/DeptConverter.java @@ -3,6 +3,7 @@ package com.youlai.admin.converter; import com.youlai.admin.pojo.entity.SysDept; import com.youlai.admin.pojo.form.DeptForm; import com.youlai.admin.pojo.vo.dept.DeptDetailVO; +import com.youlai.admin.pojo.vo.dept.DeptVO; import org.mapstruct.Mapper; /** @@ -14,6 +15,8 @@ import org.mapstruct.Mapper; @Mapper(componentModel = "spring") public interface DeptConverter { + DeptVO entity2Vo(SysDept entity); + DeptDetailVO entity2DetailVO(SysDept entity); SysDept form2Entity(DeptForm deptForm); diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/impl/SysDeptServiceImpl.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/impl/SysDeptServiceImpl.java index e28e2f5ec..af834db25 100644 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/impl/SysDeptServiceImpl.java +++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/impl/SysDeptServiceImpl.java @@ -2,7 +2,6 @@ package com.youlai.admin.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Validator; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -19,7 +18,6 @@ import com.youlai.common.constant.GlobalConstants; import com.youlai.common.constant.SystemConstants; import com.youlai.common.web.domain.Option; import lombok.RequiredArgsConstructor; -import org.apache.logging.log4j.util.Strings; import org.springframework.stereotype.Service; import java.util.*; @@ -54,62 +52,56 @@ public class SysDeptServiceImpl extends ServiceImpl impl .eq(Validator.isNotNull(status), SysDept::getStatus, status) .orderByAsc(SysDept::getSort) ); - return recurDepartments(deptList); - } - /** - * 递归生成部门表格层级列表 - * - * @param deptList 部门列表 - * @return 部门列表 - */ - private static List recurDepartments(List deptList) { - List deptTableList = new ArrayList<>(); - // 保存所有节点的 id - Set nodeIdSet = deptList.stream() - .map(SysDept::getId) - .collect(Collectors.toSet()); - for (SysDept sysDept : deptList) { - // 不在节点 id 集合中存在的 id 即为顶级节点 id, 递归生成列表 - Long parentId = sysDept.getParentId(); - if (!nodeIdSet.contains(parentId)) { - deptTableList.addAll(recurTableDepts(parentId, deptList)); - nodeIdSet.add(parentId); + List list = new ArrayList<>(); + + if (CollectionUtil.isNotEmpty(deptList)) { + + Set cacheDeptIds = deptList.stream() + .map(SysDept::getId) + .collect(Collectors.toSet()); + + + for (SysDept dept : deptList) { + Long parentId = dept.getParentId(); + // 不在缓存ID列表的parentId是顶级节点ID,以此作为递归开始 + if (cacheDeptIds.contains(parentId) == false) { + list.addAll(recurDepartments(parentId, deptList)); + cacheDeptIds.add(parentId); // 避免重复递归 + } } } - // 如果结果列表为空说明所有的节点都是独立分散的, 直接转换后返回 - if (deptTableList.isEmpty()) { - return deptList.stream() - .map(item -> { + + // 列表为空说明所有的节点都是独立的 + if (list.isEmpty()) { + return deptList.stream().map(item -> { DeptVO deptVO = new DeptVO(); BeanUtil.copyProperties(item, deptVO); return deptVO; }) .collect(Collectors.toList()); } - return deptTableList; + + return list; } /** - * 递归生成部门表格层级列表 + * 递归生成部门层级列表 * * @param parentId * @param deptList * @return */ - public static List recurTableDepts(Long parentId, List deptList) { - List deptTableList = new ArrayList<>(); - Optional.ofNullable(deptList).orElse(new ArrayList<>()) - .stream() + public List recurDepartments(Long parentId, List deptList) { + List list = deptList.stream() .filter(dept -> dept.getParentId().equals(parentId)) - .forEach(dept -> { - DeptVO deptVO = new DeptVO(); - BeanUtil.copyProperties(dept, deptVO); - List children = recurTableDepts(dept.getId(), deptList); + .map(dept -> { + DeptVO deptVO = deptConverter.entity2Vo(dept); + List children = recurDepartments(dept.getId(), deptList); deptVO.setChildren(children); - deptTableList.add(deptVO); - }); - return deptTableList; + return deptVO; + }).collect(Collectors.toList()); + return list; } @@ -217,7 +209,6 @@ public class SysDeptServiceImpl extends ServiceImpl impl SysDept::getParentId, SysDept::getStatus, SysDept::getSort - )); DeptDetailVO detailVO = deptConverter.entity2DetailVO(entity);