diff --git a/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/service/impl/MapLayerBizServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/service/impl/MapLayerBizServiceImpl.java index 059bcdd0..38d4d548 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/service/impl/MapLayerBizServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/service/impl/MapLayerBizServiceImpl.java @@ -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 getMapLayerTree(String moduleId, String systemId, String templateId) { List allLayers; - if (adminAuthService.isCurrentManagedAdmin()) { + boolean currentManagedAdmin = adminAuthService.isCurrentManagedAdmin(); + if (currentManagedAdmin) { allLayers = msMapmoduleBMapper.getMapLayerTree(moduleId, systemId, templateId); } else { List 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 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 deduplicateMapLayers(List layers) { + Map 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 getCurrentModuleCheckedLayerIds(String moduleId, String systemId, String templateId) { + if (StrUtil.isBlank(moduleId)) { + return Collections.emptySet(); + } + LambdaQueryWrapper 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 moduleLayers = msMapmoduleBMapper.selectList(wrapper); + if (moduleLayers == null || moduleLayers.isEmpty()) { + return Collections.emptySet(); + } + Set checkedIds = moduleLayers.stream() + .map(MsMapmoduleB::getResId) + .filter(StrUtil::isNotBlank) + .collect(Collectors.toCollection(LinkedHashSet::new)); + if (checkedIds.isEmpty()) { + return Collections.emptySet(); + } + Set pendingParentIds = new LinkedHashSet<>(checkedIds); + while (!pendingParentIds.isEmpty()) { + LambdaQueryWrapper wrapperParent = new LambdaQueryWrapper<>(); + wrapperParent.in(MsMaplayerB::getId, pendingParentIds) + .eq(MsMaplayerB::getIsDeleted, 0) + .select(MsMaplayerB::getId, MsMaplayerB::getParentId); + List currentLayers = msMaplayerBMapper.selectList(wrapperParent); + if (currentLayers == null || currentLayers.isEmpty()) { + break; + } + Set 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 layers, Set checkedLayerIds) { + if (layers == null || layers.isEmpty()) { + return; + } + Set normalizedCheckedIds = checkedLayerIds == null ? Collections.emptySet() : checkedLayerIds; + for (MapLayerVo layer : layers) { + layer.setChecked(normalizedCheckedIds.contains(layer.getId()) ? 1 : 0); + } + } }