fix: 优化地图逻辑

This commit is contained in:
tangwei 2026-07-08 08:36:01 +08:00
parent a69115baec
commit 1b07991cbf
3 changed files with 157 additions and 11 deletions

View File

@ -41,6 +41,34 @@ public interface MsMapmoduleBMapper extends BaseMapper<MsMapmoduleB> {
List<MapLayerVo> getMapLayerTree(@Param("moduleId") String moduleId, @Param("sid") String sid,
@Param("templateId") String templateId);
/**
* 按模块ID集合查询地图图层树用于非管理员按用户菜单权限取图层
*/
@Select("<script>"
+ "SELECT DISTINCT BML.ID,BML.ANCHOR_PARAM_JSON, BML.PARENT_ID AS parentId, BML.TITLE, BML.CODE, BML.LABEL_LEVEL AS labelLevel, "
+ "BML.CHECKABLE, BML.TYPE, BML.Z_INDEX AS zIndex, BML.STTP_TYPE AS sttpType, BML.LAYERS, "
+ "BML.PARAMJSON AS paramJson, BML.URL, BML.URL_THD AS urlThd, BML.OPACITY, BML.SYSTEM_ID AS systemId, "
+ "BML.OPTIONS, BMM.MULTI_SELECT AS multiSelect, BMM.CAN_BE_CHECKED AS canBeChecked, "
+ "CASE WHEN BMM.CHECKED IS NULL THEN 0 ELSE BMM.CHECKED END AS checked, BML.ORDER_INDEX "
+ "FROM MS_MAPLAYER_B BML INNER JOIN MS_MAPMODULE_B BMM ON BML.ID = BMM.RES_ID "
+ "WHERE BMM.IS_DELETED = 0 AND BMM.RES_TYPE = 'layer' "
+ "<if test=\"moduleIds != null and moduleIds.size() > 0\">"
+ " AND BMM.MODULE_ID IN "
+ "<foreach collection=\"moduleIds\" item=\"moduleId\" open=\"(\" separator=\",\" close=\")\">"
+ "#{moduleId}"
+ "</foreach>"
+ "</if>"
+ "<if test=\"sid != null and sid != ''\"> AND BMM.SYSTEM_ID = #{sid}</if>"
+ "<choose>"
+ "<when test=\"templateId != null and templateId != ''\"> AND BMM.TEMPLATE_ID = #{templateId}</when>"
+ "<otherwise> AND (BMM.TEMPLATE_ID IS NULL OR BMM.TEMPLATE_ID = '00000000-0000-0000-0000-000000000000')</otherwise>"
+ "</choose>"
+ " AND BML.ENABLE = 1 AND BML.IS_DELETED = 0 AND (BML.TYPE NOT IN ('YXDT','DXDT','SLDT') OR BML.TYPE IS NULL) "
+ "ORDER BY BML.ORDER_INDEX"
+ "</script>")
List<MapLayerVo> getMapLayerTreeByModuleIds(@Param("moduleIds") List<String> moduleIds, @Param("sid") String sid,
@Param("templateId") String templateId);
/**
* 查询地图工具箱关联MS_MAPMODULE_B与MS_MAPTOOLBOX_B
*/

View File

@ -8,12 +8,16 @@ import com.yfd.platform.qgc_sys.mapLayer.entity.vo.MapLayerVo;
import com.yfd.platform.qgc_sys.mapLayer.mapper.MsMaplayerBMapper;
import com.yfd.platform.qgc_sys.mapLayer.mapper.MsMapmoduleBMapper;
import com.yfd.platform.qgc_sys.mapLayer.service.IMapLayerBizService;
import com.yfd.platform.system.domain.SysMenu;
import com.yfd.platform.system.domain.SysDictionary;
import com.yfd.platform.system.domain.SysDictionaryItems;
import com.yfd.platform.system.domain.SysUser;
import com.yfd.platform.system.mapper.SysDictionaryItemsMapper;
import com.yfd.platform.system.mapper.SysDictionaryMapper;
import com.yfd.platform.system.mapper.SysMenuMapper;
import com.yfd.platform.system.mapper.SysUserMapper;
import com.yfd.platform.system.service.IAdminAuthService;
import com.yfd.platform.utils.SecurityUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
@ -43,6 +47,12 @@ public class MapLayerBizServiceImpl implements IMapLayerBizService {
@Resource
private MsMapmoduleBMapper msMapmoduleBMapper;
@Resource
private SysMenuMapper sysMenuMapper;
@Resource
private IAdminAuthService adminAuthService;
@Override
public List<MsMaplayerB> getMapLayerTree(MapLayerAo flag) {
// 1. 查询字典 "DTZJLX" 获取需要排除的图层类型
@ -173,13 +183,24 @@ public class MapLayerBizServiceImpl implements IMapLayerBizService {
@Override
public List<MapLayerVo> getMapLayerTree(String moduleId, String systemId, String templateId) {
// 通过 JOIN 查询 MS_MAPLAYER_B MS_MAPMODULE_B
List<MapLayerVo> allLayers = msMapmoduleBMapper.getMapLayerTree(moduleId, systemId, templateId);
List<MapLayerVo> allLayers;
if (adminAuthService.isCurrentManagedAdmin()) {
allLayers = msMapmoduleBMapper.getMapLayerTree(moduleId, systemId, templateId);
} else {
List<String> currentUserModuleIds = getCurrentUserModuleIds();
if (currentUserModuleIds.isEmpty()) {
return new ArrayList<>();
}
allLayers = msMapmoduleBMapper.getMapLayerTreeByModuleIds(currentUserModuleIds, systemId, templateId);
allLayers = supplementMissingParentLayers(allLayers);
}
if (allLayers == null || allLayers.isEmpty()) {
return new ArrayList<>();
}
allLayers = sortMapLayerVos(allLayers);
// 取第一级
List<MapLayerVo> parents = allLayers.stream()
.filter(p -> StrUtil.isBlank(p.getParentId()))
@ -211,4 +232,105 @@ public class MapLayerBizServiceImpl implements IMapLayerBizService {
}
}
}
private List<String> getCurrentUserModuleIds() {
String userId = SecurityUtils.getUserId();
if (StrUtil.isBlank(userId)) {
return new ArrayList<>();
}
List<SysMenu> userMenus = sysMenuMapper.selectMenuByUserId(userId, null);
if (userMenus == null || userMenus.isEmpty()) {
return new ArrayList<>();
}
return userMenus.stream()
.map(SysMenu::getId)
.filter(StrUtil::isNotBlank)
.distinct()
.collect(Collectors.toList());
}
private List<MapLayerVo> supplementMissingParentLayers(List<MapLayerVo> layers) {
if (layers == null || layers.isEmpty()) {
return new ArrayList<>();
}
List<MapLayerVo> result = new ArrayList<>(layers);
Set<String> existingIds = result.stream()
.map(MapLayerVo::getId)
.filter(StrUtil::isNotBlank)
.collect(Collectors.toCollection(LinkedHashSet::new));
Set<String> pendingParentIds = result.stream()
.map(MapLayerVo::getParentId)
.filter(StrUtil::isNotBlank)
.filter(parentId -> !existingIds.contains(parentId))
.collect(Collectors.toCollection(LinkedHashSet::new));
while (!pendingParentIds.isEmpty()) {
LambdaQueryWrapper<MsMaplayerB> wrapper = new LambdaQueryWrapper<>();
wrapper.in(MsMaplayerB::getId, pendingParentIds)
.eq(MsMaplayerB::getIsDeleted, 0)
.eq(MsMaplayerB::getEnable, 1)
.and(w -> w.notIn(MsMaplayerB::getType, "YXDT", "DXDT", "SLDT").or().isNull(MsMaplayerB::getType))
.orderByAsc(MsMaplayerB::getOrderIndex);
List<MsMaplayerB> parentLayers = msMaplayerBMapper.selectList(wrapper);
if (parentLayers == null || parentLayers.isEmpty()) {
break;
}
Set<String> nextParentIds = new LinkedHashSet<>();
for (MsMaplayerB parentLayer : parentLayers) {
if (parentLayer == null || StrUtil.isBlank(parentLayer.getId()) || existingIds.contains(parentLayer.getId())) {
continue;
}
result.add(toMapLayerVo(parentLayer));
existingIds.add(parentLayer.getId());
if (StrUtil.isNotBlank(parentLayer.getParentId()) && !existingIds.contains(parentLayer.getParentId())) {
nextParentIds.add(parentLayer.getParentId());
}
}
pendingParentIds = nextParentIds;
}
return result;
}
private List<MapLayerVo> sortMapLayerVos(List<MapLayerVo> layers) {
return layers.stream()
.sorted(Comparator
.comparingInt((MapLayerVo item) -> parseOrderIndex(item.getOrderIndex()))
.thenComparing(item -> StrUtil.nullToDefault(item.getId(), "")))
.collect(Collectors.toList());
}
private int parseOrderIndex(String orderIndex) {
if (StrUtil.isBlank(orderIndex)) {
return Integer.MAX_VALUE;
}
try {
return Integer.parseInt(orderIndex);
} catch (NumberFormatException ex) {
return Integer.MAX_VALUE;
}
}
private MapLayerVo toMapLayerVo(MsMaplayerB layer) {
MapLayerVo vo = new MapLayerVo();
vo.setId(layer.getId());
vo.setParentId(layer.getParentId());
vo.setTitle(layer.getTitle());
vo.setCode(layer.getCode());
vo.setLabelLevel(layer.getLabelLevel());
vo.setCheckable(layer.getCheckable());
vo.setType(layer.getType());
vo.setZIndex(layer.getZIndex());
vo.setSttpType(layer.getSttpType());
vo.setLayers(layer.getLayers());
vo.setUrl(layer.getUrl());
vo.setUrlThd(layer.getUrlThd());
vo.setOpacity(layer.getOpacity());
vo.setParamJson(layer.getParamJson());
vo.setAnchorParamJson(layer.getAnchorParamJson());
vo.setOptions(layer.getOptions());
vo.setOrderIndex(layer.getOrderIndex() == null ? null : String.valueOf(layer.getOrderIndex()));
vo.setChecked(0);
vo.setCanBeChecked(0);
vo.setMultiSelect(1);
return vo;
}
}

View File

@ -136,13 +136,9 @@ public class MapmoduleBServiceImpl extends ServiceImpl<MsMapmoduleBMapper, MsMap
MapmoduleVo mapmoduleVo = new MapmoduleVo();
// 1. GIS图层区
List<MapLayerVo> layer;
if (hasCurrentUserModulePermission(mapmoduleB.getModuleId())) {
layer = mapLayerBizService.getMapLayerTree(
mapmoduleB.getModuleId(), mapmoduleB.getSystemId(), templateId);
} else {
layer = new ArrayList<>();
}
List<MapLayerVo> layer = mapLayerBizService.getMapLayerTree(
mapmoduleB.getModuleId(), mapmoduleB.getSystemId(), templateId);;
mapmoduleVo.setMapLayerVos(layer);
// 2. 地图图例