From d20269b15635b4ad8625c3c933545ca39f38a7a8 Mon Sep 17 00:00:00 2001 From: tangwei Date: Fri, 5 Jun 2026 13:34:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E5=AE=A1=E6=A0=B8?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qgc_base/domain/StationBasinInfo.java | 1 + .../system/service/impl/UserServiceImpl.java | 157 +++++++++++++++--- .../mapper/qgc_base/SdEngInfoBHMapper.xml | 6 +- 3 files changed, 141 insertions(+), 23 deletions(-) diff --git a/backend/src/main/java/com/yfd/platform/qgc_base/domain/StationBasinInfo.java b/backend/src/main/java/com/yfd/platform/qgc_base/domain/StationBasinInfo.java index d0c53bd6..45712859 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_base/domain/StationBasinInfo.java +++ b/backend/src/main/java/com/yfd/platform/qgc_base/domain/StationBasinInfo.java @@ -10,4 +10,5 @@ public class StationBasinInfo { private String hbrvnm; // 流域名称 private String rvcd; private String rvnm; + private String reachcd; } diff --git a/backend/src/main/java/com/yfd/platform/system/service/impl/UserServiceImpl.java b/backend/src/main/java/com/yfd/platform/system/service/impl/UserServiceImpl.java index cdd40b31..0b108700 100644 --- a/backend/src/main/java/com/yfd/platform/system/service/impl/UserServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/system/service/impl/UserServiceImpl.java @@ -12,9 +12,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.yfd.platform.config.ResponseResult; import com.yfd.platform.qgc_data.domain.SysUserDataScope; import com.yfd.platform.qgc_data.mapper.SysUserDataScopeMapper; +import com.yfd.platform.qgc_base.domain.SdRvcdDic; import com.yfd.platform.qgc_base.domain.StationBasinInfo; import com.yfd.platform.qgc_base.mapper.SdEngInfoBHMapper; import com.yfd.platform.qgc_base.mapper.SdHbrvDicMapper; +import com.yfd.platform.qgc_base.mapper.SdRvcdDicMapper; import com.yfd.platform.system.domain.LoginUser; import com.yfd.platform.system.domain.SysRole; import com.yfd.platform.system.domain.SysUser; @@ -66,6 +68,9 @@ public class UserServiceImpl extends ServiceImpl impleme @Resource private SdEngInfoBHMapper sdEngInfoBHMapper; + + @Resource + private SdRvcdDicMapper sdRvcdDicMapper; /** * 文件空间配置 */ @@ -693,7 +698,44 @@ public class UserServiceImpl extends ServiceImpl impleme userScopeMap.computeIfAbsent(scope.getUserId(), k -> new ArrayList<>()).add(scope); } } + List stationBasinInfos = sdEngInfoBHMapper.selectStationBasinInfo(); + List activeRvcdList = sdRvcdDicMapper.selectList(new LambdaQueryWrapper() + .eq(SdRvcdDic::getEnabled, 1) + .eq(SdRvcdDic::getIsDeleted, 0)); + Map rvcdMap = new HashMap<>(); + if (activeRvcdList != null) { + for (SdRvcdDic basin : activeRvcdList) { + if (StrUtil.isNotBlank(basin.getRvcd())) { + rvcdMap.put(basin.getRvcd(), basin); + } + } + } + Map rvcdDisplayNameMap = new HashMap<>(); + Map rvcdOrderPathMap = new HashMap<>(); + for (String rvcd : rvcdMap.keySet()) { + rvcdDisplayNameMap.put(rvcd, buildRvcdDisplayName(rvcd, rvcdMap, rvcdDisplayNameMap)); + rvcdOrderPathMap.put(rvcd, buildRvcdOrderPath(rvcd, rvcdMap, rvcdOrderPathMap)); + } + + Map stationNameMap = new HashMap<>(); + Map stationReachcdMap = new HashMap<>(); + Map> rvcdStationNamesMap = new HashMap<>(); + if (stationBasinInfos != null) { + for (StationBasinInfo info : stationBasinInfos) { + if (StrUtil.isNotBlank(info.getStcd()) && StrUtil.isNotBlank(info.getEnnm())) { + stationNameMap.put(info.getStcd(), info.getEnnm()); + } + if (StrUtil.isNotBlank(info.getStcd()) && StrUtil.isNotBlank(info.getReachcd())) { + stationReachcdMap.put(info.getStcd(), info.getReachcd()); + } + if (StrUtil.isBlank(info.getReachcd()) || StrUtil.isBlank(info.getEnnm())) { + continue; + } + addStationToRvcdIndex(rvcdStationNamesMap, info.getReachcd(), info.getEnnm(), rvcdMap); + } + } + for (SysUser record : records) { String userId = record.getId(); @@ -701,48 +743,119 @@ public class UserServiceImpl extends ServiceImpl impleme record.setRoles(roles); List scopes = userScopeMap.getOrDefault(userId, Collections.emptyList()); - Set basinNameSet = new LinkedHashSet<>(); + Set basinCodeSet = new LinkedHashSet<>(); Set stationNameSet = new LinkedHashSet<>(); for (SysUserDataScope scope : scopes) { String orgType = scope.getOrgType(); String orgId = scope.getOrgId(); - String orgName = scope.getOrgName(); if ("RVCD".equals(orgType)) { - if (StrUtil.isNotBlank(orgName)) { - basinNameSet.add(orgName); - } - if (orgId != null) { - if (stationBasinInfos != null) { - List stcdList = stationBasinInfos.stream().filter(info -> info.getRvcd().equals(orgId)).map(StationBasinInfo::getEnnm).toList(); - if(!stcdList.isEmpty()){ - stationNameSet.addAll(stcdList); - } + if (StrUtil.isNotBlank(orgId)) { + basinCodeSet.add(orgId); + Set stationNames = rvcdStationNamesMap.get(orgId); + if (stationNames != null && !stationNames.isEmpty()) { + stationNameSet.addAll(stationNames); } } } else if ("STATION".equals(orgType)) { - if (StrUtil.isNotBlank(orgName)) { - stationNameSet.add(orgName); - } - if (orgId != null) { - if (stationBasinInfos != null) { - String rvcd = stationBasinInfos.stream().filter(info -> info.getStcd().equals(orgId)).map(StationBasinInfo::getRvnm).findFirst().orElse(null); - if(StrUtil.isNotBlank(rvcd)){ - basinNameSet.add(rvcd); - } + if (StrUtil.isNotBlank(orgId)) { + String stationName = stationNameMap.get(orgId); + if (StrUtil.isNotBlank(stationName)) { + stationNameSet.add(stationName); + } else if (StrUtil.isNotBlank(scope.getOrgName())) { + stationNameSet.add(scope.getOrgName()); + } + + String reachcd = stationReachcdMap.get(orgId); + if (StrUtil.isNotBlank(reachcd)) { + basinCodeSet.add(reachcd); } } } } - record.setBasinNames(basinNameSet.isEmpty() ? null : String.join(",", basinNameSet)); - record.setStationNames(stationNameSet.isEmpty() ? null : String.join(",", stationNameSet)); + List sortedBasinNames = basinCodeSet.stream() + .sorted(Comparator.comparing((String code) -> rvcdOrderPathMap.getOrDefault(code, "~~~~~~~~~~")) + .thenComparing((String code) -> rvcdDisplayNameMap.getOrDefault(code, code), + Comparator.nullsLast(Comparator.naturalOrder())) + .thenComparing(Comparator.naturalOrder())) + .map(code -> rvcdDisplayNameMap.getOrDefault(code, code)) + .filter(StrUtil::isNotBlank) + .distinct() + .toList(); + + List sortedStationNames = stationNameSet.stream() + .filter(StrUtil::isNotBlank) + .sorted() + .toList(); + + record.setBasinNames(sortedBasinNames.isEmpty() ? null : String.join(",", sortedBasinNames)); + record.setStationNames(sortedStationNames.isEmpty() ? null : String.join(",", sortedStationNames)); } return mapPage; } + private void addStationToRvcdIndex(Map> rvcdStationNamesMap, String reachcd, + String stationName, Map rvcdMap) { + if (StrUtil.isBlank(reachcd) || StrUtil.isBlank(stationName)) { + return; + } + String currentCode = reachcd; + while (StrUtil.isNotBlank(currentCode)) { + rvcdStationNamesMap.computeIfAbsent(currentCode, key -> new LinkedHashSet<>()).add(stationName); + SdRvcdDic current = rvcdMap.get(currentCode); + if (current == null || StrUtil.isBlank(current.getPrvcd()) || "0".equals(current.getPrvcd())) { + break; + } + if (Objects.equals(current.getPrvcd(), currentCode)) { + break; + } + currentCode = current.getPrvcd(); + } + } + + private String buildRvcdDisplayName(String rvcd, Map rvcdMap, Map cache) { + if (StrUtil.isBlank(rvcd)) { + return null; + } + if (cache.containsKey(rvcd)) { + return cache.get(rvcd); + } + SdRvcdDic current = rvcdMap.get(rvcd); + if (current == null) { + return rvcd; + } + String currentName = StrUtil.blankToDefault(current.getRvnm(), rvcd); + String parentCode = current.getPrvcd(); + if (StrUtil.isBlank(parentCode) || "0".equals(parentCode)) { + return currentName; + } + String parentName = buildRvcdDisplayName(parentCode, rvcdMap, cache); + return StrUtil.isBlank(parentName) ? currentName : parentName + "-" + currentName; + } + + private String buildRvcdOrderPath(String rvcd, Map rvcdMap, Map cache) { + if (StrUtil.isBlank(rvcd)) { + return null; + } + if (cache.containsKey(rvcd)) { + return cache.get(rvcd); + } + SdRvcdDic current = rvcdMap.get(rvcd); + if (current == null) { + return "~~~~~~~~~~/" + rvcd; + } + String currentSegment = String.format("%010d", current.getOrderIndex() == null ? 999999999 : current.getOrderIndex()); + String parentCode = current.getPrvcd(); + if (StrUtil.isBlank(parentCode) || "0".equals(parentCode)) { + return currentSegment; + } + String parentPath = buildRvcdOrderPath(parentCode, rvcdMap, cache); + return StrUtil.isBlank(parentPath) ? currentSegment : parentPath + "/" + currentSegment; + } + /*********************************** * 用途说明:比较登录名称是否有重复 * 参数说明 diff --git a/backend/src/main/resources/mapper/qgc_base/SdEngInfoBHMapper.xml b/backend/src/main/resources/mapper/qgc_base/SdEngInfoBHMapper.xml index 58f9c214..b33d0dca 100644 --- a/backend/src/main/resources/mapper/qgc_base/SdEngInfoBHMapper.xml +++ b/backend/src/main/resources/mapper/qgc_base/SdEngInfoBHMapper.xml @@ -256,6 +256,9 @@ + + + @@ -263,10 +266,11 @@ SELECT e.STCD, e.ENNM, + e.REACHCD, e.RVCD, h.RVNM FROM SD_ENGINFO_B_H e - INNER JOIN SD_RVCD_DIC h ON e.RVCD = h.RVCD + LEFT JOIN SD_RVCD_DIC h ON e.RVCD = h.RVCD