Merge branch 'master' of http://124.222.105.7:3000/dianliang/dl_site_system
# Conflicts: # dl_admin/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiCategoryServiceImpl.java
This commit is contained in:
commit
045ead8de4
@ -47,10 +47,10 @@ public class BusiCategoryServiceImpl extends ServiceImpl<BusiCategoryMapper, Bus
|
|||||||
if(StringUtils.isNotEmpty(category.getCatgType())){
|
if(StringUtils.isNotEmpty(category.getCatgType())){
|
||||||
lambdaQueryWrapper.eq(BusiCategory::getCatgType,category.getCatgType());
|
lambdaQueryWrapper.eq(BusiCategory::getCatgType,category.getCatgType());
|
||||||
}
|
}
|
||||||
lambdaQueryWrapper.orderByDesc(BusiCategory::getSort);
|
|
||||||
if (!StringUtils.isEmpty(category.getCatgName())) {
|
if (!StringUtils.isEmpty(category.getCatgName())) {
|
||||||
lambdaQueryWrapper.like(BusiCategory::getCatgName,category.getCatgName());
|
lambdaQueryWrapper.like(BusiCategory::getCatgName, category.getCatgName());
|
||||||
}
|
}
|
||||||
|
lambdaQueryWrapper.orderByDesc(BusiCategory::getSort);
|
||||||
List<BusiCategory> list = list(lambdaQueryWrapper);
|
List<BusiCategory> list = list(lambdaQueryWrapper);
|
||||||
return buildCategoryTree(list);
|
return buildCategoryTree(list);
|
||||||
}
|
}
|
||||||
@ -62,33 +62,107 @@ public class BusiCategoryServiceImpl extends ServiceImpl<BusiCategoryMapper, Bus
|
|||||||
* @date 14:12 2025/6/30
|
* @date 14:12 2025/6/30
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public void setCategoryAmount(List<ProdNewVO> list,String tenantId) {
|
public void setCategoryAmount(List<ProdNewVO> list, String tenantId) {
|
||||||
Map<String, Integer> idToProdsJunior = new HashMap<>();
|
Map<String, Integer> idToProdsJunior = new HashMap<>();
|
||||||
list.forEach(item -> {
|
list.forEach(item -> {
|
||||||
idToProdsJunior.put(item.getCatgId(),item.getAmount());
|
idToProdsJunior.put(item.getCatgId(), item.getAmount());
|
||||||
});
|
});
|
||||||
//查询全部栏目
|
//查询全部栏目
|
||||||
LambdaQueryWrapper<BusiCategory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<BusiCategory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
lambdaQueryWrapper.eq(DlBaseEntity::getDelFlag,0)
|
lambdaQueryWrapper.eq(DlBaseEntity::getDelFlag, 0)
|
||||||
.eq(BusiCategory::getTenantId,tenantId);
|
.eq(BusiCategory::getTenantId, tenantId);
|
||||||
List<BusiCategory> categoryList = list(lambdaQueryWrapper);
|
List<BusiCategory> categoryList = list(lambdaQueryWrapper);
|
||||||
//遍历赋值
|
//遍历赋值
|
||||||
categoryList.forEach(item->{
|
categoryList.forEach(item -> {
|
||||||
if (idToProdsJunior.containsKey(item.getId())) {
|
if (idToProdsJunior.containsKey(item.getId())) {
|
||||||
item.setProdsJunior(idToProdsJunior.get(item.getId()));
|
item.setProdsJunior(idToProdsJunior.get(item.getId()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
List<BusiCategory> saveResult = computeProdsAll(categoryList);
|
||||||
|
updateBatchById(saveResult);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计每个节点的递归产品数,并返回更新后的列表
|
||||||
|
*
|
||||||
|
* @param categoryList List<BusiCategory>
|
||||||
|
* @return java.util.List<com.ruoyi.busi.domain.BusiCategory>
|
||||||
|
* @author PQZ
|
||||||
|
* @date 15:07 2025/6/30
|
||||||
|
**/
|
||||||
|
private List<BusiCategory> computeProdsAll(List<BusiCategory> categoryList) {
|
||||||
|
if (categoryList == null || categoryList.isEmpty()) {
|
||||||
|
return categoryList;
|
||||||
|
}
|
||||||
|
// 构建id到节点的映射,便于查找
|
||||||
|
Map<String, BusiCategory> idToCategory = new HashMap<>();
|
||||||
|
for (BusiCategory category : categoryList) {
|
||||||
|
idToCategory.put(category.getId(), category);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建树结构(找出根节点)
|
||||||
|
BusiCategory root = null;
|
||||||
|
for (BusiCategory category : categoryList) {
|
||||||
|
if (category.getParentId() == null) {
|
||||||
|
root = category;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 递归统计
|
||||||
|
calculateProdsAll(root, categoryList);
|
||||||
|
return categoryList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归计算子节点数据
|
||||||
|
*
|
||||||
|
* @param node 根节点
|
||||||
|
* @param categories 全部数据
|
||||||
|
* @return java.lang.Integer
|
||||||
|
* @author PQZ
|
||||||
|
* @date 15:24 2025/6/30
|
||||||
|
**/
|
||||||
|
private static Integer calculateProdsAll(BusiCategory node, List<BusiCategory> categories) {
|
||||||
|
if (node == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Integer sum = 0;
|
||||||
|
for (BusiCategory child : getChildren(node, categories)) {
|
||||||
|
sum += calculateProdsAll(child, categories);
|
||||||
|
}
|
||||||
|
Integer currentProdsJunior = (node.getProdsJunior() != null) ? node.getProdsJunior() : 0;
|
||||||
|
node.setProdsAll(sum + currentProdsJunior);
|
||||||
|
;
|
||||||
|
return node.getProdsAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某节点的子节点
|
||||||
|
*
|
||||||
|
* @param parent 父节点
|
||||||
|
* @param categories 所有栏目
|
||||||
|
* @return java.util.List<com.ruoyi.busi.domain.BusiCategory>
|
||||||
|
* @author PQZ
|
||||||
|
* @date 15:24 2025/6/30
|
||||||
|
**/
|
||||||
|
private static List<BusiCategory> getChildren(BusiCategory parent, List<BusiCategory> categories) {
|
||||||
|
List<BusiCategory> children = new ArrayList<>();
|
||||||
|
for (BusiCategory cat : categories) {
|
||||||
|
if (parent.getId().equals(cat.getParentId())) {
|
||||||
|
children.add(cat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成树结构
|
* 生成树结构
|
||||||
* @author PQZ
|
*
|
||||||
* @date 14:11 2025/6/23
|
|
||||||
* @param list 网站栏目列表
|
* @param list 网站栏目列表
|
||||||
* @return java.util.List<com.ruoyi.busi.vo.BusiCategoryVO>
|
* @return java.util.List<com.ruoyi.busi.vo.BusiCategoryVO>
|
||||||
|
* @author PQZ
|
||||||
|
* @date 14:11 2025/6/23
|
||||||
**/
|
**/
|
||||||
private List<BusiCategoryVO> buildCategoryTree(List<BusiCategory> list) {
|
private List<BusiCategoryVO> buildCategoryTree(List<BusiCategory> list) {
|
||||||
// Map存放id到VO的映射
|
// Map存放id到VO的映射
|
||||||
|
Loading…
Reference in New Issue
Block a user