From a623c90f2168a35d13caa4b9a4443aa706673801 Mon Sep 17 00:00:00 2001 From: tangwei Date: Wed, 6 May 2026 18:44:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/FishDraftDataServiceImpl.java | 5 +- .../service/impl/FishImportServiceImpl.java | 85 ++++++++++++++++--- .../service/impl/SdEngInfoBHServiceImpl.java | 27 +++++- .../env/service/impl/SdFpssBHServiceImpl.java | 28 +++++- .../service/impl/SdHbrvDicServiceImpl.java | 28 +++++- .../service/impl/SdHydrobaseServiceImpl.java | 26 +++++- 6 files changed, 175 insertions(+), 24 deletions(-) diff --git a/backend/src/main/java/com/yfd/platform/data/service/impl/FishDraftDataServiceImpl.java b/backend/src/main/java/com/yfd/platform/data/service/impl/FishDraftDataServiceImpl.java index e696a84..b863e33 100644 --- a/backend/src/main/java/com/yfd/platform/data/service/impl/FishDraftDataServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/data/service/impl/FishDraftDataServiceImpl.java @@ -85,7 +85,9 @@ public class FishDraftDataServiceImpl extends ServiceImpl FPSS_TO_STATION_CACHE = new LinkedHashMap<>(); private static final Map ISFS_DICT_CACHE = new LinkedHashMap<>(); + private static final long CACHE_EXPIRE_MILLIS = 10 * 60 * 1000; + private static long stationCacheTimestamp = 0; + private static long baseCacheTimestamp = 0; + private static long riverCacheTimestamp = 0; + private static long hbrvcdCacheTimestamp = 0; + private static long fishDictCacheTimestamp = 0; + private static long fpssCacheTimestamp = 0; + private static final String DICT_CODE_FISH = "FISH_TYPE"; private static final String DICT_CODE_DIRECTION = "FISH_DIRECTION"; private static final String DICT_CODE_ISFS = "YES_NO"; @@ -524,7 +532,14 @@ public class FishImportServiceImpl implements IFishImportService { } } - if (STATION_NAME_CACHE.isEmpty()&&!allStcdSet.isEmpty()) { + boolean stationCacheExpired = isCacheExpired(stationCacheTimestamp); + if (STATION_NAME_CACHE.isEmpty() || stationCacheExpired) { + if (stationCacheExpired) { + STATION_NAME_CACHE.clear(); + STATION_CODE_TO_NAME_CACHE.clear(); + STATION_TO_BASE_CACHE.clear(); + } + List stationList; if (!allStcdSet.isEmpty()) { stationList = engInfoBHMapper.selectBatchIds(new ArrayList<>(allStcdSet)); @@ -545,9 +560,16 @@ public class FishImportServiceImpl implements IFishImportService { } } } + stationCacheTimestamp = System.currentTimeMillis(); } - if (BASE_NAME_CACHE.isEmpty()) { + boolean baseCacheExpired = isCacheExpired(baseCacheTimestamp); + if (BASE_NAME_CACHE.isEmpty() || baseCacheExpired) { + if (baseCacheExpired) { + BASE_NAME_CACHE.clear(); + BASE_CODE_TO_NAME_CACHE.clear(); + } + List baseList = hydrobaseMapper.selectList(null); for (SdHydrobase base : baseList) { if (StringUtils.hasText(base.getBasename())) { @@ -559,9 +581,16 @@ public class FishImportServiceImpl implements IFishImportService { } } } + baseCacheTimestamp = System.currentTimeMillis(); } - if (RIVER_NAME_CACHE.isEmpty()) { + boolean riverCacheExpired = isCacheExpired(riverCacheTimestamp); + if (RIVER_NAME_CACHE.isEmpty() || riverCacheExpired) { + if (riverCacheExpired) { + RIVER_NAME_CACHE.clear(); + RIVER_CODE_TO_NAME_CACHE.clear(); + } + List riverList = rvcdDicMapper.selectList(null); for (SdRvcdDic river : riverList) { if (StringUtils.hasText(river.getRvnm())) { @@ -573,13 +602,24 @@ public class FishImportServiceImpl implements IFishImportService { } } } + riverCacheTimestamp = System.currentTimeMillis(); } - if (HBRVCD_NAME_CACHE.isEmpty()&&!allowedHbrvcdSet.isEmpty()) { + boolean hbrvcdCacheExpired = isCacheExpired(hbrvcdCacheTimestamp); + if (HBRVCD_NAME_CACHE.isEmpty() || hbrvcdCacheExpired) { + if (hbrvcdCacheExpired) { + HBRVCD_NAME_CACHE.clear(); + HBRVCD_CODE_TO_NAME_CACHE.clear(); + } + List riverList; - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.in(SdHbrvDic::getHbrvcd, allowedHbrvcdSet); - riverList = sdHbrvDicMapper.selectList(wrapper); + if (!allowedHbrvcdSet.isEmpty()) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.in(SdHbrvDic::getHbrvcd, allowedHbrvcdSet); + riverList = sdHbrvDicMapper.selectList(wrapper); + } else { + riverList = sdHbrvDicMapper.selectList(null); + } for (SdHbrvDic river : riverList) { if (StringUtils.hasText(river.getHbrvnm())) { HBRVCD_NAME_CACHE.put(river.getHbrvnm().trim().toLowerCase(), river.getHbrvcd()); @@ -590,9 +630,16 @@ public class FishImportServiceImpl implements IFishImportService { } } } + hbrvcdCacheTimestamp = System.currentTimeMillis(); } - if (FISH_DICT_CACHE.isEmpty()) { + boolean fishDictCacheExpired = isCacheExpired(fishDictCacheTimestamp); + if (FISH_DICT_CACHE.isEmpty() || fishDictCacheExpired) { + if (fishDictCacheExpired) { + FISH_DICT_CACHE.clear(); + FISH_CODE_TO_NAME_CACHE.clear(); + } + List sdFishDictoryBS = fishDictoryBMapper.selectList(null); for (SdFishDictoryB fishDictoryB : sdFishDictoryBS) { if (StringUtils.hasText(fishDictoryB.getName())) { @@ -604,10 +651,23 @@ public class FishImportServiceImpl implements IFishImportService { } } } + fishDictCacheTimestamp = System.currentTimeMillis(); } - if (FPSS_BH_CACHE.isEmpty()&&!directStcdSet.isEmpty()) { - List sdFpssBHS = fpssBHMapper.selectList(new LambdaQueryWrapper().in(SdFpssBH::getStcd, directStcdSet)); + boolean fpssCacheExpired = isCacheExpired(fpssCacheTimestamp); + if (FPSS_BH_CACHE.isEmpty() || fpssCacheExpired) { + if (fpssCacheExpired) { + FPSS_BH_CACHE.clear(); + FPSS_CODE_TO_NAME_CACHE.clear(); + FPSS_TO_STATION_CACHE.clear(); + } + + List sdFpssBHS; + if (!allStcdSet.isEmpty()) { + sdFpssBHS = fpssBHMapper.selectList(new LambdaQueryWrapper().in(SdFpssBH::getStcd, allStcdSet)); + } else { + sdFpssBHS = fpssBHMapper.selectList(null); + } for (SdFpssBH sdFpssBH : sdFpssBHS) { if (StringUtils.hasText(sdFpssBH.getStnm())) { FPSS_BH_CACHE.put(sdFpssBH.getStnm().trim().toLowerCase(), sdFpssBH.getStcd()); @@ -621,9 +681,14 @@ public class FishImportServiceImpl implements IFishImportService { } } } + fpssCacheTimestamp = System.currentTimeMillis(); } } + private boolean isCacheExpired(long timestamp) { + return System.currentTimeMillis() - timestamp > CACHE_EXPIRE_MILLIS; + } + public String resolveStationCode(String stationName) { if (stationName == null) { diff --git a/backend/src/main/java/com/yfd/platform/env/service/impl/SdEngInfoBHServiceImpl.java b/backend/src/main/java/com/yfd/platform/env/service/impl/SdEngInfoBHServiceImpl.java index a1a2cce..7f6e10b 100644 --- a/backend/src/main/java/com/yfd/platform/env/service/impl/SdEngInfoBHServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/env/service/impl/SdEngInfoBHServiceImpl.java @@ -104,17 +104,38 @@ public class SdEngInfoBHServiceImpl extends ServiceImpl(); } + Set stationCodes = new HashSet<>(); - List basinCodes = new ArrayList<>(); + Set basinCodes = new HashSet<>(); for (SysUserDataScope scope : sysUserDataScopes) { String orgType = scope.getOrgType(); String orgId = scope.getOrgId(); if ("STATION".equals(orgType)) { - stationCodes.add(orgId); + SdEngInfoBH station = engInfoBHMapper.selectById(orgId); + if (station != null) { + if (station.getHbrvcd() != null) { + basinCodes.add(station.getHbrvcd()); + } + if (station.getStcd() != null) { + stationCodes.add(station.getStcd()); + } + + } } else if ("HBRVCD".equals(orgType)) { - basinCodes.add(orgId); + List stationList = engInfoBHMapper.selectByHbrvcd(orgId); + if (stationList != null) { + for (SdEngInfoBH station : stationList) { + if (station.getStcd() != null) { + stationCodes.add(station.getStcd()); + } + if (station.getEnnm() != null) { + basinCodes.add(station.getHbrvcd()); + } + } + } + } } diff --git a/backend/src/main/java/com/yfd/platform/env/service/impl/SdFpssBHServiceImpl.java b/backend/src/main/java/com/yfd/platform/env/service/impl/SdFpssBHServiceImpl.java index 40e2cde..036578e 100644 --- a/backend/src/main/java/com/yfd/platform/env/service/impl/SdFpssBHServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/env/service/impl/SdFpssBHServiceImpl.java @@ -102,20 +102,40 @@ public class SdFpssBHServiceImpl extends ServiceImpl i return new HashSet<>(); } + Set stationCodes = new HashSet<>(); - List basinCodes = new ArrayList<>(); + Set basinCodes = new HashSet<>(); for (SysUserDataScope scope : sysUserDataScopes) { String orgType = scope.getOrgType(); String orgId = scope.getOrgId(); if ("STATION".equals(orgType)) { - stationCodes.add(orgId); + SdEngInfoBH station = sdEngInfoBHMapper.selectById(orgId); + if (station != null) { + if (station.getHbrvcd() != null) { + basinCodes.add(station.getHbrvcd()); + } + if (station.getStcd() != null) { + stationCodes.add(station.getStcd()); + } + + } } else if ("HBRVCD".equals(orgType)) { - basinCodes.add(orgId); + List stationList = sdEngInfoBHMapper.selectByHbrvcd(orgId); + if (stationList != null) { + for (SdEngInfoBH station : stationList) { + if (station.getStcd() != null) { + stationCodes.add(station.getStcd()); + } + if (station.getEnnm() != null) { + basinCodes.add(station.getHbrvcd()); + } + } + } + } } - if (!stationCodes.isEmpty()) { return stationCodes; } diff --git a/backend/src/main/java/com/yfd/platform/env/service/impl/SdHbrvDicServiceImpl.java b/backend/src/main/java/com/yfd/platform/env/service/impl/SdHbrvDicServiceImpl.java index e3ccf55..da19175 100644 --- a/backend/src/main/java/com/yfd/platform/env/service/impl/SdHbrvDicServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/env/service/impl/SdHbrvDicServiceImpl.java @@ -33,6 +33,8 @@ public class SdHbrvDicServiceImpl extends ServiceImpl queryPageList(Page page, String hbrvnm, String baseid) { return this.page(page, this.lambdaQuery() @@ -133,16 +135,36 @@ public class SdHbrvDicServiceImpl extends ServiceImpl stationCodes = new HashSet<>(); - List basinCodes = new ArrayList<>(); + Set basinCodes = new HashSet<>(); for (SysUserDataScope scope : sysUserDataScopes) { String orgType = scope.getOrgType(); String orgId = scope.getOrgId(); if ("STATION".equals(orgType)) { - stationCodes.add(orgId); + SdEngInfoBH station = engInfoBHMapper.selectById(orgId); + if (station != null) { + if (station.getHbrvcd() != null) { + basinCodes.add(station.getHbrvcd()); + } + if (station.getStcd() != null) { + stationCodes.add(station.getStcd()); + } + + } } else if ("HBRVCD".equals(orgType)) { - basinCodes.add(orgId); + List stationList = engInfoBHMapper.selectByHbrvcd(orgId); + if (stationList != null) { + for (SdEngInfoBH station : stationList) { + if (station.getStcd() != null) { + stationCodes.add(station.getStcd()); + } + if (station.getEnnm() != null) { + basinCodes.add(station.getHbrvcd()); + } + } + } + } } diff --git a/backend/src/main/java/com/yfd/platform/env/service/impl/SdHydrobaseServiceImpl.java b/backend/src/main/java/com/yfd/platform/env/service/impl/SdHydrobaseServiceImpl.java index ed4e3a4..1a0b460 100644 --- a/backend/src/main/java/com/yfd/platform/env/service/impl/SdHydrobaseServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/env/service/impl/SdHydrobaseServiceImpl.java @@ -111,16 +111,36 @@ public class SdHydrobaseServiceImpl extends ServiceImpl stationCodes = new HashSet<>(); - List basinCodes = new ArrayList<>(); + Set basinCodes = new HashSet<>(); for (SysUserDataScope scope : sysUserDataScopes) { String orgType = scope.getOrgType(); String orgId = scope.getOrgId(); if ("STATION".equals(orgType)) { - stationCodes.add(orgId); + SdEngInfoBH station = sdEngInfoBHMapper.selectById(orgId); + if (station != null) { + if (station.getHbrvcd() != null) { + basinCodes.add(station.getHbrvcd()); + } + if (station.getStcd() != null) { + stationCodes.add(station.getStcd()); + } + + } } else if ("HBRVCD".equals(orgType)) { - basinCodes.add(orgId); + List stationList = sdEngInfoBHMapper.selectByHbrvcd(orgId); + if (stationList != null) { + for (SdEngInfoBH station : stationList) { + if (station.getStcd() != null) { + stationCodes.add(station.getStcd()); + } + if (station.getEnnm() != null) { + basinCodes.add(station.getHbrvcd()); + } + } + } + } }