fix: 优化过鱼数据填报逻辑

This commit is contained in:
tangwei 2026-06-05 09:30:48 +08:00
parent af87b8ca9a
commit eddf659bc2
5 changed files with 288 additions and 164 deletions

View File

@ -12,6 +12,7 @@ import java.util.List;
public class SdEngInfoBHRequest { public class SdEngInfoBHRequest {
private String baseId; private String baseId;
private String hbrvcd; private String hbrvcd;
private String rvcd;
private List<String> basIds; private List<String> basIds;
private List<String> hbrvcds; private List<String> hbrvcds;
private List<String> rvcds; private List<String> rvcds;

View File

@ -2,6 +2,7 @@ package com.yfd.platform.qgc_base.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -84,11 +85,13 @@ public class SdEngInfoBHServiceImpl extends ServiceImpl<SdEngInfoBHMapper, SdEng
String baseId = sdEngInfoBHRequest.getBaseId(); String baseId = sdEngInfoBHRequest.getBaseId();
String hbrvcd = sdEngInfoBHRequest.getHbrvcd(); String hbrvcd = sdEngInfoBHRequest.getHbrvcd();
String ennm = sdEngInfoBHRequest.getEnnm(); String ennm = sdEngInfoBHRequest.getEnnm();
String rvcd = sdEngInfoBHRequest.getRvcd();
List<String> rvcds = sdEngInfoBHRequest.getRvcds(); List<String> rvcds = sdEngInfoBHRequest.getRvcds();
List<String> hbrvcds = sdEngInfoBHRequest.getHbrvcds(); List<String> hbrvcds = sdEngInfoBHRequest.getHbrvcds();
LambdaQueryWrapper<SdEngInfoBH> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SdEngInfoBH> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(StringUtils.hasText(baseId), SdEngInfoBH::getBaseId, baseId) wrapper.eq(StringUtils.hasText(baseId), SdEngInfoBH::getBaseId, baseId)
.eq(StringUtils.hasText(hbrvcd), SdEngInfoBH::getHbrvcd, hbrvcd) .eq(StringUtils.hasText(hbrvcd), SdEngInfoBH::getHbrvcd, hbrvcd)
.eq(StrUtil.isNotBlank(rvcd), SdEngInfoBH::getRvcd, rvcd)
.in(rvcds != null && !rvcds.isEmpty(), SdEngInfoBH::getRvcd, rvcds) .in(rvcds != null && !rvcds.isEmpty(), SdEngInfoBH::getRvcd, rvcds)
.in(hbrvcds != null && !hbrvcds.isEmpty(), SdEngInfoBH::getHbrvcd, hbrvcds) .in(hbrvcds != null && !hbrvcds.isEmpty(), SdEngInfoBH::getHbrvcd, hbrvcds)
.like(StringUtils.hasText(ennm), SdEngInfoBH::getEnnm, ennm) .like(StringUtils.hasText(ennm), SdEngInfoBH::getEnnm, ennm)

View File

@ -1095,21 +1095,25 @@ public class FishDraftDataController {
private void validateAndNormalizeData(FishDraftData data, FishImportResult.FishImportRow importRow, private void validateAndNormalizeData(FishDraftData data, FishImportResult.FishImportRow importRow,
List<String> warnings) { List<String> warnings) {
if (data.getStcd() == null || data.getStcd().isEmpty()) { if (data.getStcd() == null || data.getStcd().isEmpty()) {
warnings.add("stcd"); addWarning(warnings, "stcd");
} else { } else {
String stcd = fishImportService.resolveFpssCode(data.getStcd(), data.getStnm()); String stcd = fishImportService.resolveFpssCode(data.getStcd(), data.getStnm());
if (stcd == null) { if (stcd == null) {
warnings.add("stcd"); addWarning(warnings, "stcd");
} else {
data.setStcd(stcd);
} }
} }
if (data.getRstcd() != null && !data.getRstcd().isEmpty()) { if (data.getRstcd() != null && !data.getRstcd().isEmpty()) {
String stationCode = fishImportService.resolveStationCode(data.getRstcd(), data.getEnnm()); String stationCode = fishImportService.resolveStationCode(data.getRstcd(), data.getEnnm());
if (stationCode == null) { if (stationCode == null) {
warnings.add("rstcd"); addWarning(warnings, "rstcd");
} else {
data.setRstcd(stationCode);
} }
} else { } else {
warnings.add("rstcd"); addWarning(warnings, "rstcd");
} }
// if (data.getBaseId() != null && !data.getBaseId().isEmpty()) { // if (data.getBaseId() != null && !data.getBaseId().isEmpty()) {
@ -1122,14 +1126,18 @@ public class FishDraftDataController {
if (data.getHbrvcd() != null && !data.getHbrvcd().isEmpty()) { if (data.getHbrvcd() != null && !data.getHbrvcd().isEmpty()) {
String baseId = fishImportService.resolveHbrvcdCode(data.getHbrvcd(), data.getHbrvnm()); String baseId = fishImportService.resolveHbrvcdCode(data.getHbrvcd(), data.getHbrvnm());
if (baseId == null) { if (baseId == null) {
warnings.add("hbrvcd"); addWarning(warnings, "hbrvcd");
} else {
data.setHbrvcd(baseId);
} }
} }
if (data.getRvcd() != null && !data.getRvcd().isEmpty()) { if (data.getRvcd() != null && !data.getRvcd().isEmpty()) {
String rvcd = fishImportService.resolveRiverCode(data.getRvcd(), data.getRvcd()); String rvcd = fishImportService.resolveRiverCode(data.getRvcd(), data.getRvnm());
if (rvcd == null) { if (rvcd == null) {
warnings.add("rvcd"); addWarning(warnings, "rvcd");
} else {
data.setRvcd(rvcd);
} }
} }
@ -1145,55 +1153,64 @@ public class FishDraftDataController {
// } // }
if (data.getFtp() == null || data.getFtp().isEmpty()) { if (data.getFtp() == null || data.getFtp().isEmpty()) {
warnings.add("ftp"); addWarning(warnings, "ftp");
} else { } else {
String ftpCode = fishImportService.resolveFishDictCode(data.getFtp(), data.getFtpName()); String ftpCode = fishImportService.resolveFishDictCode(data.getFtp(), data.getFtpName());
if (ftpCode == null) { if (ftpCode == null) {
warnings.add("ftp"); addWarning(warnings, "ftp");
} else {
data.setFtp(ftpCode);
} }
} }
if (data.getFcnt() == null) { if (data.getFcnt() == null) {
warnings.add("fcnt"); addWarning(warnings, "fcnt");
} }
if (data.getStrdt() == null) { if (data.getStrdt() == null) {
warnings.add("strdt"); addWarning(warnings, "strdt");
} }
if (data.getEnddt() != null && data.getStrdt() != null && data.getEnddt().before(data.getStrdt())) { if (data.getEnddt() != null && data.getStrdt() != null && data.getEnddt().before(data.getStrdt())) {
warnings.add("enddt"); addWarning(warnings, "enddt");
} }
if (data.getDirection() == null || data.getDirection().isEmpty()) { if (data.getDirection() == null || data.getDirection().isEmpty()) {
warnings.add("direction"); addWarning(warnings, "direction");
} else { } else {
String direction = fishImportService.resolveDirection(data.getDirection().trim(), importRow); String direction = fishImportService.resolveDirection(data.getDirection().trim(), importRow);
if (direction == null) { if (direction == null) {
warnings.add("direction"); addWarning(warnings, "direction");
} }
} }
if (data.getIsfs() == null) { if (data.getIsfs() == null) {
warnings.add("isfs"); addWarning(warnings, "isfs");
} else { } else {
String isfs = fishImportService.resolveIsfs(String.valueOf(data.getIsfs()), importRow); String isfs = fishImportService.resolveIsfs(String.valueOf(data.getIsfs()), importRow);
if (isfs == null) { if (isfs == null) {
warnings.add("isfs"); addWarning(warnings, "isfs");
} }
} }
if (StringUtils.hasText(data.getHbrvcd()) && StringUtils.hasText(data.getRstcd())) { if (StringUtils.hasText(data.getHbrvcd()) && StringUtils.hasText(data.getRstcd())) {
if (!fishImportService.validateStationBelongsToBase(data.getRstcd(), data.getHbrvcd())) { if (!fishImportService.validateStationBelongsToBase(data.getRstcd(), data.getHbrvcd())) {
warnings.add("hbrvcd"); addWarning(warnings, "hbrvcd");
warnings.add("rstcd"); addWarning(warnings, "rstcd");
}
}
if (StringUtils.hasText(data.getRvcd()) && StringUtils.hasText(data.getRstcd())) {
if (!fishImportService.validateStationBelongsToRiver(data.getRstcd(), data.getRvcd())) {
addWarning(warnings, "rvcd");
addWarning(warnings, "rstcd");
} }
} }
if (StringUtils.hasText(data.getRstcd()) && StringUtils.hasText(data.getStcd())) { if (StringUtils.hasText(data.getRstcd()) && StringUtils.hasText(data.getStcd())) {
if (!fishImportService.validateFpssBelongsToStation(data.getStcd(), data.getRstcd())) { if (!fishImportService.validateFpssBelongsToStation(data.getStcd(), data.getRstcd())) {
warnings.add("stcd"); addWarning(warnings, "stcd");
warnings.add("rstcd"); addWarning(warnings, "rstcd");
} }
} }
@ -1202,6 +1219,12 @@ public class FishDraftDataController {
// } // }
} }
private void addWarning(List<String> warnings, String field) {
if (!warnings.contains(field)) {
warnings.add(field);
}
}
@PostMapping("/validateAndMatchRow") @PostMapping("/validateAndMatchRow")
@Operation(summary = "校验数据并匹配到成功或失败列表") @Operation(summary = "校验数据并匹配到成功或失败列表")
public ResponseResult validateAndMatchRow(@RequestBody FishImportRowRequest request) { public ResponseResult validateAndMatchRow(@RequestBody FishImportRowRequest request) {
@ -1324,4 +1347,4 @@ public class FishDraftDataController {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
} }

View File

@ -50,10 +50,12 @@ public interface IFishImportService {
boolean validateStationBelongsToBase(String stationCode, String baseId); boolean validateStationBelongsToBase(String stationCode, String baseId);
boolean validateStationBelongsToRiver(String stationCode, String rvcd);
boolean validateFpssBelongsToStation(String fpssCode, String stationCode); boolean validateFpssBelongsToStation(String fpssCode, String stationCode);
void processAttachments(FishImportResult result, ZipFileUtil.ZipContent zipContent); void processAttachments(FishImportResult result, ZipFileUtil.ZipContent zipContent);
void processAttachmentsAsync(List<FishDraftData> dataList, void processAttachmentsAsync(List<FishDraftData> dataList,
String tempDir); String tempDir);
} }

View File

@ -831,248 +831,343 @@ public class FishImportServiceImpl implements IFishImportService {
public String resolveStationCode(String stationName) { public String resolveStationCode(String stationName) {
if (stationName == null) { String normalizedName = normalizeInput(stationName);
if (!StringUtils.hasText(normalizedName)) {
return null; return null;
} }
String lowerName = stationName.toLowerCase().trim(); SdEngInfoBH exactMatch = findFirst(engInfoBHMapper.selectList(new LambdaQueryWrapper<SdEngInfoBH>()
if (STATION_NAME_CACHE.containsKey(lowerName)) { .select(SdEngInfoBH::getStcd, SdEngInfoBH::getEnnm)
return STATION_NAME_CACHE.get(lowerName); .eq(SdEngInfoBH::getEnnm, normalizedName)));
if (exactMatch != null) {
return exactMatch.getStcd();
} }
for (Map.Entry<String, String> entry : STATION_NAME_CACHE.entrySet()) { SdEngInfoBH fuzzyMatch = findFirst(engInfoBHMapper.selectList(new LambdaQueryWrapper<SdEngInfoBH>()
if (entry.getKey().contains(lowerName)) { .select(SdEngInfoBH::getStcd, SdEngInfoBH::getEnnm)
return entry.getValue(); .like(SdEngInfoBH::getEnnm, normalizedName)));
} return fuzzyMatch == null ? null : fuzzyMatch.getStcd();
}
return null;
} }
public String resolveFpssCode(String name) { public String resolveFpssCode(String name) {
if (name == null) { String normalizedName = normalizeInput(name);
if (!StringUtils.hasText(normalizedName)) {
return null; return null;
} }
String lowerName = name.toLowerCase().trim(); SdFpssBH exactMatch = findFirst(fpssBHMapper.selectList(new LambdaQueryWrapper<SdFpssBH>()
if (FPSS_BH_CACHE.containsKey(lowerName)) { .select(SdFpssBH::getStcd, SdFpssBH::getStnm, SdFpssBH::getRstcd)
return FPSS_BH_CACHE.get(lowerName); .eq(SdFpssBH::getStnm, normalizedName)));
if (exactMatch != null) {
return exactMatch.getStcd();
} }
for (Map.Entry<String, String> entry : FPSS_BH_CACHE.entrySet()) { SdFpssBH fuzzyMatch = findFirst(fpssBHMapper.selectList(new LambdaQueryWrapper<SdFpssBH>()
if (entry.getKey().contains(lowerName)) { .select(SdFpssBH::getStcd, SdFpssBH::getStnm, SdFpssBH::getRstcd)
return entry.getValue(); .like(SdFpssBH::getStnm, normalizedName)));
} return fuzzyMatch == null ? null : fuzzyMatch.getStcd();
}
return null;
} }
@Override @Override
public String resolveStationCode(String code, String stationName) { public String resolveStationCode(String code, String stationName) {
if (code == null && stationName == null) { String normalizedCode = normalizeInput(code);
// String normalizedName = normalizeInput(stationName);
if (!StringUtils.hasText(normalizedCode)) {
return null; return null;
} }
loadStationAndBaseCache(); if (StringUtils.hasText(normalizedCode)) {
String lowerCode = code != null ? code.trim().toLowerCase() : null; SdEngInfoBH exact = findFirst(engInfoBHMapper.selectList(new LambdaQueryWrapper<SdEngInfoBH>()
String lowerName = stationName != null ? stationName.trim().toLowerCase() : null; .select(SdEngInfoBH::getStcd, SdEngInfoBH::getEnnm)
if (lowerCode != null && lowerName != null) { .eq(SdEngInfoBH::getStcd, normalizedCode)));
String cachedName = STATION_CODE_TO_NAME_CACHE.get(lowerCode); // .eq(SdEngInfoBH::getEnnm, normalizedName)));
if (cachedName != null && cachedName.equals(lowerName)) { if (exact != null) {
return code.trim(); return exact.getStcd();
} }
} }
String resultByName = resolveStationCode(stationName); // if (StringUtils.hasText(normalizedCode)) {
if (resultByName != null && resultByName.equalsIgnoreCase(code)) { // SdEngInfoBH byCode = engInfoBHMapper.selectById(normalizedCode);
return resultByName; // if (byCode != null && (!StringUtils.hasText(normalizedName) || normalizedName.equals(byCode.getEnnm()))) {
} // return byCode.getStcd();
// }
// }
// if (StringUtils.hasText(normalizedName)) {
// String resultByName = resolveStationCode(normalizedName);
// if (!StringUtils.hasText(normalizedCode) || normalizedCode.equalsIgnoreCase(resultByName)) {
// return resultByName;
// }
// }
return null; return null;
} }
@Override @Override
public String resolveFpssCode(String code, String name) { public String resolveFpssCode(String code, String name) {
if (code == null && name == null) { String normalizedCode = normalizeInput(code);
// String normalizedName = normalizeInput(name);
if (!StringUtils.hasText(normalizedCode)) {
return null; return null;
} }
loadStationAndBaseCache(); if (StringUtils.hasText(normalizedCode)) {
String lowerCode = code != null ? code.trim().toLowerCase() : null; SdFpssBH exact = findFirst(fpssBHMapper.selectList(new LambdaQueryWrapper<SdFpssBH>()
String lowerName = name != null ? name.trim().toLowerCase() : null; .select(SdFpssBH::getStcd, SdFpssBH::getStnm, SdFpssBH::getRstcd)
if (lowerCode != null && lowerName != null) { .eq(SdFpssBH::getStcd, normalizedCode)));
String cachedName = FPSS_CODE_TO_NAME_CACHE.get(lowerCode); // .eq(SdFpssBH::getStnm, normalizedName)));
if (cachedName != null && cachedName.equals(lowerName)) { if (exact != null) {
return code.trim(); return exact.getStcd();
} }
} }
String resultByName = resolveFpssCode(name); // if (StringUtils.hasText(normalizedCode)) {
if (resultByName != null && resultByName.equalsIgnoreCase(code)) { // SdFpssBH byCode = fpssBHMapper.selectById(normalizedCode);
return resultByName; // if (byCode != null && (!StringUtils.hasText(normalizedName) || normalizedName.equals(byCode.getStnm()))) {
} // return byCode.getStcd();
// }
// }
// if (StringUtils.hasText(normalizedName)) {
// String resultByName = resolveFpssCode(normalizedName);
// if (!StringUtils.hasText(normalizedCode) || normalizedCode.equalsIgnoreCase(resultByName)) {
// return resultByName;
// }
// }
return null; return null;
} }
public String resolveFishDictCode(String name) { public String resolveFishDictCode(String name) {
if (name == null) { String normalizedName = normalizeInput(name);
if (!StringUtils.hasText(normalizedName)) {
return null; return null;
} }
String lowerName = name.toLowerCase().trim(); SdFishDictoryB exactMatch = findFirst(fishDictoryBMapper.selectList(new LambdaQueryWrapper<SdFishDictoryB>()
if (FISH_DICT_CACHE.containsKey(lowerName)) { .select(SdFishDictoryB::getCode, SdFishDictoryB::getName)
return FISH_DICT_CACHE.get(lowerName); .eq(SdFishDictoryB::getName, normalizedName)));
if (exactMatch != null) {
return exactMatch.getCode();
} }
for (Map.Entry<String, String> entry : FISH_DICT_CACHE.entrySet()) { SdFishDictoryB fuzzyMatch = findFirst(fishDictoryBMapper.selectList(new LambdaQueryWrapper<SdFishDictoryB>()
if (entry.getKey().contains(lowerName) || lowerName.contains(entry.getKey())) { .select(SdFishDictoryB::getCode, SdFishDictoryB::getName)
return entry.getValue(); .and(wrapper -> wrapper.like(SdFishDictoryB::getName, normalizedName)
} .or()
} .like(SdFishDictoryB::getAlias, normalizedName))));
return null; return fuzzyMatch == null ? null : fuzzyMatch.getCode();
} }
@Override @Override
public String resolveFishDictCode(String code, String name) { public String resolveFishDictCode(String code, String name) {
if (code == null && name == null) { String normalizedCode = normalizeInput(code);
// String normalizedName = normalizeInput(name);
if (!StringUtils.hasText(normalizedCode)) {
return null; return null;
} }
loadStationAndBaseCache(); if (StringUtils.hasText(normalizedCode)) {
String lowerCode = code != null ? code.trim().toLowerCase() : null; SdFishDictoryB exact = findFirst(fishDictoryBMapper.selectList(new LambdaQueryWrapper<SdFishDictoryB>()
String lowerName = name != null ? name.trim().toLowerCase() : null; .select(SdFishDictoryB::getCode, SdFishDictoryB::getName)
if (lowerCode != null && lowerName != null) { .eq(SdFishDictoryB::getCode, normalizedCode)));
String cachedName = FISH_CODE_TO_NAME_CACHE.get(lowerCode); // .eq(SdFishDictoryB::getName, normalizedName)));
if (cachedName != null && cachedName.equals(lowerName)) { if (exact != null) {
return code.trim(); return exact.getCode();
} }
} }
String resultByName = resolveFishDictCode(name); // if (StringUtils.hasText(normalizedCode)) {
if (resultByName != null && resultByName.equalsIgnoreCase(code)) { // SdFishDictoryB byCode = findFirst(fishDictoryBMapper.selectList(new LambdaQueryWrapper<SdFishDictoryB>()
return resultByName; // .select(SdFishDictoryB::getCode, SdFishDictoryB::getName)
} // .eq(SdFishDictoryB::getCode, normalizedCode)));
// if (byCode != null && (!StringUtils.hasText(normalizedName) || normalizedName.equals(byCode.getName()))) {
// return byCode.getCode();
// }
// }
// if (StringUtils.hasText(normalizedName)) {
// String resultByName = resolveFishDictCode(normalizedName);
// if (!StringUtils.hasText(normalizedCode) || normalizedCode.equalsIgnoreCase(resultByName)) {
// return resultByName;
// }
// }
return null; return null;
} }
public String resolveBaseCode(String baseName) { public String resolveBaseCode(String baseName) {
if (baseName == null) { String normalizedName = normalizeInput(baseName);
if (!StringUtils.hasText(normalizedName)) {
return null; return null;
} }
String lowerName = baseName.toLowerCase().trim(); SdHydrobase exactMatch = findFirst(hydrobaseMapper.selectList(new LambdaQueryWrapper<SdHydrobase>()
if (BASE_NAME_CACHE.containsKey(lowerName)) { .select(SdHydrobase::getBaseid, SdHydrobase::getBasename)
return BASE_NAME_CACHE.get(lowerName); .eq(SdHydrobase::getBasename, normalizedName)));
if (exactMatch != null) {
return exactMatch.getBaseid();
} }
for (Map.Entry<String, String> entry : BASE_NAME_CACHE.entrySet()) { SdHydrobase fuzzyMatch = findFirst(hydrobaseMapper.selectList(new LambdaQueryWrapper<SdHydrobase>()
if (entry.getKey().contains(lowerName)) { .select(SdHydrobase::getBaseid, SdHydrobase::getBasename)
return entry.getValue(); .like(SdHydrobase::getBasename, normalizedName)));
} return fuzzyMatch == null ? null : fuzzyMatch.getBaseid();
}
return null;
} }
@Override @Override
public String resolveBaseCode(String code, String baseName) { public String resolveBaseCode(String code, String baseName) {
if (code == null && baseName == null) { String normalizedCode = normalizeInput(code);
String normalizedName = normalizeInput(baseName);
if (!StringUtils.hasText(normalizedCode) && !StringUtils.hasText(normalizedName)) {
return null; return null;
} }
loadStationAndBaseCache(); if (StringUtils.hasText(normalizedCode) && StringUtils.hasText(normalizedName)) {
String lowerCode = code != null ? code.trim().toLowerCase() : null; SdHydrobase exact = findFirst(hydrobaseMapper.selectList(new LambdaQueryWrapper<SdHydrobase>()
String lowerName = baseName != null ? baseName.trim().toLowerCase() : null; .select(SdHydrobase::getBaseid, SdHydrobase::getBasename)
if (lowerCode != null && lowerName != null) { .eq(SdHydrobase::getBaseid, normalizedCode)
String cachedName = BASE_CODE_TO_NAME_CACHE.get(lowerCode); .eq(SdHydrobase::getBasename, normalizedName)));
if (cachedName != null && cachedName.equals(lowerName)) { if (exact != null) {
return code.trim(); return exact.getBaseid();
} }
} }
String resultByName = resolveBaseCode(baseName); if (StringUtils.hasText(normalizedCode)) {
if (resultByName != null && resultByName.equalsIgnoreCase(code)) { SdHydrobase byCode = hydrobaseMapper.selectById(normalizedCode);
return resultByName; if (byCode != null && (!StringUtils.hasText(normalizedName) || normalizedName.equals(byCode.getBasename()))) {
return byCode.getBaseid();
}
}
if (StringUtils.hasText(normalizedName)) {
String resultByName = resolveBaseCode(normalizedName);
if (!StringUtils.hasText(normalizedCode) || normalizedCode.equalsIgnoreCase(resultByName)) {
return resultByName;
}
} }
return null; return null;
} }
public String resolveRiverCode(String riverName) { public String resolveRiverCode(String riverName) {
if (riverName == null) { String normalizedName = normalizeInput(riverName);
if (!StringUtils.hasText(normalizedName)) {
return null; return null;
} }
String lowerName = riverName.toLowerCase().trim(); SdRvcdDic exactMatch = findFirst(rvcdDicMapper.selectList(new LambdaQueryWrapper<SdRvcdDic>()
if (RIVER_NAME_CACHE.containsKey(lowerName)) { .select(SdRvcdDic::getRvcd, SdRvcdDic::getRvnm)
return RIVER_NAME_CACHE.get(lowerName); .eq(SdRvcdDic::getRvnm, normalizedName)));
if (exactMatch != null) {
return exactMatch.getRvcd();
} }
for (Map.Entry<String, String> entry : RIVER_NAME_CACHE.entrySet()) { SdRvcdDic fuzzyMatch = findFirst(rvcdDicMapper.selectList(new LambdaQueryWrapper<SdRvcdDic>()
if (entry.getKey().contains(lowerName)) { .select(SdRvcdDic::getRvcd, SdRvcdDic::getRvnm)
return entry.getValue(); .like(SdRvcdDic::getRvnm, normalizedName)));
} return fuzzyMatch == null ? null : fuzzyMatch.getRvcd();
}
return null;
} }
public String resolveHbrvcdCode(String riverName) { public String resolveHbrvcdCode(String riverName) {
if (riverName == null) { String normalizedName = normalizeInput(riverName);
if (!StringUtils.hasText(normalizedName)) {
return null; return null;
} }
String lowerName = riverName.toLowerCase().trim(); SdHbrvDic exactMatch = findFirst(sdHbrvDicMapper.selectList(new LambdaQueryWrapper<SdHbrvDic>()
if (HBRVCD_NAME_CACHE.containsKey(lowerName)) { .select(SdHbrvDic::getHbrvcd, SdHbrvDic::getHbrvnm)
return HBRVCD_NAME_CACHE.get(lowerName); .eq(SdHbrvDic::getHbrvnm, normalizedName)));
if (exactMatch != null) {
return exactMatch.getHbrvcd();
} }
for (Map.Entry<String, String> entry : HBRVCD_NAME_CACHE.entrySet()) { SdHbrvDic fuzzyMatch = findFirst(sdHbrvDicMapper.selectList(new LambdaQueryWrapper<SdHbrvDic>()
if (entry.getKey().contains(lowerName)) { .select(SdHbrvDic::getHbrvcd, SdHbrvDic::getHbrvnm)
return entry.getValue(); .like(SdHbrvDic::getHbrvnm, normalizedName)));
} return fuzzyMatch == null ? null : fuzzyMatch.getHbrvcd();
}
return null;
} }
@Override @Override
public String resolveRiverCode(String code, String riverName) { public String resolveRiverCode(String code, String riverName) {
if (code == null && riverName == null) { String normalizedCode = normalizeInput(code);
// String normalizedName = normalizeInput(riverName);
if (!StringUtils.hasText(normalizedCode)) {
return null; return null;
} }
loadStationAndBaseCache(); if (StringUtils.hasText(normalizedCode)) {
String lowerCode = code != null ? code.trim().toLowerCase() : null; SdRvcdDic exact = findFirst(rvcdDicMapper.selectList(new LambdaQueryWrapper<SdRvcdDic>()
String lowerName = riverName != null ? riverName.trim().toLowerCase() : null; .select(SdRvcdDic::getRvcd, SdRvcdDic::getRvnm)
if (lowerCode != null && lowerName != null) { .eq(SdRvcdDic::getRvcd, normalizedCode)));
String cachedName = RIVER_CODE_TO_NAME_CACHE.get(lowerCode); // .eq(SdRvcdDic::getRvnm, normalizedName)));
if (cachedName != null && cachedName.equals(lowerName)) { if (exact != null) {
return code.trim(); return exact.getRvcd();
} }
} }
String resultByName = resolveRiverCode(riverName); // if (StringUtils.hasText(normalizedCode)) {
if (resultByName != null && resultByName.equalsIgnoreCase(code)) { // SdRvcdDic byCode = rvcdDicMapper.selectById(normalizedCode);
return resultByName; // if (byCode != null && (!StringUtils.hasText(normalizedName) || normalizedName.equals(byCode.getRvnm()))) {
} // return byCode.getRvcd();
// }
// }
// if (StringUtils.hasText(normalizedName)) {
// String resultByName = resolveRiverCode(normalizedName);
// if (!StringUtils.hasText(normalizedCode) || normalizedCode.equalsIgnoreCase(resultByName)) {
// return resultByName;
// }
// }
return null; return null;
} }
@Override @Override
public String resolveHbrvcdCode(String code, String riverName) { public String resolveHbrvcdCode(String code, String riverName) {
if (code == null && riverName == null) { String normalizedCode = normalizeInput(code);
// String normalizedName = normalizeInput(riverName);
if (!StringUtils.hasText(normalizedCode)) {
return null; return null;
} }
loadStationAndBaseCache(); if (StringUtils.hasText(normalizedCode)) {
String lowerCode = code != null ? code.trim().toLowerCase() : null; SdHbrvDic exact = findFirst(sdHbrvDicMapper.selectList(new LambdaQueryWrapper<SdHbrvDic>()
String lowerName = riverName != null ? riverName.trim().toLowerCase() : null; .select(SdHbrvDic::getHbrvcd, SdHbrvDic::getHbrvnm)
if (lowerCode != null && lowerName != null) { .eq(SdHbrvDic::getHbrvcd, normalizedCode)));
String cachedName = HBRVCD_CODE_TO_NAME_CACHE.get(lowerCode); // .eq(SdHbrvDic::getHbrvnm, normalizedName)));
if (cachedName != null && cachedName.equals(lowerName)) { if (exact != null) {
return code.trim(); return exact.getHbrvcd();
} }
} }
String resultByName = resolveHbrvcdCode(riverName); // if (StringUtils.hasText(normalizedCode)) {
if (resultByName != null && resultByName.equalsIgnoreCase(code)) { // SdHbrvDic byCode = sdHbrvDicMapper.selectById(normalizedCode);
return resultByName; // if (byCode != null && (!StringUtils.hasText(normalizedName) || normalizedName.equals(byCode.getHbrvnm()))) {
} // return byCode.getHbrvcd();
// }
// }
// if (StringUtils.hasText(normalizedName)) {
// String resultByName = resolveHbrvcdCode(normalizedName);
// if (!StringUtils.hasText(normalizedCode) || normalizedCode.equalsIgnoreCase(resultByName)) {
// return resultByName;
// }
// }
return null; return null;
} }
@Override @Override
public boolean validateStationBelongsToBase(String stationCode, String baseId) { public boolean validateStationBelongsToBase(String stationCode, String baseId) {
if (stationCode == null || baseId == null) { String normalizedStationCode = normalizeInput(stationCode);
String normalizedBaseId = normalizeInput(baseId);
if (!StringUtils.hasText(normalizedStationCode) || !StringUtils.hasText(normalizedBaseId)) {
return false; return false;
} }
loadStationAndBaseCache(); return findFirst(engInfoBHMapper.selectList(new LambdaQueryWrapper<SdEngInfoBH>()
String stationLower = stationCode.trim().toLowerCase(); .select(SdEngInfoBH::getStcd)
String cachedBaseId = STATION_TO_BASE_CACHE.get(stationLower); .eq(SdEngInfoBH::getStcd, normalizedStationCode)
return baseId.equalsIgnoreCase(cachedBaseId); .eq(SdEngInfoBH::getHbrvcd, normalizedBaseId))) != null;
}
@Override
public boolean validateStationBelongsToRiver(String stationCode, String rvcd) {
String normalizedStationCode = normalizeInput(stationCode);
String normalizedRvcd = normalizeInput(rvcd);
if (!StringUtils.hasText(normalizedStationCode) || !StringUtils.hasText(normalizedRvcd)) {
return false;
}
return findFirst(engInfoBHMapper.selectList(new LambdaQueryWrapper<SdEngInfoBH>()
.select(SdEngInfoBH::getStcd)
.eq(SdEngInfoBH::getStcd, normalizedStationCode)
.eq(SdEngInfoBH::getRvcd, normalizedRvcd))) != null;
} }
@Override @Override
public boolean validateFpssBelongsToStation(String fpssCode, String stationCode) { public boolean validateFpssBelongsToStation(String fpssCode, String stationCode) {
if (fpssCode == null || stationCode == null) { String normalizedFpssCode = normalizeInput(fpssCode);
String normalizedStationCode = normalizeInput(stationCode);
if (!StringUtils.hasText(normalizedFpssCode) || !StringUtils.hasText(normalizedStationCode)) {
return false; return false;
} }
loadStationAndBaseCache(); return findFirst(fpssBHMapper.selectList(new LambdaQueryWrapper<SdFpssBH>()
String fpssLower = fpssCode.trim().toLowerCase(); .select(SdFpssBH::getStcd)
String cachedStationCode = FPSS_TO_STATION_CACHE.get(fpssLower); .eq(SdFpssBH::getStcd, normalizedFpssCode)
return stationCode.equalsIgnoreCase(cachedStationCode); .eq(SdFpssBH::getRstcd, normalizedStationCode))) != null;
}
private String normalizeInput(String value) {
return StringUtils.hasText(value) ? value.trim() : null;
}
private <T> T findFirst(List<T> list) {
return list == null || list.isEmpty() ? null : list.get(0);
} }
private String validateFishType(String fishName, FishImportResult.FishImportRow importRow) { private String validateFishType(String fishName, FishImportResult.FishImportRow importRow) {
@ -1762,4 +1857,4 @@ public class FishImportServiceImpl implements IFishImportService {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
} }