diff --git a/src/main/java/com/ycwl/basic/integration/device/service/DeviceDefaultConfigIntegrationService.java b/src/main/java/com/ycwl/basic/integration/device/service/DeviceDefaultConfigIntegrationService.java index 97ba52a9..1ad2d521 100644 --- a/src/main/java/com/ycwl/basic/integration/device/service/DeviceDefaultConfigIntegrationService.java +++ b/src/main/java/com/ycwl/basic/integration/device/service/DeviceDefaultConfigIntegrationService.java @@ -64,6 +64,8 @@ public class DeviceDefaultConfigIntegrationService { log.info("创建默认配置, configKey: {}", request.getConfigKey()); CommonResponse response = defaultConfigClient.createDefaultConfig(request); String result = handleResponse(response, "创建默认配置失败"); + // 清理相关缓存 + clearDefaultConfigCache(request.getConfigKey()); return result != null; } @@ -75,6 +77,9 @@ public class DeviceDefaultConfigIntegrationService { CommonResponse> response = defaultConfigClient.updateDefaultConfig(configKey, updates); Map result = handleResponse(response, "更新默认配置失败"); + // 清理相关缓存 + clearDefaultConfigCache(configKey); + // 检查是否有冲突信息 if (result != null && result.containsKey("conflict")) { Object conflictObj = result.get("conflict"); @@ -94,6 +99,8 @@ public class DeviceDefaultConfigIntegrationService { log.info("删除默认配置, configKey: {}", configKey); CommonResponse response = defaultConfigClient.deleteDefaultConfig(configKey); String result = handleResponse(response, "删除默认配置失败"); + // 清理相关缓存 + clearDefaultConfigCache(configKey); return result != null; } @@ -103,7 +110,26 @@ public class DeviceDefaultConfigIntegrationService { public BatchDefaultConfigResponse batchUpdateDefaultConfigs(BatchDefaultConfigRequest request) { log.info("批量更新默认配置, configs count: {}", request.getConfigs().size()); CommonResponse response = defaultConfigClient.batchUpdateDefaultConfigs(request); - return handleResponse(response, "批量更新默认配置失败"); + BatchDefaultConfigResponse result = handleResponse(response, "批量更新默认配置失败"); + // 清理所有默认配置相关缓存 + clearAllDefaultConfigCache(); + return result; + } + + /** + * 清理指定配置的缓存 + */ + private void clearDefaultConfigCache(String configKey) { + if (configKey != null) { + fallbackService.clearFallbackCache(SERVICE_NAME, "defaults:config:" + configKey); + } + } + + /** + * 清理所有默认配置缓存 + */ + private void clearAllDefaultConfigCache() { + fallbackService.clearAllFallbackCache(SERVICE_NAME); } /** diff --git a/src/main/java/com/ycwl/basic/integration/device/service/DeviceIntegrationService.java b/src/main/java/com/ycwl/basic/integration/device/service/DeviceIntegrationService.java index 0790b520..67e1b51d 100644 --- a/src/main/java/com/ycwl/basic/integration/device/service/DeviceIntegrationService.java +++ b/src/main/java/com/ycwl/basic/integration/device/service/DeviceIntegrationService.java @@ -58,12 +58,16 @@ public class DeviceIntegrationService { log.debug("更新设备信息, deviceId: {}", deviceId); CommonResponse response = deviceV2Client.updateDevice(deviceId, request); handleResponse(response, "更新设备信息失败"); + // 清理设备相关缓存 + fallbackService.clearFallbackCache(SERVICE_NAME, "device:" + deviceId); } public void deleteDevice(Long deviceId) { log.debug("删除设备, deviceId: {}", deviceId); CommonResponse response = deviceV2Client.deleteDevice(deviceId); handleResponse(response, "删除设备失败"); + // 清理设备相关缓存 + fallbackService.clearFallbackCache(SERVICE_NAME, "device:" + deviceId); } public PageResponse listDevices(Integer page, Integer pageSize, String name, String no, diff --git a/src/main/java/com/ycwl/basic/integration/profitshare/service/ProfitShareIntegrationService.java b/src/main/java/com/ycwl/basic/integration/profitshare/service/ProfitShareIntegrationService.java index 40a2347d..c9940579 100644 --- a/src/main/java/com/ycwl/basic/integration/profitshare/service/ProfitShareIntegrationService.java +++ b/src/main/java/com/ycwl/basic/integration/profitshare/service/ProfitShareIntegrationService.java @@ -83,7 +83,10 @@ public class ProfitShareIntegrationService { public RuleVO updateRule(Long ruleId, CreateRuleRequest request) { log.debug("更新分账规则, ruleId: {}", ruleId); CommonResponse response = profitShareClient.updateRule(ruleId, request); - return handleResponse(response, "更新分账规则失败"); + RuleVO result = handleResponse(response, "更新分账规则失败"); + // 清理规则缓存 + clearRuleCache(ruleId); + return result; } /** @@ -93,6 +96,8 @@ public class ProfitShareIntegrationService { log.debug("删除分账规则, ruleId: {}", ruleId); CommonResponse response = profitShareClient.deleteRule(ruleId); handleResponse(response, "删除分账规则失败"); + // 清理规则缓存 + clearRuleCache(ruleId); } /** @@ -102,6 +107,8 @@ public class ProfitShareIntegrationService { log.debug("启用分账规则, ruleId: {}", ruleId); CommonResponse response = profitShareClient.enableRule(ruleId); handleResponse(response, "启用分账规则失败"); + // 清理规则缓存 + clearRuleCache(ruleId); } /** @@ -111,6 +118,8 @@ public class ProfitShareIntegrationService { log.debug("禁用分账规则, ruleId: {}", ruleId); CommonResponse response = profitShareClient.disableRule(ruleId); handleResponse(response, "禁用分账规则失败"); + // 清理规则缓存 + clearRuleCache(ruleId); } // ==================== 分账记录查询 ==================== @@ -211,6 +220,13 @@ public class ProfitShareIntegrationService { // ==================== 私有方法 ==================== + /** + * 清理规则相关缓存 + */ + private void clearRuleCache(Long ruleId) { + fallbackService.clearFallbackCache(SERVICE_NAME, "rule:" + ruleId); + } + private T handleResponse(CommonResponse response, String errorMessage) { if (response == null || !response.isSuccess()) { String msg = response != null && response.getMessage() != null