diff --git a/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/evaluation/AeIndicatorController.java b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/evaluation/AeIndicatorController.java index 2920b3e..a51c440 100644 --- a/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/evaluation/AeIndicatorController.java +++ b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/evaluation/AeIndicatorController.java @@ -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)); + } } diff --git a/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/model/domain/AeIndicatorEntity.java b/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/model/domain/AeIndicatorEntity.java index 7b1df23..d41cfaa 100644 --- a/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/model/domain/AeIndicatorEntity.java +++ b/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/model/domain/AeIndicatorEntity.java @@ -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 children; } diff --git a/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/service/AeIndicatorService.java b/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/service/AeIndicatorService.java index 4cf0f41..43f32b6 100644 --- a/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/service/AeIndicatorService.java +++ b/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/service/AeIndicatorService.java @@ -17,4 +17,6 @@ public interface AeIndicatorService extends IService { boolean removeIndicator(Long id); boolean updateIndicator(AeIndicatorUpdateDTO dto); + + List getChildrenByParentIdWithLevelLimit(Long parentId, Integer maxLevel, Integer type); } diff --git a/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/service/impl/AeIndicatorServiceImpl.java b/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/service/impl/AeIndicatorServiceImpl.java index 06e17dd..b1c3d75 100644 --- a/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/service/impl/AeIndicatorServiceImpl.java +++ b/cmvr-iot-evaluation/src/main/java/com/cmvr/evaluation/service/impl/AeIndicatorServiceImpl.java @@ -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 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 buildTree(Long parentId, Integer currentLevel, Integer maxLevel, Integer type) { + // 3. 构建Lambda查询条件:类型过滤+父ID匹配+逻辑删除过滤+按sort降序 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(AeIndicatorEntity::getParentId, parentId) // 匹配当前父ID + .eq(AeIndicatorEntity::getType, type); // 过滤指标类型 + + // 4. 查询当前父ID下的直接子节点 + List childNodes = this.list(queryWrapper); + if (CollectionUtils.isEmpty(childNodes)) { + return new ArrayList<>(); // 无直接子节点,返回空列表,递归终止 + } + + // 5. 遍历子节点,递归构建子节点的children(层级未达最大值时才递归) + for (AeIndicatorEntity node : childNodes) { + // 核心:判断当前节点层级是否小于最大层级,未达则继续递归查询子节点的子节点 + if (currentLevel < maxLevel) { + // 递归:当前节点作为父ID,层级+1,继续构建子树 + List grandChildren = buildTree(node.getId(), currentLevel + 1, maxLevel, type); + node.setChildren(grandChildren); // 给当前节点设置子节点列表 + } else { + node.setChildren(new ArrayList<>()); // 达到最大层级,子节点置空,停止递归 + } + } + + // 6. 返回当前层级的带children的节点列表 + return childNodes; + } + } diff --git a/cmvr-iot-vi/src/main/java/com/cmvr/vi/model/domain/ViProject.java b/cmvr-iot-vi/src/main/java/com/cmvr/vi/model/domain/ViProject.java index d8e74f7..c8b67ce 100644 --- a/cmvr-iot-vi/src/main/java/com/cmvr/vi/model/domain/ViProject.java +++ b/cmvr-iot-vi/src/main/java/com/cmvr/vi/model/domain/ViProject.java @@ -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;