From 3ecc8ccf8b663fc0d379cb5acd342e2e08ffcbb2 Mon Sep 17 00:00:00 2001 From: tangwei Date: Fri, 3 Jul 2026 10:27:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yfd/platform/config/RedisConfig.java | 16 ++++++++++++---- .../service/impl/SdEngInfoBHServiceImpl.java | 8 ++++---- .../service/impl/SdHycdDicServiceImpl.java | 14 +++++++------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/com/yfd/platform/config/RedisConfig.java b/backend/src/main/java/com/yfd/platform/config/RedisConfig.java index e23850cb..94b9a0db 100644 --- a/backend/src/main/java/com/yfd/platform/config/RedisConfig.java +++ b/backend/src/main/java/com/yfd/platform/config/RedisConfig.java @@ -1,5 +1,7 @@ package com.yfd.platform.config; +import cn.hutool.crypto.digest.DigestUtil; +import cn.hutool.json.JSONUtil; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.ObjectMapper; @@ -23,6 +25,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; import java.time.Duration; import java.util.HashMap; import java.util.Map; +import java.util.UUID; @Configuration @EnableCaching @@ -61,9 +64,9 @@ public class RedisConfig { .entryTtl(Duration.ofMinutes(30)); Map cacheConfigs = new HashMap<>(); - cacheConfigs.put("dictCache", defaultConfig.entryTtl(Duration.ofHours(6))); - cacheConfigs.put("dataCache", defaultConfig.entryTtl(Duration.ofMinutes(5))); - cacheConfigs.put("engInfoCache", defaultConfig.entryTtl(Duration.ofHours(2))); +// cacheConfigs.put("dictCache", defaultConfig.entryTtl(Duration.ofHours(6))); +// cacheConfigs.put("dataCache", defaultConfig.entryTtl(Duration.ofMinutes(5))); +// cacheConfigs.put("engInfoCache", defaultConfig.entryTtl(Duration.ofHours(2))); return RedisCacheManager.builder(redisConnectionFactory) .cacheDefaults(defaultConfig) @@ -92,10 +95,15 @@ public class RedisConfig { sb.append(param != null ? param.toString() : "null"); sb.append(","); } - if (sb.length() > 0 && sb.charAt(sb.length() - 1) == ',') { + if (!sb.isEmpty() && sb.charAt(sb.length() - 1) == ',') { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }; } + + @Bean("cacheKeyGenerator") + public KeyGenerator cacheKeyGenerator() { + return (target, method, params) -> target.getClass().getName() + "." + method.getName() + ":" + DigestUtil.md5Hex(JSONUtil.toJsonStr(params)); + } } \ No newline at end of file diff --git a/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdEngInfoBHServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdEngInfoBHServiceImpl.java index e8921304..66b206ef 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdEngInfoBHServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdEngInfoBHServiceImpl.java @@ -106,25 +106,25 @@ public class SdEngInfoBHServiceImpl extends ServiceImpl getByBaseId(String baseId) { return engInfoBHMapper.selectByBaseId(baseId); } @Override - @Cacheable(cacheNames = "engInfoCache", key = "'eng:hycd:' + #hycd") + @Cacheable(cacheNames = "engInfoCache#3600", keyGenerator = "cacheKeyGenerator") public List getByHycd(String hycd) { return engInfoBHMapper.selectByHycd(hycd); } @Override - @Cacheable(cacheNames = "engInfoCache", key = "'eng:rvcd:' + #rvcd + ':' + #reachcd") + @Cacheable(cacheNames = "engInfoCache#3600", keyGenerator = "cacheKeyGenerator") public List getByRvcd(String rvcd,String reachcd) { return engInfoBHMapper.selectByRvcd(rvcd,reachcd); } @Override - @Cacheable(cacheNames = "engInfoCache", key = "'eng:dropdown:' + #sdEngInfoBHRequest.baseId + ':' + #sdEngInfoBHRequest.hbrvcd + ':' + #sdEngInfoBHRequest.rvcd + ':' + #sdEngInfoBHRequest.reachcd + ':' + #sdEngInfoBHRequest.ennm") + @Cacheable(cacheNames = "engInfoCache#3600", keyGenerator = "cacheKeyGenerator") public List selectForDropdown(SdEngInfoBHRequest sdEngInfoBHRequest) { String baseId = sdEngInfoBHRequest.getBaseId(); String hbrvcd = sdEngInfoBHRequest.getHbrvcd(); diff --git a/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdHycdDicServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdHycdDicServiceImpl.java index 96b2c3b2..5a5f3397 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdHycdDicServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_base/service/impl/SdHycdDicServiceImpl.java @@ -29,7 +29,7 @@ public class SdHycdDicServiceImpl extends ServiceImpl getByPhycd(String phycd) { return this.lambdaQuery() .eq(SdHycdDic::getPhycd, phycd) @@ -38,7 +38,7 @@ public class SdHycdDicServiceImpl extends ServiceImpl getRootList() { return this.lambdaQuery() .eq(SdHycdDic::getPhycd, "0") @@ -47,25 +47,25 @@ public class SdHycdDicServiceImpl extends ServiceImpl selectForDropdown(String hynm, Integer grd, Integer lx,String phycd) { return this.lambdaQuery() .like(hynm != null && !hynm.isEmpty(), SdHycdDic::getHynm, hynm) @@ -77,7 +77,7 @@ public class SdHycdDicServiceImpl extends ServiceImpl regDropdown(String hynm, Integer grd,Integer lx,String phycd) { return this.lambdaQuery() .like(hynm != null && !hynm.isEmpty(), SdHycdDic::getHynm, hynm)