fix: 用户审核注册查询优化
This commit is contained in:
parent
abb685258c
commit
d20269b156
@ -10,4 +10,5 @@ public class StationBasinInfo {
|
|||||||
private String hbrvnm; // 流域名称
|
private String hbrvnm; // 流域名称
|
||||||
private String rvcd;
|
private String rvcd;
|
||||||
private String rvnm;
|
private String rvnm;
|
||||||
|
private String reachcd;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,9 +12,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.config.ResponseResult;
|
||||||
import com.yfd.platform.qgc_data.domain.SysUserDataScope;
|
import com.yfd.platform.qgc_data.domain.SysUserDataScope;
|
||||||
import com.yfd.platform.qgc_data.mapper.SysUserDataScopeMapper;
|
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.domain.StationBasinInfo;
|
||||||
import com.yfd.platform.qgc_base.mapper.SdEngInfoBHMapper;
|
import com.yfd.platform.qgc_base.mapper.SdEngInfoBHMapper;
|
||||||
import com.yfd.platform.qgc_base.mapper.SdHbrvDicMapper;
|
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.LoginUser;
|
||||||
import com.yfd.platform.system.domain.SysRole;
|
import com.yfd.platform.system.domain.SysRole;
|
||||||
import com.yfd.platform.system.domain.SysUser;
|
import com.yfd.platform.system.domain.SysUser;
|
||||||
@ -66,6 +68,9 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SdEngInfoBHMapper sdEngInfoBHMapper;
|
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);
|
userScopeMap.computeIfAbsent(scope.getUserId(), k -> new ArrayList<>()).add(scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<StationBasinInfo> stationBasinInfos = sdEngInfoBHMapper.selectStationBasinInfo();
|
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) {
|
for (SysUser record : records) {
|
||||||
String userId = record.getId();
|
String userId = record.getId();
|
||||||
|
|
||||||
@ -701,48 +743,119 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
|
|||||||
record.setRoles(roles);
|
record.setRoles(roles);
|
||||||
|
|
||||||
List<SysUserDataScope> scopes = userScopeMap.getOrDefault(userId, Collections.emptyList());
|
List<SysUserDataScope> scopes = userScopeMap.getOrDefault(userId, Collections.emptyList());
|
||||||
Set<String> basinNameSet = new LinkedHashSet<>();
|
Set<String> basinCodeSet = new LinkedHashSet<>();
|
||||||
Set<String> stationNameSet = new LinkedHashSet<>();
|
Set<String> stationNameSet = new LinkedHashSet<>();
|
||||||
|
|
||||||
for (SysUserDataScope scope : scopes) {
|
for (SysUserDataScope scope : scopes) {
|
||||||
String orgType = scope.getOrgType();
|
String orgType = scope.getOrgType();
|
||||||
String orgId = scope.getOrgId();
|
String orgId = scope.getOrgId();
|
||||||
String orgName = scope.getOrgName();
|
|
||||||
|
|
||||||
if ("RVCD".equals(orgType)) {
|
if ("RVCD".equals(orgType)) {
|
||||||
if (StrUtil.isNotBlank(orgName)) {
|
if (StrUtil.isNotBlank(orgId)) {
|
||||||
basinNameSet.add(orgName);
|
basinCodeSet.add(orgId);
|
||||||
}
|
Set<String> stationNames = rvcdStationNamesMap.get(orgId);
|
||||||
if (orgId != null) {
|
if (stationNames != null && !stationNames.isEmpty()) {
|
||||||
if (stationBasinInfos != null) {
|
stationNameSet.addAll(stationNames);
|
||||||
List<String> stcdList = stationBasinInfos.stream().filter(info -> info.getRvcd().equals(orgId)).map(StationBasinInfo::getEnnm).toList();
|
|
||||||
if(!stcdList.isEmpty()){
|
|
||||||
stationNameSet.addAll(stcdList);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ("STATION".equals(orgType)) {
|
} else if ("STATION".equals(orgType)) {
|
||||||
if (StrUtil.isNotBlank(orgName)) {
|
if (StrUtil.isNotBlank(orgId)) {
|
||||||
stationNameSet.add(orgName);
|
String stationName = stationNameMap.get(orgId);
|
||||||
}
|
if (StrUtil.isNotBlank(stationName)) {
|
||||||
if (orgId != null) {
|
stationNameSet.add(stationName);
|
||||||
if (stationBasinInfos != null) {
|
} else if (StrUtil.isNotBlank(scope.getOrgName())) {
|
||||||
String rvcd = stationBasinInfos.stream().filter(info -> info.getStcd().equals(orgId)).map(StationBasinInfo::getRvnm).findFirst().orElse(null);
|
stationNameSet.add(scope.getOrgName());
|
||||||
if(StrUtil.isNotBlank(rvcd)){
|
|
||||||
basinNameSet.add(rvcd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String reachcd = stationReachcdMap.get(orgId);
|
||||||
|
if (StrUtil.isNotBlank(reachcd)) {
|
||||||
|
basinCodeSet.add(reachcd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
record.setBasinNames(basinNameSet.isEmpty() ? null : String.join(",", basinNameSet));
|
List<String> sortedBasinNames = basinCodeSet.stream()
|
||||||
record.setStationNames(stationNameSet.isEmpty() ? null : String.join(",", stationNameSet));
|
.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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************
|
/***********************************
|
||||||
* 用途说明:比较登录名称是否有重复
|
* 用途说明:比较登录名称是否有重复
|
||||||
* 参数说明
|
* 参数说明
|
||||||
|
|||||||
@ -256,6 +256,9 @@
|
|||||||
<result column="ENNM" property="ennm"/>
|
<result column="ENNM" property="ennm"/>
|
||||||
<result column="HBRVCD" property="hbrvcd"/>
|
<result column="HBRVCD" property="hbrvcd"/>
|
||||||
<result column="HBRVNM" property="hbrvnm"/>
|
<result column="HBRVNM" property="hbrvnm"/>
|
||||||
|
<result column="RVCD" property="rvcd"/>
|
||||||
|
<result column="RVNM" property="rvnm"/>
|
||||||
|
<result column="REACHCD" property="reachcd"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
|
|
||||||
@ -263,10 +266,11 @@
|
|||||||
SELECT
|
SELECT
|
||||||
e.STCD,
|
e.STCD,
|
||||||
e.ENNM,
|
e.ENNM,
|
||||||
|
e.REACHCD,
|
||||||
e.RVCD,
|
e.RVCD,
|
||||||
h.RVNM
|
h.RVNM
|
||||||
FROM SD_ENGINFO_B_H e
|
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>
|
||||||
<!-- <select id="selectStationBasinInfo" resultMap="StationBasinInfoResultMap">-->
|
<!-- <select id="selectStationBasinInfo" resultMap="StationBasinInfoResultMap">-->
|
||||||
<!-- SELECT-->
|
<!-- SELECT-->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user