fix: 优化流域树
This commit is contained in:
parent
272b85b275
commit
820eb37548
@ -353,17 +353,14 @@ public class TreeStructureServiceImpl implements ITreeStructureService {
|
|||||||
public List<Map<String, Object>> getRvcdEngTree(String rvcd, String engName) {
|
public List<Map<String, Object>> getRvcdEngTree(String rvcd, String engName) {
|
||||||
List<Map<String, Object>> result = new ArrayList<>();
|
List<Map<String, Object>> result = new ArrayList<>();
|
||||||
|
|
||||||
// 1. 查询流域列表
|
// 1. 查询流域列表,名称与排序口径对齐注册下拉
|
||||||
List<SdRvcdDic> rvcdList;
|
List<SdRvcdDic> rvcdList = rvcdDicMapper.selectRegDropdown(null, null);
|
||||||
if (StringUtils.hasText(rvcd)) {
|
if (StringUtils.hasText(rvcd)) {
|
||||||
rvcdList = rvcdDicMapper.selectByPrvcd(rvcd);
|
Map<String, SdRvcdDic> rvcdMap = rvcdList.stream()
|
||||||
SdRvcdDic singleRvcd = rvcdDicMapper.selectById(rvcd);
|
.collect(Collectors.toMap(SdRvcdDic::getRvcd, item -> item, (left, right) -> left));
|
||||||
if (singleRvcd != null && !rvcdList.contains(singleRvcd)) {
|
rvcdList = rvcdList.stream()
|
||||||
rvcdList = new ArrayList<>();
|
.filter(item -> isSameOrDescendantRvcd(item, rvcd, rvcdMap))
|
||||||
rvcdList.add(singleRvcd);
|
.collect(Collectors.toList());
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rvcdList = rvcdDicMapper.selectRootList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 预加载所有流域下的电站(按流域分组)
|
// 2. 预加载所有流域下的电站(按流域分组)
|
||||||
@ -428,6 +425,24 @@ public class TreeStructureServiceImpl implements ITreeStructureService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSameOrDescendantRvcd(SdRvcdDic current, String targetRvcd, Map<String, SdRvcdDic> rvcdMap) {
|
||||||
|
if (current == null || !StringUtils.hasText(targetRvcd)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (targetRvcd.equals(current.getRvcd())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Set<String> visited = new HashSet<>();
|
||||||
|
SdRvcdDic cursor = current;
|
||||||
|
while (cursor != null && StringUtils.hasText(cursor.getPrvcd()) && visited.add(cursor.getRvcd())) {
|
||||||
|
if (targetRvcd.equals(cursor.getPrvcd())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
cursor = rvcdMap.get(cursor.getPrvcd());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> getBaseEngTree(String baseId, String engName) {
|
public List<Map<String, Object>> getBaseEngTree(String baseId, String engName) {
|
||||||
List<Map<String, Object>> result = new ArrayList<>();
|
List<Map<String, Object>> result = new ArrayList<>();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user