fix: 用户审核注册查询优化

This commit is contained in:
tangwei 2026-06-05 13:34:24 +08:00
parent abb685258c
commit d20269b156
3 changed files with 141 additions and 23 deletions

View File

@ -10,4 +10,5 @@ public class StationBasinInfo {
private String hbrvnm; // 流域名称
private String rvcd;
private String rvnm;
private String reachcd;
}

View File

@ -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<SysUserMapper, SysUser> impleme
@Resource
private SdEngInfoBHMapper sdEngInfoBHMapper;
@Resource
private SdRvcdDicMapper sdRvcdDicMapper;
/**
* 文件空间配置
*/
@ -693,7 +698,44 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
userScopeMap.computeIfAbsent(scope.getUserId(), k -> new ArrayList<>()).add(scope);
}
}
List<StationBasinInfo> stationBasinInfos = sdEngInfoBHMapper.selectStationBasinInfo();
List<SdRvcdDic> activeRvcdList = sdRvcdDicMapper.selectList(new LambdaQueryWrapper<SdRvcdDic>()
.eq(SdRvcdDic::getEnabled, 1)
.eq(SdRvcdDic::getIsDeleted, 0));
Map<String, SdRvcdDic> rvcdMap = new HashMap<>();
if (activeRvcdList != null) {
for (SdRvcdDic basin : activeRvcdList) {
if (StrUtil.isNotBlank(basin.getRvcd())) {
rvcdMap.put(basin.getRvcd(), basin);
}
}
}
Map<String, String> rvcdDisplayNameMap = new HashMap<>();
Map<String, String> rvcdOrderPathMap = new HashMap<>();
for (String rvcd : rvcdMap.keySet()) {
rvcdDisplayNameMap.put(rvcd, buildRvcdDisplayName(rvcd, rvcdMap, rvcdDisplayNameMap));
rvcdOrderPathMap.put(rvcd, buildRvcdOrderPath(rvcd, rvcdMap, rvcdOrderPathMap));
}
Map<String, String> stationNameMap = new HashMap<>();
Map<String, String> stationReachcdMap = new HashMap<>();
Map<String, Set<String>> 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<SysUserMapper, SysUser> impleme
record.setRoles(roles);
List<SysUserDataScope> scopes = userScopeMap.getOrDefault(userId, Collections.emptyList());
Set<String> basinNameSet = new LinkedHashSet<>();
Set<String> basinCodeSet = new LinkedHashSet<>();
Set<String> 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<String> 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<String> 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<String> 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<String> 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<String, Set<String>> rvcdStationNamesMap, String reachcd,
String stationName, Map<String, SdRvcdDic> 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<String, SdRvcdDic> rvcdMap, Map<String, String> 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<String, SdRvcdDic> rvcdMap, Map<String, String> 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;
}
/***********************************
* 用途说明:比较登录名称是否有重复
* 参数说明

View File

@ -256,6 +256,9 @@
<result column="ENNM" property="ennm"/>
<result column="HBRVCD" property="hbrvcd"/>
<result column="HBRVNM" property="hbrvnm"/>
<result column="RVCD" property="rvcd"/>
<result column="RVNM" property="rvnm"/>
<result column="REACHCD" property="reachcd"/>
</resultMap>
@ -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
</select>
<!-- <select id="selectStationBasinInfo" resultMap="StationBasinInfoResultMap">-->
<!-- SELECT-->