web端-新增风采墙模块(工会信息传播与文化展示): 修复栏目管理下级栏目无法打开等问题;
This commit is contained in:
+14
-11
@@ -36,7 +36,9 @@ public class SpreadCategoryServiceImpl extends BaseServiceImpl<SpreadCategory> i
|
||||
public List<NutMap> categoryTree(boolean visibleOnly) {
|
||||
List<SpreadCategory> categories = listCategories(visibleOnly);
|
||||
Map<String, NutMap> nodeMap = new LinkedHashMap<>();
|
||||
Map<String, List<NutMap>> childrenMap = new LinkedHashMap<>();
|
||||
for (SpreadCategory category : categories) {
|
||||
List<NutMap> children = new ArrayList<>();
|
||||
nodeMap.put(category.getId(), NutMap.NEW()
|
||||
.addv("id", category.getId())
|
||||
.addv("parentId", category.getParentId())
|
||||
@@ -45,7 +47,8 @@ public class SpreadCategoryServiceImpl extends BaseServiceImpl<SpreadCategory> i
|
||||
.addv("sortOrder", category.getSortOrder())
|
||||
.addv("visible", category.getVisible())
|
||||
.addv("slider", category.getSlider())
|
||||
.addv("children", new ArrayList<>()));
|
||||
.addv("children", children));
|
||||
childrenMap.put(category.getId(), children);
|
||||
}
|
||||
List<NutMap> roots = new ArrayList<>();
|
||||
for (NutMap node : nodeMap.values()) {
|
||||
@@ -53,9 +56,16 @@ public class SpreadCategoryServiceImpl extends BaseServiceImpl<SpreadCategory> i
|
||||
if ("0".equals(parentId) || !nodeMap.containsKey(parentId)) {
|
||||
roots.add(node);
|
||||
} else {
|
||||
nodeMap.get(parentId).getList("children", NutMap.class).add(node);
|
||||
// 直接向节点持有的原始集合追加,避免 NutMap 类型转换后子节点没有写回。
|
||||
childrenMap.get(parentId).add(node);
|
||||
}
|
||||
}
|
||||
// 叶子栏目不返回空 children,避免级联选择器误判为仍有下一级。
|
||||
nodeMap.forEach((id, node) -> {
|
||||
if (childrenMap.get(id).isEmpty()) {
|
||||
node.remove("children");
|
||||
}
|
||||
});
|
||||
return roots;
|
||||
}
|
||||
|
||||
@@ -125,11 +135,9 @@ public class SpreadCategoryServiceImpl extends BaseServiceImpl<SpreadCategory> i
|
||||
if (category == null || StrUtil.isBlank(category.getName())) {
|
||||
throw new RuntimeException("栏目名称不能为空");
|
||||
}
|
||||
if (StrUtil.isBlank(category.getCode())) {
|
||||
throw new RuntimeException("栏目编码不能为空");
|
||||
}
|
||||
category.setName(category.getName().trim());
|
||||
category.setCode(category.getCode().trim());
|
||||
// 参考模块不要求用户维护栏目编码,空值统一保存为 NULL。
|
||||
category.setCode(StrUtil.isBlank(category.getCode()) ? null : category.getCode().trim());
|
||||
category.setParentId(StrUtil.blankToDefault(category.getParentId(), "0"));
|
||||
if (category.getId() != null && category.getId().equals(category.getParentId())) {
|
||||
throw new RuntimeException("上级栏目不能选择自身");
|
||||
@@ -146,17 +154,12 @@ public class SpreadCategoryServiceImpl extends BaseServiceImpl<SpreadCategory> i
|
||||
Cnd nameCnd = Cnd.where("name", "=", category.getName())
|
||||
.and("parentId", "=", category.getParentId())
|
||||
.and("delFlag", "=", false);
|
||||
Cnd codeCnd = Cnd.where("code", "=", category.getCode()).and("delFlag", "=", false);
|
||||
if (StrUtil.isNotBlank(excludeId)) {
|
||||
nameCnd.and("id", "!=", excludeId);
|
||||
codeCnd.and("id", "!=", excludeId);
|
||||
}
|
||||
if (count(nameCnd) > 0) {
|
||||
throw new RuntimeException("同级栏目名称已存在");
|
||||
}
|
||||
if (count(codeCnd) > 0) {
|
||||
throw new RuntimeException("栏目编码已存在");
|
||||
}
|
||||
}
|
||||
|
||||
private void applyDefaults(SpreadCategory category) {
|
||||
|
||||
Reference in New Issue
Block a user