update 标签管理-树形查询

This commit is contained in:
lijiarao
2023-08-25 10:40:11 +08:00
parent 7809a7c4e5
commit 2558415c2d
2 changed files with 13 additions and 8 deletions
@@ -98,12 +98,14 @@ public class SysDictItemController {
List<SysDictItem> sysDictItems = sysDictItemService.list(queryWrapper);
//当查询结果中有数据的父级不存在时,赋值父级id为"0"
List<String> idList = sysDictItems.stream().map(SysDictItem::getId).collect(Collectors.toList());
//保存数据中的父级id
Map<String, String> map1 = CollStreamUtil.toMap(sysDictItems, SysDictItem::getId, SysDictItem::getParentId);
idList.add("0");
//赋值pId
sysDictItems.forEach(i ->{
if (!idList.contains(i.getParentId())) {
i.setParentId("0");
String parentId = i.getParentId();
if (idList.contains(parentId)) {
i.setPId(parentId);
}else {
i.setPId("0");
}
});
//配置
@@ -119,16 +121,14 @@ public class SysDictItemController {
(treeNode, tree) -> {
String id = treeNode.getId();
tree.setId(id);
tree.setParentId(treeNode.getParentId());
tree.setParentId(treeNode.getPId());
tree.setWeight(treeNode.getSortOrder());
tree.setName(treeNode.getItemText());
// 扩展属性 ...
Map<String, Object> map = BeanUtil.beanToMap(treeNode,"dictId","itemText","itemValue","enName","description","sortOrder","status");
Map<String, Object> map = BeanUtil.beanToMap(treeNode,"dictId","parentId","itemText","itemValue","enName","description","sortOrder","status");
for (String s : map.keySet()) {
tree.putExtra(s, map.get(s));
}
String parentId = map1.get(id);
tree.putExtra("parentId",parentId);
});
JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(treeNodes,SerializerFeature.WriteMapNullValue));
@@ -43,6 +43,11 @@ public class SysDictItem implements Serializable {
* 父级id
*/
private String parentId;
/**
* 父级id(树形结构使用)
*/
@TableField(exist = false)
private String pId;
/**
* 字典项文本