1
This commit is contained in:
parent
95415e84d2
commit
33de2cbc7b
@ -40,20 +40,18 @@ public class BusiCategoryServiceImpl extends ServiceImpl<BusiCategoryMapper, Bus
|
||||
public List<BusiCategoryVO> treeCategory(BusiCategory category) {
|
||||
//查询全部栏目
|
||||
LambdaQueryWrapper<BusiCategory> 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<BusiCategory> list = list(lambdaQueryWrapper);
|
||||
List<BusiCategoryVO> 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<BusiCategoryMapper, Bus
|
||||
|
||||
|
||||
/**
|
||||
* 生成树结构
|
||||
* 生成树结构(修改版)
|
||||
*
|
||||
* @param list 网站栏目列表
|
||||
* @return java.util.List<com.ruoyi.busi.vo.BusiCategoryVO>
|
||||
* @author PQZ
|
||||
* @date 14:11 2025/6/23
|
||||
**/
|
||||
private List<BusiCategoryVO> buildCategoryTree(List<BusiCategory> list) {
|
||||
// Map存放id到VO的映射
|
||||
@ -165,7 +161,7 @@ public class BusiCategoryServiceImpl extends ServiceImpl<BusiCategoryMapper, Bus
|
||||
// 先将所有节点转换为VO,并放入Map
|
||||
for (BusiCategory category : list) {
|
||||
BusiCategoryVO vo = new BusiCategoryVO();
|
||||
BeanUtils.copyProperties(category,vo);
|
||||
BeanUtils.copyProperties(category, vo);
|
||||
vo.setId(category.getId());
|
||||
vo.setLabel(category.getCatgName());
|
||||
idToNodeMap.put(vo.getId(), vo);
|
||||
@ -183,9 +179,36 @@ public class BusiCategoryServiceImpl extends ServiceImpl<BusiCategoryMapper, Bus
|
||||
parent.getChildren().add(node);
|
||||
}
|
||||
}
|
||||
|
||||
// 对所有层级节点进行排序
|
||||
sortTreeNodes(roots);
|
||||
|
||||
return roots;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归对树节点进行排序
|
||||
*
|
||||
* @param nodes 节点列表
|
||||
*/
|
||||
private void sortTreeNodes(List<BusiCategoryVO> 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<java.lang.String>
|
||||
@ -207,54 +230,55 @@ public class BusiCategoryServiceImpl extends ServiceImpl<BusiCategoryMapper, Bus
|
||||
**/
|
||||
@Override
|
||||
public List<BusiCategoryVO> dealFirstId(List<BusiCategoryVO> 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<BusiCategoryVO> childList,String maxParentId){
|
||||
childList.forEach(item->{
|
||||
private void setChildMaxParentId(List<BusiCategoryVO> 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<com.ruoyi.busi.vo.BusiCategoryVO>
|
||||
* @author vinjor-M
|
||||
* @date 11:23 2025/7/19
|
||||
**/
|
||||
@Override
|
||||
public Map<String,String> dealFirstIdRtnMap(List<BusiCategoryVO> busiCategoryVOList){
|
||||
Map<String,String> rtnMap = new HashMap<>();
|
||||
busiCategoryVOList.forEach(item->{
|
||||
public Map<String, String> dealFirstIdRtnMap(List<BusiCategoryVO> busiCategoryVOList) {
|
||||
Map<String, String> 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<BusiCategoryVO> childList,String maxParentId,Map<String,String> rtnMap){
|
||||
childList.forEach(item->{
|
||||
private void setChildMaxParentIdMap(List<BusiCategoryVO> childList, String maxParentId, Map<String, String> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
select id, tenant_id from dl_busi_keyword
|
||||
</sql>
|
||||
<delete id="deleteByIdAndTenantId">
|
||||
DELETE dl_busi_keyword WHERE id =#{id} AND tenant_id=#{tenantId}
|
||||
DELETE FROM dl_busi_keyword WHERE id =#{id} AND tenant_id=#{tenantId}
|
||||
</delete>
|
||||
|
||||
<select id="queryListPage" parameterType="BusiKeyword" resultMap="BusiKeywordResult">
|
||||
|
Loading…
Reference in New Issue
Block a user