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