fix: 优化地图逻辑

This commit is contained in:
tangwei 2026-07-08 09:03:27 +08:00
parent 1b07991cbf
commit db6f87ba71

View File

@ -2,6 +2,7 @@ package com.yfd.platform.qgc_sys.mapLayer.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yfd.platform.qgc_sys.mapLayer.domain.MsMapmoduleB;
import com.yfd.platform.qgc_sys.mapLayer.domain.MsMaplayerB;
import com.yfd.platform.qgc_sys.mapLayer.entity.vo.MapLayerAo;
import com.yfd.platform.qgc_sys.mapLayer.entity.vo.MapLayerVo;
@ -184,7 +185,8 @@ public class MapLayerBizServiceImpl implements IMapLayerBizService {
@Override
public List<MapLayerVo> getMapLayerTree(String moduleId, String systemId, String templateId) {
List<MapLayerVo> allLayers;
if (adminAuthService.isCurrentManagedAdmin()) {
boolean currentManagedAdmin = adminAuthService.isCurrentManagedAdmin();
if (currentManagedAdmin) {
allLayers = msMapmoduleBMapper.getMapLayerTree(moduleId, systemId, templateId);
} else {
List<String> currentUserModuleIds = getCurrentUserModuleIds();
@ -193,12 +195,15 @@ public class MapLayerBizServiceImpl implements IMapLayerBizService {
}
allLayers = msMapmoduleBMapper.getMapLayerTreeByModuleIds(currentUserModuleIds, systemId, templateId);
allLayers = supplementMissingParentLayers(allLayers);
allLayers = deduplicateMapLayers(allLayers);
}
if (allLayers == null || allLayers.isEmpty()) {
if (allLayers.isEmpty()) {
return new ArrayList<>();
}
if (!currentManagedAdmin) {
Set<String> checkedLayerIds = getCurrentModuleCheckedLayerIds(moduleId, systemId, templateId);
resetCheckedStatus(allLayers, checkedLayerIds);
}
allLayers = sortMapLayerVos(allLayers);
// 取第一级
@ -333,4 +338,76 @@ public class MapLayerBizServiceImpl implements IMapLayerBizService {
vo.setMultiSelect(1);
return vo;
}
private List<MapLayerVo> deduplicateMapLayers(List<MapLayerVo> layers) {
Map<String, MapLayerVo> uniqueMap = new LinkedHashMap<>();
for (MapLayerVo layer : layers) {
if (layer == null || StrUtil.isBlank(layer.getId())) {
continue;
}
uniqueMap.putIfAbsent(layer.getId(), layer);
}
return new ArrayList<>(uniqueMap.values());
}
private Set<String> getCurrentModuleCheckedLayerIds(String moduleId, String systemId, String templateId) {
if (StrUtil.isBlank(moduleId)) {
return Collections.emptySet();
}
LambdaQueryWrapper<MsMapmoduleB> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MsMapmoduleB::getModuleId, moduleId)
.eq(MsMapmoduleB::getResType, "layer")
.eq(MsMapmoduleB::getIsDeleted, 0)
.select(MsMapmoduleB::getResId);
if (StrUtil.isNotBlank(systemId)) {
wrapper.eq(MsMapmoduleB::getSystemId, systemId);
}
if (StrUtil.isNotBlank(templateId)) {
wrapper.eq(MsMapmoduleB::getTemplateId, templateId);
} else {
wrapper.and(w -> w.isNull(MsMapmoduleB::getTemplateId)
.or()
.eq(MsMapmoduleB::getTemplateId, "00000000-0000-0000-0000-000000000000"));
}
List<MsMapmoduleB> moduleLayers = msMapmoduleBMapper.selectList(wrapper);
if (moduleLayers == null || moduleLayers.isEmpty()) {
return Collections.emptySet();
}
Set<String> checkedIds = moduleLayers.stream()
.map(MsMapmoduleB::getResId)
.filter(StrUtil::isNotBlank)
.collect(Collectors.toCollection(LinkedHashSet::new));
if (checkedIds.isEmpty()) {
return Collections.emptySet();
}
Set<String> pendingParentIds = new LinkedHashSet<>(checkedIds);
while (!pendingParentIds.isEmpty()) {
LambdaQueryWrapper<MsMaplayerB> wrapperParent = new LambdaQueryWrapper<>();
wrapperParent.in(MsMaplayerB::getId, pendingParentIds)
.eq(MsMaplayerB::getIsDeleted, 0)
.select(MsMaplayerB::getId, MsMaplayerB::getParentId);
List<MsMaplayerB> currentLayers = msMaplayerBMapper.selectList(wrapperParent);
if (currentLayers == null || currentLayers.isEmpty()) {
break;
}
Set<String> nextParentIds = new LinkedHashSet<>();
for (MsMaplayerB currentLayer : currentLayers) {
if (StrUtil.isNotBlank(currentLayer.getParentId()) && checkedIds.add(currentLayer.getParentId())) {
nextParentIds.add(currentLayer.getParentId());
}
}
pendingParentIds = nextParentIds;
}
return checkedIds;
}
private void resetCheckedStatus(List<MapLayerVo> layers, Set<String> checkedLayerIds) {
if (layers == null || layers.isEmpty()) {
return;
}
Set<String> normalizedCheckedIds = checkedLayerIds == null ? Collections.emptySet() : checkedLayerIds;
for (MapLayerVo layer : layers) {
layer.setChecked(normalizedCheckedIds.contains(layer.getId()) ? 1 : 0);
}
}
}