Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
stream 2026-02-04 10:01:43 +08:00
commit f74454888d
5 changed files with 76 additions and 0 deletions

View File

@ -50,4 +50,10 @@ public class AeIndicatorController extends BaseController {
public AjaxResult updateIndicator(@Valid @RequestBody AeIndicatorUpdateDTO updateDTO) {
return toAjax(indicatorService.updateIndicator(updateDTO));
}
@ApiOperation("获取指定parentId下指定level层级的指标")
@GetMapping("/getChildrenByParentIdWithLevelLimit")
public AjaxResult getChildrenByParentIdWithLevelLimit(@RequestParam Long parentId, @RequestParam Integer maxLevel, @RequestParam Integer type) {
return success(indicatorService.getChildrenByParentIdWithLevelLimit(parentId, maxLevel, type));
}
}

View File

@ -1,6 +1,7 @@
package com.cmvr.evaluation.model.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cmvr.common.core.domain.BaseEntity;
@ -10,6 +11,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
@ -51,4 +53,8 @@ public class AeIndicatorEntity extends BaseEntity {
@ApiModelProperty("类型 0-语音 1-触控")
private Integer type;
@ApiModelProperty("子指标列表")
@TableField(exist = false) // 关键标注该字段不是数据库列避免MP映射报错
private List<AeIndicatorEntity> children;
}

View File

@ -17,4 +17,6 @@ public interface AeIndicatorService extends IService<AeIndicatorEntity> {
boolean removeIndicator(Long id);
boolean updateIndicator(AeIndicatorUpdateDTO dto);
List<AeIndicatorEntity> getChildrenByParentIdWithLevelLimit(Long parentId, Integer maxLevel, Integer type);
}

View File

@ -1,6 +1,7 @@
package com.cmvr.evaluation.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cmvr.evaluation.mapper.AeIndicatorMapper;
@ -15,7 +16,10 @@ import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
@ -102,6 +106,23 @@ public class AeIndicatorServiceImpl extends ServiceImpl<AeIndicatorMapper, AeInd
return saveResult;
}
@Override
public List<AeIndicatorEntity> getChildrenByParentIdWithLevelLimit(Long parentId, Integer maxLevel, Integer type) {
// 1. 参数校验与默认值处理避免空指针适配业务默认规则
if (parentId == null) {
parentId = 0L; // 默认查父ID为0的根节点一级指标
}
if (maxLevel == null || maxLevel < 1) {
maxLevel = 3; // 默认最大层级为3贴合三级指标业务
}
if (type == null) {
return new ArrayList<>(); // 类型为null时无数据可查返回空列表
}
Integer currentLevel = 1;
return buildTree(parentId, currentLevel, maxLevel, type);
}
/**
* 私有工具方法递归查询指定ID的所有后代指标ID重孙无限级
* @param parentId /祖指标ID
@ -194,4 +215,41 @@ public class AeIndicatorServiceImpl extends ServiceImpl<AeIndicatorMapper, AeInd
return entity;
}
/**
* 私有递归辅助方法核心构建树形结构实现层级限制
* @param parentId 当前父节点ID
* @param currentLevel 当前要构建的节点层级
* @param maxLevel 允许的最大层级达到则停止递归
* @param type 指标类型 0-语音 1-触控
* @return 带children的树形节点列表
*/
private List<AeIndicatorEntity> buildTree(Long parentId, Integer currentLevel, Integer maxLevel, Integer type) {
// 3. 构建Lambda查询条件类型过滤+父ID匹配+逻辑删除过滤+按sort降序
LambdaQueryWrapper<AeIndicatorEntity> queryWrapper = new LambdaQueryWrapper<AeIndicatorEntity>()
.eq(AeIndicatorEntity::getParentId, parentId) // 匹配当前父ID
.eq(AeIndicatorEntity::getType, type); // 过滤指标类型
// 4. 查询当前父ID下的直接子节点
List<AeIndicatorEntity> childNodes = this.list(queryWrapper);
if (CollectionUtils.isEmpty(childNodes)) {
return new ArrayList<>(); // 无直接子节点返回空列表递归终止
}
// 5. 遍历子节点递归构建子节点的children层级未达最大值时才递归
for (AeIndicatorEntity node : childNodes) {
// 核心判断当前节点层级是否小于最大层级未达则继续递归查询子节点的子节点
if (currentLevel < maxLevel) {
// 递归当前节点作为父ID层级+1继续构建子树
List<AeIndicatorEntity> grandChildren = buildTree(node.getId(), currentLevel + 1, maxLevel, type);
node.setChildren(grandChildren); // 给当前节点设置子节点列表
} else {
node.setChildren(new ArrayList<>()); // 达到最大层级子节点置空停止递归
}
}
// 6. 返回当前层级的带children的节点列表
return childNodes;
}
}

View File

@ -38,6 +38,10 @@ public class ViProject extends BaseEntity {
@ApiModelProperty("计划测试结束时间")
private Date planEnd;
@Excel(name = "评价指标")
@ApiModelProperty("评价指标")
private Long indicatorId;
@Excel(name = "项目描述")
@ApiModelProperty("项目描述")
private String description;