fix: 树形isLeaf问题
This commit is contained in:
+21
-6
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -25,6 +26,10 @@ public class DictTreeService {
|
|||||||
}
|
}
|
||||||
List<SysDictItem> list = dictItemService.list(queryWrapper);
|
List<SysDictItem> list = dictItemService.list(queryWrapper);
|
||||||
|
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
List<String> dictItemIds = list.stream().map(SysDictItem::getId).collect(Collectors.toList());
|
List<String> dictItemIds = list.stream().map(SysDictItem::getId).collect(Collectors.toList());
|
||||||
// 判断有没有子级
|
// 判断有没有子级
|
||||||
queryWrapper.clear();
|
queryWrapper.clear();
|
||||||
@@ -34,10 +39,15 @@ public class DictTreeService {
|
|||||||
queryWrapper.like(SysDictItem::getItemText, nodeName);
|
queryWrapper.like(SysDictItem::getItemText, nodeName);
|
||||||
}
|
}
|
||||||
List<SysDictItem> childList = dictItemService.list(queryWrapper);
|
List<SysDictItem> childList = dictItemService.list(queryWrapper);
|
||||||
|
|
||||||
|
if (childList.isEmpty()) {
|
||||||
|
list.forEach(e -> e.setLeafFlag(true));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
Map<String, List<SysDictItem>> childMap = childList.stream().collect(Collectors.groupingBy(SysDictItem::getParentId));
|
||||||
list.forEach(item -> {
|
list.forEach(item -> {
|
||||||
if (childList.stream().anyMatch(child -> child.getParentId().equals(item.getId()))) {
|
List<SysDictItem> sysDictItems = childMap.get(item.getId());
|
||||||
item.setLeafFlag(false);
|
item.setLeafFlag(sysDictItems == null || sysDictItems.isEmpty());
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -67,10 +77,15 @@ public class DictTreeService {
|
|||||||
queryWrapper.like(SysDictItem::getItemText, nodeName);
|
queryWrapper.like(SysDictItem::getItemText, nodeName);
|
||||||
}
|
}
|
||||||
List<SysDictItem> childList = dictItemService.list(queryWrapper);
|
List<SysDictItem> childList = dictItemService.list(queryWrapper);
|
||||||
|
|
||||||
|
if (childList.isEmpty()) {
|
||||||
|
list.forEach(e -> e.setLeafFlag(true));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
Map<String, List<SysDictItem>> childMap = childList.stream().collect(Collectors.groupingBy(SysDictItem::getParentId));
|
||||||
list.forEach(item -> {
|
list.forEach(item -> {
|
||||||
if (childList.stream().anyMatch(child -> child.getParentId().equals(item.getId()))) {
|
List<SysDictItem> sysDictItems = childMap.get(item.getId());
|
||||||
item.setLeafFlag(false);
|
item.setLeafFlag(sysDictItems == null || sysDictItems.isEmpty());
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-6
@@ -194,10 +194,15 @@ public class PartNameServiceImpl extends ServiceImpl<PartNameMapper, PartName>
|
|||||||
queryWrapper.like(PartName::getName, nodeName);
|
queryWrapper.like(PartName::getName, nodeName);
|
||||||
}
|
}
|
||||||
List<PartName> childList = list(queryWrapper);
|
List<PartName> childList = list(queryWrapper);
|
||||||
|
|
||||||
|
if (childList.isEmpty()) {
|
||||||
|
list.forEach(e -> e.setLeafFlag(true));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
Map<String, List<PartName>> childMap = childList.stream().collect(Collectors.groupingBy(PartName::getParentCode));
|
||||||
list.forEach(item -> {
|
list.forEach(item -> {
|
||||||
if (childList.stream().anyMatch(child -> child.getParentCode().equals(item.getCode()))) {
|
List<PartName> partNames = childMap.get(item.getCode());
|
||||||
item.setLeafFlag(false);
|
item.setLeafFlag(partNames == null || partNames.isEmpty());
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -219,10 +224,14 @@ public class PartNameServiceImpl extends ServiceImpl<PartNameMapper, PartName>
|
|||||||
queryWrapper.like(PartName::getName, nodeName);
|
queryWrapper.like(PartName::getName, nodeName);
|
||||||
}
|
}
|
||||||
List<PartName> childList = list(queryWrapper);
|
List<PartName> childList = list(queryWrapper);
|
||||||
|
if (childList.isEmpty()) {
|
||||||
|
list.forEach(e -> e.setLeafFlag(true));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
Map<String, List<PartName>> childMap = childList.stream().collect(Collectors.groupingBy(PartName::getParentCode));
|
||||||
list.forEach(item -> {
|
list.forEach(item -> {
|
||||||
if (childList.stream().anyMatch(child -> child.getParentCode().equals(item.getCode()))) {
|
List<PartName> partNames = childMap.get(item.getCode());
|
||||||
item.setLeafFlag(false);
|
item.setLeafFlag(partNames == null || partNames.isEmpty());
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user