From 1f302aefd634da665ef0b5338724d4d0117d2746 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Fri, 13 Feb 2026 12:06:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(scenic):=20=E6=B7=BB=E5=8A=A0=E6=99=AF?= =?UTF-8?q?=E5=8C=BA=E9=85=8D=E7=BD=AE=E5=92=8C=E6=9C=8D=E5=8A=A1=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=B8=85=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在创建配置后清理配置列表缓存 - 在更新配置后清理配置相关缓存 - 在删除配置后清理整个列表缓存 - 在批量更新配置后清理所有相关缓存 - 在更新景区信息后清理单个景区缓存 - 在删除景区后清理对应缓存 - 添加清除指定配置缓存的私有方法 - 添加清除景区所有配置缓存的私有方法 --- .../ScenicConfigIntegrationService.java | 34 +++++++++++++++++-- .../service/ScenicIntegrationService.java | 7 +++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ycwl/basic/integration/scenic/service/ScenicConfigIntegrationService.java b/src/main/java/com/ycwl/basic/integration/scenic/service/ScenicConfigIntegrationService.java index 9ff90e9c..5d0108b7 100644 --- a/src/main/java/com/ycwl/basic/integration/scenic/service/ScenicConfigIntegrationService.java +++ b/src/main/java/com/ycwl/basic/integration/scenic/service/ScenicConfigIntegrationService.java @@ -55,25 +55,53 @@ public class ScenicConfigIntegrationService { public ScenicConfigV2DTO createConfig(Long scenicId, CreateConfigRequest request) { log.debug("创建景区配置, scenicId: {}, configKey: {}", scenicId, request.getConfigKey()); CommonResponse response = scenicConfigV2Client.createConfig(scenicId, request); - return handleResponse(response, "创建景区配置失败"); + ScenicConfigV2DTO result = handleResponse(response, "创建景区配置失败"); + // 清理配置列表缓存 + clearConfigCache(scenicId, request.getConfigKey()); + return result; } public ScenicConfigV2DTO updateConfig(Long scenicId, String id, UpdateConfigRequest request) { log.debug("更新景区配置, scenicId: {}, id: {}", scenicId, id); CommonResponse response = scenicConfigV2Client.updateConfig(scenicId, id, request); - return handleResponse(response, "更新景区配置失败"); + ScenicConfigV2DTO result = handleResponse(response, "更新景区配置失败"); + // 清理配置相关缓存 + clearConfigCache(scenicId, request.getConfigKey()); + return result; } public void deleteConfig(Long scenicId, String id) { log.debug("删除景区配置, scenicId: {}, id: {}", scenicId, id); CommonResponse response = scenicConfigV2Client.deleteConfig(scenicId, id); handleResponse(response, "删除景区配置失败"); + // 清理配置列表缓存(无法确定具体key,清理整个列表缓存) + fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:configs:" + scenicId); } public BatchUpdateResponse batchUpdateConfigs(Long scenicId, BatchConfigRequest request) { log.debug("批量更新景区配置, scenicId: {}, configs count: {}", scenicId, request.getConfigs().size()); CommonResponse response = scenicConfigV2Client.batchUpdateConfigs(scenicId, request); - return handleResponse(response, "批量更新景区配置失败"); + BatchUpdateResponse result = handleResponse(response, "批量更新景区配置失败"); + // 清理所有相关缓存 + clearAllConfigCache(scenicId); + return result; + } + + /** + * 清理指定配置的缓存 + */ + private void clearConfigCache(Long scenicId, String configKey) { + fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:configs:" + scenicId); + if (configKey != null) { + fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:config:" + scenicId + ":" + configKey); + } + } + + /** + * 清理景区所有配置相关缓存 + */ + private void clearAllConfigCache(Long scenicId) { + fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:configs:" + scenicId); } diff --git a/src/main/java/com/ycwl/basic/integration/scenic/service/ScenicIntegrationService.java b/src/main/java/com/ycwl/basic/integration/scenic/service/ScenicIntegrationService.java index d55d2c87..3b7507ea 100644 --- a/src/main/java/com/ycwl/basic/integration/scenic/service/ScenicIntegrationService.java +++ b/src/main/java/com/ycwl/basic/integration/scenic/service/ScenicIntegrationService.java @@ -48,13 +48,18 @@ public class ScenicIntegrationService { public ScenicV2DTO updateScenic(Long scenicId, UpdateScenicRequest request) { log.debug("更新景区信息, scenicId: {}", scenicId); CommonResponse response = scenicV2Client.updateScenic(scenicId, request); - return handleResponse(response, "更新景区信息失败"); + ScenicV2DTO result = handleResponse(response, "更新景区信息失败"); + // 清理缓存,确保下次查询获取最新数据 + fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:" + scenicId); + return result; } public void deleteScenic(Long scenicId) { log.debug("删除景区, scenicId: {}", scenicId); CommonResponse response = scenicV2Client.deleteScenic(scenicId); handleResponse(response, "删除景区失败"); + // 清理缓存 + fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:" + scenicId); } public ScenicFilterPageResponse filterScenics(ScenicFilterRequest request) {