类型树问题

This commit is contained in:
sxu 2024-10-28 16:19:53 +08:00
parent 0f7dfd949c
commit 30d96d8cad
2 changed files with 29 additions and 11 deletions

View File

@ -16,6 +16,9 @@ public class MaterialConstants {
*/
public static final String UTF8 = "UTF-8";
// 树的根节点ID
public static final Long TREE_ROOT_ID = 0L;
/**
* 领料任务类型
*/

View File

@ -348,18 +348,33 @@ public class TypeServiceImpl implements ITypeService {
}
// 3.遍历所有配置关联
for (WhHouseSet whHouseSet : whHouseSets) {
// --- 数据校验 ----
// for (WhHouseSet whHouseSet : whHouseSets) {
// // --- 数据校验 ----
// if (whHouseSet == null || whHouseSet.getTypeId() == null) { continue; }
// // 构造函数定义0级Tree对象
// TreeSelect thisTree = new TreeSelect(whHouseSet.getHouseId(),whHouseSet.getHouseName(),0,null);
// // 从Map中直接获取对应的1级节点
// TreeSelect oneLevelTree = maTypeMap.get(whHouseSet.getTypeId());
// // 转换为集合存入0级Tree对象中
// thisTree.setChildren(oneLevelTree != null ? Collections.singletonList(oneLevelTree) : null);
// // 最后把0级Tree对象存入Result结果集合返回给前端
// treeSelectResultList.add(thisTree);
// }
// 3.遍历所有配置关联
Map<Long, List<WhHouseSet>> groupedById = whHouseSets.stream().collect(Collectors.groupingBy(WhHouseSet::getHouseId));
groupedById.forEach((id, itemList) -> {
TreeSelect thisTree = new TreeSelect(itemList.get(0).getHouseId(),itemList.get(0).getHouseName(),0,null);
List<TreeSelect> children = new ArrayList<>();
for (WhHouseSet whHouseSet : itemList) {
if (whHouseSet == null || whHouseSet.getTypeId() == null) { continue; }
// 构造函数定义0级Tree对象
TreeSelect thisTree = new TreeSelect(whHouseSet.getHouseId(),whHouseSet.getHouseName(),0,null);
// 从Map中直接获取对应的1级节点
TreeSelect oneLevelTree = maTypeMap.get(whHouseSet.getTypeId());
// 转换为集合存入0级Tree对象中
thisTree.setChildren(oneLevelTree != null ? Collections.singletonList(oneLevelTree) : null);
// 最后把0级Tree对象存入Result结果集合返回给前端
treeSelectResultList.add(thisTree);
children.add(oneLevelTree != null ? oneLevelTree : null);
}
thisTree.setChildren(children);
treeSelectResultList.add(thisTree);
});
return AjaxResult.success(treeSelectResultList);
}