diff --git a/dl_admin/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiCategoryServiceImpl.java b/dl_admin/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiCategoryServiceImpl.java index 776a40b..4a557b1 100644 --- a/dl_admin/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiCategoryServiceImpl.java +++ b/dl_admin/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiCategoryServiceImpl.java @@ -40,20 +40,18 @@ public class BusiCategoryServiceImpl extends ServiceImpl treeCategory(BusiCategory category) { //查询全部栏目 LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(DlBaseEntity::getDelFlag,0) - .eq(BusiCategory::getTenantId,category.getTenantId()); - if(StringUtils.isNotEmpty(category.getCatgType())){ - lambdaQueryWrapper.eq(BusiCategory::getCatgType,category.getCatgType()); + lambdaQueryWrapper.eq(DlBaseEntity::getDelFlag, 0) + .eq(BusiCategory::getTenantId, category.getTenantId()); + if (StringUtils.isNotEmpty(category.getCatgType())) { + lambdaQueryWrapper.eq(BusiCategory::getCatgType, category.getCatgType()); } if (!StringUtils.isEmpty(category.getCatgName())) { lambdaQueryWrapper.like(BusiCategory::getCatgName, category.getCatgName()); } - lambdaQueryWrapper.orderByAsc(BusiCategory::getSort); + lambdaQueryWrapper.orderByDesc(BusiCategory::getSort); List list = list(lambdaQueryWrapper); List rtnList = buildCategoryTree(list); - return rtnList.stream().sorted(Comparator.comparing(BusiCategoryVO::getSort, - Comparator.nullsLast(Comparator.reverseOrder()))) - .collect(Collectors.toList()); + return rtnList; } /** @@ -152,12 +150,10 @@ public class BusiCategoryServiceImpl extends ServiceImpl - * @author PQZ - * @date 14:11 2025/6/23 **/ private List buildCategoryTree(List list) { // Map存放id到VO的映射 @@ -165,7 +161,7 @@ public class BusiCategoryServiceImpl extends ServiceImpl nodes) { + if (nodes == null || nodes.isEmpty()) { + return; + } + + // 对当前层级节点排序 + nodes.sort(Comparator.comparing(BusiCategoryVO::getSort, + Comparator.nullsLast(Comparator.reverseOrder()))); + + // 递归对子节点排序 + for (BusiCategoryVO node : nodes) { + if (node.getChildren() != null && !node.getChildren().isEmpty()) { + sortTreeNodes(node.getChildren()); + } + } + } + + /** * @param id 查询的栏目ID * @return java.util.List @@ -207,54 +230,55 @@ public class BusiCategoryServiceImpl extends ServiceImpl dealFirstId(List busiCategoryVOList) { - busiCategoryVOList.forEach(item->{ + busiCategoryVOList.forEach(item -> { String thisMaxParentId = item.getId(); item.setMaxParentId(thisMaxParentId); - if(null!=item.getChildren() && !item.getChildren().isEmpty()){ + if (null != item.getChildren() && !item.getChildren().isEmpty()) { //有子级 - this.setChildMaxParentId(item.getChildren(),thisMaxParentId); + this.setChildMaxParentId(item.getChildren(), thisMaxParentId); } }); return busiCategoryVOList; } - private void setChildMaxParentId(List childList,String maxParentId){ - childList.forEach(item->{ + private void setChildMaxParentId(List childList, String maxParentId) { + childList.forEach(item -> { item.setMaxParentId(maxParentId); - if(null!=item.getChildren()&& !item.getChildren().isEmpty()){ - this.setChildMaxParentId(item.getChildren(),maxParentId); + if (null != item.getChildren() && !item.getChildren().isEmpty()) { + this.setChildMaxParentId(item.getChildren(), maxParentId); } }); } /** * 给所有子级设置最父级ID并且反回map格式 - * @author vinjor-M - * @date 11:23 2025/7/19 + * * @param busiCategoryVOList 栏目树 * @return java.util.List + * @author vinjor-M + * @date 11:23 2025/7/19 **/ @Override - public Map dealFirstIdRtnMap(List busiCategoryVOList){ - Map rtnMap = new HashMap<>(); - busiCategoryVOList.forEach(item->{ + public Map dealFirstIdRtnMap(List busiCategoryVOList) { + Map rtnMap = new HashMap<>(); + busiCategoryVOList.forEach(item -> { String thisMaxParentId = item.getId(); item.setMaxParentId(thisMaxParentId); - rtnMap.put(item.getId(),thisMaxParentId); - if(null!=item.getChildren() && !item.getChildren().isEmpty()){ + rtnMap.put(item.getId(), thisMaxParentId); + if (null != item.getChildren() && !item.getChildren().isEmpty()) { //有子级 - this.setChildMaxParentIdMap(item.getChildren(),thisMaxParentId,rtnMap); + this.setChildMaxParentIdMap(item.getChildren(), thisMaxParentId, rtnMap); } }); return rtnMap; } - private void setChildMaxParentIdMap(List childList,String maxParentId,Map rtnMap){ - childList.forEach(item->{ + private void setChildMaxParentIdMap(List childList, String maxParentId, Map rtnMap) { + childList.forEach(item -> { item.setMaxParentId(maxParentId); - rtnMap.put(item.getId(),maxParentId); - if(null!=item.getChildren()&& !item.getChildren().isEmpty()){ - this.setChildMaxParentIdMap(item.getChildren(),maxParentId,rtnMap); + rtnMap.put(item.getId(), maxParentId); + if (null != item.getChildren() && !item.getChildren().isEmpty()) { + this.setChildMaxParentIdMap(item.getChildren(), maxParentId, rtnMap); } }); } diff --git a/dl_admin/ruoyi-admin/src/main/resources/mapper/busi/BusiKeywordMapper.xml b/dl_admin/ruoyi-admin/src/main/resources/mapper/busi/BusiKeywordMapper.xml index ce8e748..9a110e6 100644 --- a/dl_admin/ruoyi-admin/src/main/resources/mapper/busi/BusiKeywordMapper.xml +++ b/dl_admin/ruoyi-admin/src/main/resources/mapper/busi/BusiKeywordMapper.xml @@ -13,7 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select id, tenant_id from dl_busi_keyword - DELETE dl_busi_keyword WHERE id =#{id} AND tenant_id=#{tenantId} + DELETE FROM dl_busi_keyword WHERE id =#{id} AND tenant_id=#{tenantId}