From e8c645a3c0c0705d4524437cdff423343e0e22e2 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Fri, 10 Oct 2025 23:55:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor(device):=20=E7=A7=BB=E9=99=A4=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E4=B8=8E=E6=99=AF=E5=8C=BA=E7=9A=84=E5=86=97=E4=BD=99?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 DeviceV2Controller 中的设备配置相关接口 - 删除 ScenicV2Controller 中的景区配置相关接口 - 移除 DeviceConfigV2Client 中的扁平化配置接口 - 移除 DeviceV2Client 中的设备详情配置接口 - 更新 DeviceIntegrationExample 示例代码 - 移除 DeviceIntegrationFallbackExample 中的配置缓存示例 - 删除 DeviceConfigIntegrationService 中的配置获取方法 - 删除 DeviceIntegrationService 中的设备配置服务方法- 移除 RenderWorkerV2Client 中的工作器配置接口- 删除 RenderWorkerConfigIntegrationService 中的配置键名- 移除 RenderWorkerIntegrationService 中的工作器配置方法 - 删除 ScenicConfigV2Client 中的扁平化配置接口 - 移除 ScenicV2Client 中的景区配置接口 - 更新 ScenicIntegrationExample 示例代码 - 删除 ScenicConfigIntegrationService 中的配置获取方法 - 删除 ScenicIntegrationService 中的景区配置服务方法 - 修改 ScenicRepository 中景区实体获取逻辑 --- .../controller/pc/DeviceV2Controller.java | 85 ------------------- .../controller/pc/ScenicV2Controller.java | 70 --------------- .../device/client/DeviceConfigV2Client.java | 14 +-- .../device/client/DeviceV2Client.java | 29 +------ .../example/DeviceIntegrationExample.java | 12 +-- .../DeviceIntegrationFallbackExample.java | 7 -- .../DeviceConfigIntegrationService.java | 25 ------ .../service/DeviceIntegrationService.java | 35 -------- .../render/client/RenderWorkerV2Client.java | 26 +----- .../RenderWorkerConfigIntegrationService.java | 2 +- .../RenderWorkerIntegrationService.java | 44 ---------- .../scenic/client/ScenicConfigV2Client.java | 7 -- .../scenic/client/ScenicV2Client.java | 10 --- .../example/ScenicIntegrationExample.java | 33 +++---- .../ScenicConfigIntegrationService.java | 19 ----- .../service/ScenicIntegrationService.java | 32 ------- .../basic/repository/ScenicRepository.java | 23 ++++- 17 files changed, 43 insertions(+), 430 deletions(-) diff --git a/src/main/java/com/ycwl/basic/controller/pc/DeviceV2Controller.java b/src/main/java/com/ycwl/basic/controller/pc/DeviceV2Controller.java index f90679af..784e1269 100644 --- a/src/main/java/com/ycwl/basic/controller/pc/DeviceV2Controller.java +++ b/src/main/java/com/ycwl/basic/controller/pc/DeviceV2Controller.java @@ -63,34 +63,6 @@ public class DeviceV2Controller { } } - /** - * 设备V2带配置信息分页列表 - */ - @GetMapping("/with-config") - public ApiResponse> listDevicesWithConfig(@RequestParam(defaultValue = "1") Integer page, - @RequestParam(defaultValue = "10") Integer pageSize, - @RequestParam(required = false) String name, - @RequestParam(required = false) String no, - @RequestParam(required = false) String type, - @RequestParam(required = false) Integer isActive, - @RequestParam(required = false) Long scenicId) { - log.info("分页查询设备带配置信息列表, page: {}, pageSize: {}, name: {}, no: {}, type: {}, isActive: {}, scenicId: {}", - page, pageSize, name, no, type, isActive, scenicId); - - // 参数验证:限制pageSize最大值为100 - if (pageSize > 100) { - pageSize = 100; - } - - try { - PageResponse response = deviceIntegrationService.listDevicesWithConfig(page, pageSize, name, no, type, isActive, scenicId); - return ApiResponse.success(response); - } catch (Exception e) { - log.error("分页查询设备带配置信息列表失败", e); - return ApiResponse.fail("分页查询设备带配置信息列表失败: " + e.getMessage()); - } - } - /** * 根据ID获取设备信息 */ @@ -105,20 +77,6 @@ public class DeviceV2Controller { } } - /** - * 根据ID获取设备带配置信息 - */ - @GetMapping("/{id}/with-config") - public ApiResponse getDeviceWithConfig(@PathVariable Long id) { - try { - DeviceV2WithConfigDTO device = deviceIntegrationService.getDeviceWithConfig(id); - return ApiResponse.success(device); - } catch (Exception e) { - log.error("获取设备配置信息失败, id: {}", id, e); - return ApiResponse.fail("获取设备配置信息失败: " + e.getMessage()); - } - } - /** * 根据设备编号获取设备信息 */ @@ -133,20 +91,6 @@ public class DeviceV2Controller { } } - /** - * 根据设备编号获取设备带配置信息 - */ - @GetMapping("/no/{no}/with-config") - public ApiResponse getDeviceWithConfigByNo(@PathVariable String no) { - try { - DeviceV2WithConfigDTO device = deviceIntegrationService.getDeviceWithConfigByNo(no); - return ApiResponse.success(device); - } catch (Exception e) { - log.error("根据设备编号获取设备配置信息失败, no: {}", no, e); - return ApiResponse.fail("根据设备编号获取设备配置信息失败: " + e.getMessage()); - } - } - /** * 根据设备ID获取设备在线状态 */ @@ -327,20 +271,6 @@ public class DeviceV2Controller { } } - /** - * 获取设备扁平化配置 - */ - @GetMapping("/{id}/flat-config") - public ApiResponse> getDeviceFlatConfig(@PathVariable Long id) { - try { - Map config = deviceConfigIntegrationService.getDeviceFlatConfig(id); - return ApiResponse.success(config); - } catch (Exception e) { - log.error("获取设备扁平化配置失败, deviceId: {}", id, e); - return ApiResponse.fail("获取设备扁平化配置失败: " + e.getMessage()); - } - } - /** * 根据配置键获取配置 */ @@ -371,21 +301,6 @@ public class DeviceV2Controller { } } - /** - * 根据设备编号获取扁平化配置 - */ - @GetMapping("/no/{no}/flat-config") - public ApiResponse> getDeviceFlatConfigByNo(@PathVariable String no) { - log.info("根据设备编号获取扁平化配置, deviceNo: {}", no); - try { - Map config = deviceConfigIntegrationService.getDeviceFlatConfigByNo(no); - return ApiResponse.success(config); - } catch (Exception e) { - log.error("根据设备编号获取扁平化配置失败, deviceNo: {}", no, e); - return ApiResponse.fail("根据设备编号获取扁平化配置失败: " + e.getMessage()); - } - } - /** * 创建设备配置 */ diff --git a/src/main/java/com/ycwl/basic/controller/pc/ScenicV2Controller.java b/src/main/java/com/ycwl/basic/controller/pc/ScenicV2Controller.java index 15a3e423..2205fb1d 100644 --- a/src/main/java/com/ycwl/basic/controller/pc/ScenicV2Controller.java +++ b/src/main/java/com/ycwl/basic/controller/pc/ScenicV2Controller.java @@ -71,30 +71,6 @@ public class ScenicV2Controller { } } - /** - * 景区V2带配置信息分页列表 - */ - @GetMapping("/with-config") - public ApiResponse> listScenicsWithConfig(@RequestParam(defaultValue = "1") Integer page, - @RequestParam(defaultValue = "10") Integer pageSize, - @RequestParam(required = false) Integer status, - @RequestParam(required = false) String name) { - log.info("分页查询景区带配置信息列表, page: {}, pageSize: {}, status: {}, name: {}", page, pageSize, status, name); - - // 参数验证:限制pageSize最大值为100 - if (pageSize > 100) { - pageSize = 100; - } - - try { - PageResponse response = scenicIntegrationService.listScenicsWithConfig(page, pageSize, status, name); - return ApiResponse.success(response); - } catch (Exception e) { - log.error("分页查询景区带配置信息列表失败", e); - return ApiResponse.fail("分页查询景区带配置信息列表失败: " + e.getMessage()); - } - } - /** * 查询单个景区详情 */ @@ -192,36 +168,6 @@ public class ScenicV2Controller { // ========== 景区配置管理 ========== - /** - * 获取景区及其配置信息 - */ - @GetMapping("/{scenicId}/with-config") - public ApiResponse getScenicWithConfig(@PathVariable Long scenicId) { - log.info("获取景区配置信息, scenicId: {}", scenicId); - try { - ScenicV2WithConfigDTO scenic = scenicIntegrationService.getScenicWithConfig(scenicId); - return ApiResponse.success(scenic); - } catch (Exception e) { - log.error("获取景区配置信息失败, scenicId: {}", scenicId, e); - return ApiResponse.fail("获取景区配置信息失败: " + e.getMessage()); - } - } - - /** - * 获取景区扁平化配置 - */ - @GetMapping("/{scenicId}/flat-config") - public ApiResponse> getScenicFlatConfig(@PathVariable Long scenicId) { - log.info("获取景区扁平化配置, scenicId: {}", scenicId); - try { - Map config = scenicIntegrationService.getScenicFlatConfig(scenicId); - return ApiResponse.success(config); - } catch (Exception e) { - log.error("获取景区扁平化配置失败, scenicId: {}", scenicId, e); - return ApiResponse.fail("获取景区扁平化配置失败: " + e.getMessage()); - } - } - /** * 获取景区配置列表 */ @@ -316,20 +262,4 @@ public class ScenicV2Controller { return ApiResponse.fail("批量更新配置失败: " + e.getMessage()); } } - - /** - * 扁平化批量更新景区配置 - */ - @PutMapping("/{scenicId}/flat-config") - public ApiResponse batchFlatUpdateConfigs(@PathVariable Long scenicId, - @RequestBody Map configs) { - log.info("扁平化批量更新景区配置, scenicId: {}, configs count: {}", scenicId, configs.size()); - try { - BatchUpdateResponse response = scenicConfigIntegrationService.batchFlatUpdateConfigs(scenicId, configs); - return ApiResponse.success(response); - } catch (Exception e) { - log.error("扁平化批量更新景区配置失败, scenicId: {}", scenicId, e); - return ApiResponse.fail("扁平化批量更新配置失败: " + e.getMessage()); - } - } } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/integration/device/client/DeviceConfigV2Client.java b/src/main/java/com/ycwl/basic/integration/device/client/DeviceConfigV2Client.java index 86afa902..6f787582 100644 --- a/src/main/java/com/ycwl/basic/integration/device/client/DeviceConfigV2Client.java +++ b/src/main/java/com/ycwl/basic/integration/device/client/DeviceConfigV2Client.java @@ -29,19 +29,7 @@ public interface DeviceConfigV2Client { @GetMapping("/{deviceId}/key/{configKey}") CommonResponse getDeviceConfigByKey(@PathVariable("deviceId") Long deviceId, @PathVariable("configKey") String configKey); - - /** - * 获取设备扁平化配置 - */ - @GetMapping("/{deviceId}/flat") - CommonResponse> getDeviceFlatConfig(@PathVariable("deviceId") Long deviceId); - - /** - * 根据设备编号获取设备扁平化配置 - */ - @GetMapping("/no/{no}/flat") - CommonResponse> getDeviceFlatConfigByNo(@PathVariable("no") String no); - + /** * 创建设备配置 */ diff --git a/src/main/java/com/ycwl/basic/integration/device/client/DeviceV2Client.java b/src/main/java/com/ycwl/basic/integration/device/client/DeviceV2Client.java index 694cc525..c7351cbf 100644 --- a/src/main/java/com/ycwl/basic/integration/device/client/DeviceV2Client.java +++ b/src/main/java/com/ycwl/basic/integration/device/client/DeviceV2Client.java @@ -20,19 +20,7 @@ public interface DeviceV2Client { */ @GetMapping("/no/{no}") CommonResponse getDeviceByNo(@PathVariable("no") String no); - - /** - * 获取设备详细信息(含配置) - */ - @GetMapping("/{id}/with-config") - CommonResponse getDeviceWithConfig(@PathVariable("id") Long id); - - /** - * 根据设备编号获取设备详细信息(含配置) - */ - @GetMapping("/no/{no}/with-config") - CommonResponse getDeviceByNoWithConfig(@PathVariable("no") String no); - + /** * 创建设备 */ @@ -64,20 +52,7 @@ public interface DeviceV2Client { @RequestParam(value = "type", required = false) String type, @RequestParam(value = "isActive", required = false) Integer isActive, @RequestParam(value = "scenicId", required = false) Long scenicId); - - /** - * 分页获取设备列表(含配置) - */ - @GetMapping("/with-config") - CommonResponse> listDevicesWithConfig( - @RequestParam(value = "page", defaultValue = "1") Integer page, - @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, - @RequestParam(value = "name", required = false) String name, - @RequestParam(value = "no", required = false) String no, - @RequestParam(value = "type", required = false) String type, - @RequestParam(value = "isActive", required = false) Integer isActive, - @RequestParam(value = "scenicId", required = false) Long scenicId); - + /** * 根据配置条件筛选设备 */ diff --git a/src/main/java/com/ycwl/basic/integration/device/example/DeviceIntegrationExample.java b/src/main/java/com/ycwl/basic/integration/device/example/DeviceIntegrationExample.java index 638a7eed..84dce6a7 100644 --- a/src/main/java/com/ycwl/basic/integration/device/example/DeviceIntegrationExample.java +++ b/src/main/java/com/ycwl/basic/integration/device/example/DeviceIntegrationExample.java @@ -41,11 +41,7 @@ public class DeviceIntegrationExample { // 根据设备编号获取设备信息 DeviceV2DTO deviceByNo = deviceService.getDeviceByNo("CAM001"); log.info("根据编号获取设备: {}", deviceByNo.getName()); - - // 获取设备详细信息(含配置) - DeviceV2WithConfigDTO deviceWithConfig = deviceService.getDeviceWithConfig(ipcDevice.getId()); - log.info("获取设备配置: {}", deviceWithConfig.getName()); - + // 分页查询景区设备列表 PageResponse deviceList = deviceService.getScenicIpcDevices(1001L, 1, 10); log.info("景区设备列表: 总数={}", deviceList.getTotal()); @@ -105,11 +101,7 @@ public class DeviceIntegrationExample { // 获取设备所有配置 List configs = deviceConfigService.getDeviceConfigs(deviceId); log.info("设备配置数量: {}", configs.size()); - - // 获取扁平化配置 - Map flatConfig = deviceConfigService.getDeviceFlatConfig(deviceId); - log.info("扁平化配置项数: {}", flatConfig.size()); - + // 使用批量配置API BatchDeviceConfigRequest builderRequest = deviceConfigService.createBatchConfigBuilder() .build(); diff --git a/src/main/java/com/ycwl/basic/integration/device/example/DeviceIntegrationFallbackExample.java b/src/main/java/com/ycwl/basic/integration/device/example/DeviceIntegrationFallbackExample.java index 4429f127..192ab55d 100644 --- a/src/main/java/com/ycwl/basic/integration/device/example/DeviceIntegrationFallbackExample.java +++ b/src/main/java/com/ycwl/basic/integration/device/example/DeviceIntegrationFallbackExample.java @@ -43,10 +43,6 @@ public class DeviceIntegrationFallbackExample { DeviceV2DTO deviceByNo = deviceService.getDeviceByNo(deviceNo); log.info("根据设备号获取设备成功: {}", deviceByNo.getName()); - // 获取设备配置 - 自动降级 - DeviceV2WithConfigDTO deviceWithConfig = deviceService.getDeviceWithConfig(deviceId); - log.info("获取设备配置成功,配置数量: {}", deviceWithConfig.getConfig().size()); - } catch (Exception e) { log.error("所有降级策略失败", e); } @@ -83,14 +79,11 @@ public class DeviceIntegrationFallbackExample { log.info("=== 降级缓存管理示例 ==="); String deviceCacheKey = "device:1001"; - String configCacheKey = "device:flat:config:1001"; // 检查降级缓存状态 boolean hasDeviceCache = fallbackService.hasFallbackCache(SERVICE_NAME, deviceCacheKey); - boolean hasConfigCache = fallbackService.hasFallbackCache(SERVICE_NAME, configCacheKey); log.info("设备降级缓存存在: {}", hasDeviceCache); - log.info("配置降级缓存存在: {}", hasConfigCache); // 清理特定的降级缓存 if (hasDeviceCache) { diff --git a/src/main/java/com/ycwl/basic/integration/device/service/DeviceConfigIntegrationService.java b/src/main/java/com/ycwl/basic/integration/device/service/DeviceConfigIntegrationService.java index 828c6294..4379b6d6 100644 --- a/src/main/java/com/ycwl/basic/integration/device/service/DeviceConfigIntegrationService.java +++ b/src/main/java/com/ycwl/basic/integration/device/service/DeviceConfigIntegrationService.java @@ -39,31 +39,6 @@ public class DeviceConfigIntegrationService { return handleResponse(response, "根据键获取设备配置失败"); } - public Map getDeviceFlatConfig(Long deviceId) { - return fallbackService.executeWithFallback( - SERVICE_NAME, - "device:flat:config:" + deviceId, - () -> { - CommonResponse> response = deviceConfigV2Client.getDeviceFlatConfig(deviceId); - return handleResponse(response, "获取设备扁平化配置失败"); - }, - Map.class - ); - } - - public Map getDeviceFlatConfigByNo(String deviceNo) { - log.debug("根据设备编号获取扁平化配置, deviceNo: {}", deviceNo); - return fallbackService.executeWithFallback( - SERVICE_NAME, - "device:flat:config:no:" + deviceNo, - () -> { - CommonResponse> response = deviceConfigV2Client.getDeviceFlatConfigByNo(deviceNo); - return handleResponse(response, "根据设备编号获取扁平化配置失败"); - }, - Map.class - ); - } - public DeviceConfigV2DTO createDeviceConfig(Long deviceId, CreateDeviceConfigRequest request) { log.debug("创建设备配置, deviceId: {}, configKey: {}", deviceId, request.getConfigKey()); CommonResponse response = deviceConfigV2Client.createDeviceConfig(deviceId, request); 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 25d82a83..b616c728 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 @@ -48,32 +48,6 @@ public class DeviceIntegrationService { ); } - public DeviceV2WithConfigDTO getDeviceWithConfig(Long deviceId) { - log.debug("获取设备配置信息, deviceId: {}", deviceId); - return fallbackService.executeWithFallback( - SERVICE_NAME, - "device:config:" + deviceId, - () -> { - CommonResponse response = deviceV2Client.getDeviceWithConfig(deviceId); - return handleResponse(response, "获取设备配置信息失败"); - }, - DeviceV2WithConfigDTO.class - ); - } - - public DeviceV2WithConfigDTO getDeviceWithConfigByNo(String deviceNo) { - log.debug("根据设备编号获取设备配置信息, deviceNo: {}", deviceNo); - return fallbackService.executeWithFallback( - SERVICE_NAME, - "device:config:no:" + deviceNo, - () -> { - CommonResponse response = deviceV2Client.getDeviceByNoWithConfig(deviceNo); - return handleResponse(response, "根据设备编号获取设备配置信息失败"); - }, - DeviceV2WithConfigDTO.class - ); - } - public DeviceV2DTO createDevice(CreateDeviceRequest request) { log.debug("创建设备, name: {}, no: {}, type: {}", request.getName(), request.getNo(), request.getType()); CommonResponse response = deviceV2Client.createDevice(request); @@ -101,15 +75,6 @@ public class DeviceIntegrationService { return handleResponse(response, "分页查询设备列表失败"); } - public PageResponse listDevicesWithConfig(Integer page, Integer pageSize, String name, String no, - String type, Integer isActive, Long scenicId) { - log.debug("分页查询设备带配置列表, page: {}, pageSize: {}, name: {}, no: {}, type: {}, isActive: {}, scenicId: {}", - page, pageSize, name, no, type, isActive, scenicId); - CommonResponse> response = deviceV2Client.listDevicesWithConfig( - page, pageSize, name, no, type, isActive, scenicId); - return handleResponse(response, "分页查询设备带配置列表失败"); - } - /** * 创建IPC摄像头设备 */ diff --git a/src/main/java/com/ycwl/basic/integration/render/client/RenderWorkerV2Client.java b/src/main/java/com/ycwl/basic/integration/render/client/RenderWorkerV2Client.java index c6c923ce..04389236 100644 --- a/src/main/java/com/ycwl/basic/integration/render/client/RenderWorkerV2Client.java +++ b/src/main/java/com/ycwl/basic/integration/render/client/RenderWorkerV2Client.java @@ -17,13 +17,7 @@ public interface RenderWorkerV2Client { */ @GetMapping("/{id}") CommonResponse getWorker(@PathVariable("id") Long id); - - /** - * 获取工作器含配置信息 - */ - @GetMapping("/{id}/with-config") - CommonResponse getWorkerWithConfig(@PathVariable("id") Long id); - + /** * 创建工作器 */ @@ -51,26 +45,10 @@ public interface RenderWorkerV2Client { @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(required = false) Integer isEnabled, @RequestParam(required = false) String name); - - /** - * 分页查询工作器列表(含配置信息) - */ - @GetMapping("/with-config") - CommonResponse> listWorkersWithConfig( - @RequestParam(defaultValue = "1") Integer page, - @RequestParam(defaultValue = "10") Integer pageSize, - @RequestParam(required = false) Integer isEnabled, - @RequestParam(required = false) String name); - + /** * 根据key获取工作器核心信息 */ @GetMapping("/key/{key}") CommonResponse getWorkerByKey(@PathVariable("key") String key); - - /** - * 根据key获取工作器完整信息(含配置) - */ - @GetMapping("/key/{key}/with-config") - CommonResponse getWorkerWithConfigByKey(@PathVariable("key") String key); } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/integration/render/service/RenderWorkerConfigIntegrationService.java b/src/main/java/com/ycwl/basic/integration/render/service/RenderWorkerConfigIntegrationService.java index 41296cc2..8952d0ce 100644 --- a/src/main/java/com/ycwl/basic/integration/render/service/RenderWorkerConfigIntegrationService.java +++ b/src/main/java/com/ycwl/basic/integration/render/service/RenderWorkerConfigIntegrationService.java @@ -70,7 +70,7 @@ public class RenderWorkerConfigIntegrationService { log.debug("获取渲染工作器平铺配置, workerId: {}", workerId); return fallbackService.executeWithFallback( SERVICE_NAME, - "worker:flat:config:" + workerId, + "worker:config:" + workerId, () -> { List configs = getWorkerConfigsInternal(workerId); return flattenConfigs(configs); diff --git a/src/main/java/com/ycwl/basic/integration/render/service/RenderWorkerIntegrationService.java b/src/main/java/com/ycwl/basic/integration/render/service/RenderWorkerIntegrationService.java index 556e3033..95306715 100644 --- a/src/main/java/com/ycwl/basic/integration/render/service/RenderWorkerIntegrationService.java +++ b/src/main/java/com/ycwl/basic/integration/render/service/RenderWorkerIntegrationService.java @@ -42,22 +42,6 @@ public class RenderWorkerIntegrationService { ); } - /** - * 获取工作器详细信息(含配置)(带降级) - */ - public RenderWorkerV2WithConfigDTO getWorkerWithConfig(Long id) { - log.debug("获取渲染工作器详细信息, id: {}", id); - return fallbackService.executeWithFallback( - SERVICE_NAME, - "worker:config:" + id, - () -> { - CommonResponse response = renderWorkerV2Client.getWorkerWithConfig(id); - return handleResponse(response, "获取渲染工作器详细信息失败"); - }, - RenderWorkerV2WithConfigDTO.class - ); - } - /** * 创建工作器(直接调用,不降级) */ @@ -96,18 +80,6 @@ public class RenderWorkerIntegrationService { return handleResponse(response, "查询渲染工作器列表失败"); } - /** - * 分页查询工作器列表(含配置信息)(不降级) - */ - public PageResponse listWorkersWithConfig(Integer page, Integer pageSize, - Integer isEnabled, String name) { - log.debug("分页查询渲染工作器列表(含配置), page: {}, pageSize: {}, isEnabled: {}, name: {}", - page, pageSize, isEnabled, name); - CommonResponse> response = - renderWorkerV2Client.listWorkersWithConfig(page, pageSize, isEnabled, name); - return handleResponse(response, "查询渲染工作器列表(含配置)失败"); - } - /** * 根据key获取工作器核心信息(带降级) */ @@ -124,22 +96,6 @@ public class RenderWorkerIntegrationService { ); } - /** - * 根据key获取工作器详细信息(含配置)(带降级) - */ - public RenderWorkerV2WithConfigDTO getWorkerWithConfigByKey(String key) { - log.debug("根据key获取渲染工作器详细信息, key: {}", key); - return fallbackService.executeWithFallback( - SERVICE_NAME, - "worker:key:config:" + key, - () -> { - CommonResponse response = renderWorkerV2Client.getWorkerWithConfigByKey(key); - return handleResponse(response, "根据key获取渲染工作器详细信息失败"); - }, - RenderWorkerV2WithConfigDTO.class - ); - } - /** * 处理通用响应 */ diff --git a/src/main/java/com/ycwl/basic/integration/scenic/client/ScenicConfigV2Client.java b/src/main/java/com/ycwl/basic/integration/scenic/client/ScenicConfigV2Client.java index 31c17097..6c5d84c2 100644 --- a/src/main/java/com/ycwl/basic/integration/scenic/client/ScenicConfigV2Client.java +++ b/src/main/java/com/ycwl/basic/integration/scenic/client/ScenicConfigV2Client.java @@ -18,9 +18,6 @@ public interface ScenicConfigV2Client { CommonResponse getConfigByKey(@PathVariable("scenicId") Long scenicId, @PathVariable("configKey") String configKey); - @GetMapping("/{scenicId}/keys") - CommonResponse> getFlatConfigs(@PathVariable("scenicId") Long scenicId); - @PostMapping("/{scenicId}") CommonResponse createConfig(@PathVariable("scenicId") Long scenicId, @RequestBody CreateConfigRequest request); @@ -37,8 +34,4 @@ public interface ScenicConfigV2Client { @PostMapping("/{scenicId}/batch") CommonResponse batchUpdateConfigs(@PathVariable("scenicId") Long scenicId, @RequestBody BatchConfigRequest request); - - @PostMapping("/{scenicId}/batchFlatUpdate") - CommonResponse batchFlatUpdateConfigs(@PathVariable("scenicId") Long scenicId, - @RequestBody Map configs); } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/integration/scenic/client/ScenicV2Client.java b/src/main/java/com/ycwl/basic/integration/scenic/client/ScenicV2Client.java index f2c2d355..2d637941 100644 --- a/src/main/java/com/ycwl/basic/integration/scenic/client/ScenicV2Client.java +++ b/src/main/java/com/ycwl/basic/integration/scenic/client/ScenicV2Client.java @@ -19,10 +19,6 @@ public interface ScenicV2Client { @GetMapping("/{scenicId}") CommonResponse getScenic(@PathVariable("scenicId") Long scenicId); - @GetMapping("/{scenicId}/with-config") - CommonResponse getScenicWithConfig(@PathVariable("scenicId") Long scenicId); - - @PostMapping("/") CommonResponse createScenic(@RequestBody CreateScenicRequest request); @@ -41,10 +37,4 @@ public interface ScenicV2Client { @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(required = false) Integer status, @RequestParam(required = false) String name); - - @GetMapping("/with-config") - CommonResponse> listScenicsWithConfig(@RequestParam(defaultValue = "1") Integer page, - @RequestParam(defaultValue = "10") Integer pageSize, - @RequestParam(required = false) Integer status, - @RequestParam(required = false) String name); } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/integration/scenic/example/ScenicIntegrationExample.java b/src/main/java/com/ycwl/basic/integration/scenic/example/ScenicIntegrationExample.java index fe5c8757..fcc77f06 100644 --- a/src/main/java/com/ycwl/basic/integration/scenic/example/ScenicIntegrationExample.java +++ b/src/main/java/com/ycwl/basic/integration/scenic/example/ScenicIntegrationExample.java @@ -94,14 +94,6 @@ public class ScenicIntegrationExample { ScenicV2DTO scenic = scenicIntegrationService.getScenic(scenicId); log.info("获取景区成功: {}", scenic.getName()); - // 获取景区配置信息 - 自动降级 - ScenicV2WithConfigDTO scenicWithConfig = scenicIntegrationService.getScenicWithConfig(scenicId); - log.info("获取景区配置成功,配置数量: {}", scenicWithConfig.getConfig().size()); - - // 获取扁平化配置 - 自动降级 - Map flatConfig = scenicIntegrationService.getScenicFlatConfig(scenicId); - log.info("获取扁平化配置成功,配置项数量: {}", flatConfig.size()); - } catch (Exception e) { log.error("景区操作降级失败", e); } @@ -116,16 +108,22 @@ public class ScenicIntegrationExample { Long scenicId = 2001L; try { - // 获取扁平化配置 - 自动降级 - Map flatConfigs = scenicConfigIntegrationService.getFlatConfigs(scenicId); - log.info("获取扁平化配置成功,配置项数量: {}", flatConfigs.size()); + // 获取配置列表 - 自动降级 + var configs = scenicConfigIntegrationService.listConfigs(scenicId); + log.info("获取配置列表成功,配置项数量: {}", configs.size()); // 批量更新配置 - 直接操作,失败时抛出异常 - Map updates = new HashMap<>(); - updates.put("max_visitors", "5000"); - updates.put("opening_hours", "08:00-18:00"); - - BatchUpdateResponse result = scenicConfigIntegrationService.batchFlatUpdateConfigs(scenicId, updates); + BatchConfigRequest batchRequest = new BatchConfigRequest(); + // 添加配置项示例 + BatchConfigRequest.BatchConfigItem item1 = new BatchConfigRequest.BatchConfigItem(); + item1.setConfigKey("max_visitors"); + item1.setConfigValue("5000"); + BatchConfigRequest.BatchConfigItem item2 = new BatchConfigRequest.BatchConfigItem(); + item2.setConfigKey("opening_hours"); + item2.setConfigValue("08:00-18:00"); + batchRequest.setConfigs(java.util.Arrays.asList(item1, item2)); + + BatchUpdateResponse result = scenicConfigIntegrationService.batchUpdateConfigs(scenicId, batchRequest); log.info("批量更新配置完成: 成功 {}, 失败 {}", result.getSuccess(), result.getFailed()); } catch (Exception e) { @@ -140,14 +138,11 @@ public class ScenicIntegrationExample { log.info("=== 景区降级缓存管理示例 ==="); String scenicCacheKey = "scenic:2001"; - String configCacheKey = "scenic:flat:configs:2001"; // 检查降级缓存状态 boolean hasScenicCache = fallbackService.hasFallbackCache(SERVICE_NAME, scenicCacheKey); - boolean hasConfigCache = fallbackService.hasFallbackCache(SERVICE_NAME, configCacheKey); log.info("景区降级缓存存在: {}", hasScenicCache); - log.info("配置降级缓存存在: {}", hasConfigCache); // 获取降级缓存统计信息 IntegrationFallbackService.FallbackCacheStats stats = fallbackService.getFallbackCacheStats(SERVICE_NAME); 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 be001636..a776a629 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 @@ -48,19 +48,6 @@ public class ScenicConfigIntegrationService { ); } - public Map getFlatConfigs(Long scenicId) { - log.debug("获取景区扁平化配置, scenicId: {}", scenicId); - return fallbackService.executeWithFallback( - SERVICE_NAME, - "scenic:flat:configs:" + scenicId, - () -> { - CommonResponse> response = scenicConfigV2Client.getFlatConfigs(scenicId); - return handleResponse(response, "获取景区扁平化配置失败"); - }, - Map.class - ); - } - public ScenicConfigV2DTO createConfig(Long scenicId, CreateConfigRequest request) { log.debug("创建景区配置, scenicId: {}, configKey: {}", scenicId, request.getConfigKey()); CommonResponse response = scenicConfigV2Client.createConfig(scenicId, request); @@ -85,12 +72,6 @@ public class ScenicConfigIntegrationService { return handleResponse(response, "批量更新景区配置失败"); } - public BatchUpdateResponse batchFlatUpdateConfigs(Long scenicId, Map configs) { - log.debug("扁平化批量更新景区配置, scenicId: {}, configs count: {}", scenicId, configs.size()); - CommonResponse response = scenicConfigV2Client.batchFlatUpdateConfigs(scenicId, configs); - return handleResponse(response, "扁平化批量更新景区配置失败"); - } - private T handleResponse(CommonResponse response, String errorMessage) { if (response == null || !response.isSuccess()) { 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 487918a2..be79e19b 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 @@ -42,32 +42,6 @@ public class ScenicIntegrationService { ); } - public ScenicV2WithConfigDTO getScenicWithConfig(Long scenicId) { - log.debug("获取景区配置信息, scenicId: {}", scenicId); - return fallbackService.executeWithFallback( - SERVICE_NAME, - "scenic:config:" + scenicId, - () -> { - CommonResponse response = scenicV2Client.getScenicWithConfig(scenicId); - return handleResponse(response, "获取景区配置信息失败"); - }, - ScenicV2WithConfigDTO.class - ); - } - - public Map getScenicFlatConfig(Long scenicId) { - log.debug("获取景区扁平化配置, scenicId: {}", scenicId); - return fallbackService.executeWithFallback( - SERVICE_NAME, - "scenic:flat:config:" + scenicId, - () -> { - CommonResponse> response = scenicConfigV2Client.getFlatConfigs(scenicId); - return handleResponse(response, "获取景区扁平化配置失败"); - }, - Map.class - ); - } - public ScenicV2DTO createScenic(CreateScenicRequest request) { log.debug("创建景区, name: {}", request.getName()); CommonResponse response = scenicV2Client.createScenic(request); @@ -98,12 +72,6 @@ public class ScenicIntegrationService { return handleResponse(response, "分页查询景区列表失败"); } - public PageResponse listScenicsWithConfig(Integer page, Integer pageSize, Integer status, String name) { - log.debug("分页查询景区带配置列表, page: {}, pageSize: {}, status: {}, name: {}", page, pageSize, status, name); - CommonResponse> response = scenicV2Client.listScenicsWithConfig(page, pageSize, status, name); - return handleResponse(response, "分页查询景区带配置列表失败"); - } - private T handleResponse(CommonResponse response, String errorMessage) { if (response == null || !response.isSuccess()) { String msg = response != null && response.getMessage() != null diff --git a/src/main/java/com/ycwl/basic/repository/ScenicRepository.java b/src/main/java/com/ycwl/basic/repository/ScenicRepository.java index a2e5365b..7bc87c40 100644 --- a/src/main/java/com/ycwl/basic/repository/ScenicRepository.java +++ b/src/main/java/com/ycwl/basic/repository/ScenicRepository.java @@ -52,8 +52,27 @@ public class ScenicRepository { } public ScenicEntity getScenic(Long id) { - ScenicV2WithConfigDTO scenicDTO = scenicIntegrationService.getScenicWithConfig(id); - ScenicEntity scenicEntity = convertToScenicEntity(scenicDTO); + // 分别获取景区基础信息和配置信息 + ScenicV2DTO scenicBasic = scenicIntegrationService.getScenic(id); + List configList = scenicConfigIntegrationService.listConfigs(id); + + // 将配置列表转换为Map + Map configMap = new HashMap<>(); + if (configList != null) { + for (ScenicConfigV2DTO config : configList) { + configMap.put(config.getConfigKey(), config.getConfigValue()); + } + } + + // 手动组合成WithConfig对象用于转换 + ScenicV2WithConfigDTO scenicWithConfig = new ScenicV2WithConfigDTO(); + scenicWithConfig.setId(scenicBasic.getId()); + scenicWithConfig.setName(scenicBasic.getName()); + scenicWithConfig.setMpId(scenicBasic.getMpId()); + scenicWithConfig.setStatus(scenicBasic.getStatus()); + scenicWithConfig.setConfig(configMap); + + ScenicEntity scenicEntity = convertToScenicEntity(scenicWithConfig); return scenicEntity; }