diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java index 7960388e..0a7bc6c5 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java @@ -65,9 +65,9 @@ public class TypeController extends BaseController { } /** - * 根据物资类型ID查询所属下拉列表 + * 根据物资类型ID查询子级下拉列表 --不进行递归穿透 */ - @ApiOperation(value = "根据物资类型ID查询所属下拉列表") + @ApiOperation(value = "根据物资类型ID-查询子级下拉列表") @RequiresPermissions("ma:type:list") @GetMapping("/selectMaTypeListByTypeId") public AjaxResult selectMaTypeListByTypeId(@NotNull(message = "物资类型ID不能为空") Long typeId) { diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java index 875ee3a1..2057fa68 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java @@ -99,10 +99,61 @@ public class TypeServiceImpl implements ITypeService { @Override public List selectTypeListAndParent(Type type) { // 如果是顶级节点,则查询所有子节点 - if (type != null && "0".equals(type.getLevel())) { + if (type != null && type.getLevel() != null && "0".equals(type.getLevel())) { type.setLevel(null); } - return typeMapper.selectTypeListAndParent(type); + + // 拿到数据要处理一下上级信息 + List maTypeListVos; + try { + maTypeListVos = typeMapper.selectTypeListAndParent(type); + } catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + + // 检查Mapper集合 + if (maTypeListVos == null || maTypeListVos.isEmpty()) { + return new ArrayList<>(); + } + + + for (MaTypeListVo maTypeListVo : maTypeListVos) { + // ------------ 检查 ----------- + + // object对象是空的,忽略处理 + if (maTypeListVo == null) { + continue; + } + // 没有上级就不需要处理,或者level等级不清晰的也不进行处理 + if (maTypeListVo.getParentId() == null || maTypeListVo.getLevel() == null) { + continue; + } + // 1级节点已经是顶级,无上级,所以不需要处理 + if ("1".equals(maTypeListVo.getLevel())) { + continue; + } + // ------------ 检查结束 ----------- + + + // 进行数据处理 + switch (maTypeListVo.getLevel()) { + case "2": + // 二级节点父级是一级节点,所以要拿到父节点名称,并赋值至ONE_LEVEL_NAME字段 + maTypeListVo.setParentOneLevelName(maTypeListVo.getParentThreeLevelName() == null ? "" : maTypeListVo.getParentThreeLevelName()); + break; + case "3": + // 三级节点父级是二级节点和一级节点, 要把祖父类型名称放入一级字段,把父类型名称存入二级字段 + maTypeListVo.setParentOneLevelName(maTypeListVo.getParentTwoLevelName() == null ? "" : maTypeListVo.getParentTwoLevelName()); + maTypeListVo.setParentTwoLevelName(maTypeListVo.getParentThreeLevelName() == null ? "" : maTypeListVo.getParentThreeLevelName()); + break; + case "4": + // 四级节点父级是三级节点和二级节点和一级节点, 要把祖父类型名称放入一级字段,把父类型名称存入二级字段,子类型名称存入三级字段 + // 但因为4级节点内循环3次,已按顺序处理,所以此处无需处理 + break; + } + + } + return maTypeListVos; } /** diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml index ea79b697..be58065a 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml @@ -251,6 +251,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" SELECT a.*, -- 当前层级的所有字段 b.type_name AS parentThreeLevelName, -- 父层级名称 + c.type_name AS parentTwoLevelName, -- 祖父层级名称 d.type_name AS parentOneLevelName -- 曾祖父层级名称 FROM @@ -288,17 +289,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select wh_house_set.type_id AS typeId, - mt.type_name AS typeName, - mt.parent_id AS parentId, - mt.level + mt.type_name AS typeName,mt.parent_id AS parentId,mt.level from wh_house_set - left join ma_type mt on wh_house_set.type_id = mt.type_id + left join + ma_type mt on wh_house_set.type_id = mt.type_id where wh_house_set.house_id = #{mouseId} and wh_house_set.del_flag = 0