You've already forked FrameTour-BE
Merge branch 'render-worker-microservice'
# Conflicts: # src/main/java/com/ycwl/basic/integration/scenic/service/ScenicIntegrationService.java # src/main/java/com/ycwl/basic/service/task/impl/TaskTaskServiceImpl.java
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package com.ycwl.basic.integration.device.client;
|
||||
|
||||
import com.ycwl.basic.integration.common.response.CommonResponse;
|
||||
import com.ycwl.basic.integration.common.response.PageResponse;
|
||||
import com.ycwl.basic.integration.device.dto.defaults.*;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 默认配置管理 Feign 客户端
|
||||
*/
|
||||
@FeignClient(name = "zt-device", contextId = "device-default-config", path = "/api/device/config/v2/defaults")
|
||||
public interface DefaultConfigClient {
|
||||
|
||||
/**
|
||||
* 获取默认配置列表
|
||||
*/
|
||||
@GetMapping
|
||||
CommonResponse<PageResponse<DefaultConfigResponse>> listDefaultConfigs(@RequestParam(value = "page", defaultValue = "1") int page,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize);
|
||||
|
||||
/**
|
||||
* 根据配置键获取默认配置
|
||||
*/
|
||||
@GetMapping("/{configKey}")
|
||||
CommonResponse<DefaultConfigResponse> getDefaultConfig(@PathVariable("configKey") String configKey);
|
||||
|
||||
/**
|
||||
* 创建默认配置
|
||||
*/
|
||||
@PostMapping
|
||||
CommonResponse<String> createDefaultConfig(@RequestBody DefaultConfigRequest request);
|
||||
|
||||
/**
|
||||
* 更新默认配置
|
||||
*/
|
||||
@PutMapping("/{configKey}")
|
||||
CommonResponse<Map<String, Object>> updateDefaultConfig(@PathVariable("configKey") String configKey,
|
||||
@RequestBody Map<String, Object> updates);
|
||||
|
||||
/**
|
||||
* 删除默认配置
|
||||
*/
|
||||
@DeleteMapping("/{configKey}")
|
||||
CommonResponse<String> deleteDefaultConfig(@PathVariable("configKey") String configKey);
|
||||
|
||||
/**
|
||||
* 批量更新默认配置
|
||||
*/
|
||||
@PostMapping("/batch")
|
||||
CommonResponse<BatchDefaultConfigResponse> batchUpdateDefaultConfigs(@RequestBody BatchDefaultConfigRequest request);
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package com.ycwl.basic.integration.device.client;
|
||||
|
||||
import com.ycwl.basic.integration.common.response.CommonResponse;
|
||||
import com.ycwl.basic.integration.common.response.PageResponse;
|
||||
import com.ycwl.basic.integration.device.dto.device.*;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -55,7 +56,7 @@ public interface DeviceV2Client {
|
||||
* 分页获取设备列表(核心信息)
|
||||
*/
|
||||
@GetMapping("/")
|
||||
CommonResponse<DeviceV2ListResponse> listDevices(
|
||||
CommonResponse<PageResponse<DeviceV2DTO>> listDevices(
|
||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(value = "name", required = false) String name,
|
||||
@@ -68,7 +69,7 @@ public interface DeviceV2Client {
|
||||
* 分页获取设备列表(含配置)
|
||||
*/
|
||||
@GetMapping("/with-config")
|
||||
CommonResponse<DeviceV2WithConfigListResponse> listDevicesWithConfig(
|
||||
CommonResponse<PageResponse<DeviceV2WithConfigDTO>> listDevicesWithConfig(
|
||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(value = "name", required = false) String name,
|
||||
|
@@ -0,0 +1,18 @@
|
||||
package com.ycwl.basic.integration.device.dto.defaults;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量默认配置操作请求模型
|
||||
*/
|
||||
@Data
|
||||
public class BatchDefaultConfigRequest {
|
||||
|
||||
@NotEmpty(message = "配置列表不能为空")
|
||||
@Valid
|
||||
private List<DefaultConfigRequest> configs;
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package com.ycwl.basic.integration.device.dto.defaults;
|
||||
|
||||
import com.ycwl.basic.integration.device.dto.config.ProcessedConfigItem;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量默认配置操作响应模型
|
||||
*/
|
||||
@Data
|
||||
public class BatchDefaultConfigResponse {
|
||||
|
||||
private Integer success;
|
||||
|
||||
private Integer failed;
|
||||
|
||||
private List<DefaultConfigConflict> conflicts;
|
||||
|
||||
private List<ProcessedConfigItem> processedItems;
|
||||
|
||||
private List<String> errors;
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package com.ycwl.basic.integration.device.dto.defaults;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 冲突信息模型
|
||||
*/
|
||||
@Data
|
||||
public class DefaultConfigConflict {
|
||||
|
||||
private String configKey;
|
||||
|
||||
private String conflictType;
|
||||
|
||||
private Integer deviceCount;
|
||||
|
||||
private String currentType;
|
||||
|
||||
private String proposedType;
|
||||
|
||||
private List<Long> conflictDevices;
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.ycwl.basic.integration.device.dto.defaults;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* 默认配置请求模型
|
||||
*/
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DefaultConfigRequest {
|
||||
|
||||
@NotBlank(message = "配置键不能为空")
|
||||
private String configKey;
|
||||
|
||||
@NotBlank(message = "配置值不能为空")
|
||||
private String configValue;
|
||||
|
||||
@NotBlank(message = "配置类型不能为空")
|
||||
private String configType;
|
||||
|
||||
@NotBlank(message = "配置描述不能为空")
|
||||
private String description;
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.ycwl.basic.integration.device.dto.defaults;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 默认配置响应模型
|
||||
*/
|
||||
@Data
|
||||
public class DefaultConfigResponse {
|
||||
|
||||
private String id;
|
||||
|
||||
private String configKey;
|
||||
|
||||
private String configValue;
|
||||
|
||||
private String configType;
|
||||
|
||||
private String description;
|
||||
|
||||
private Integer isActive;
|
||||
|
||||
private String createTime;
|
||||
|
||||
private String updateTime;
|
||||
|
||||
private Integer usageCount;
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
package com.ycwl.basic.integration.device.dto.device;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DeviceV2ListResponse {
|
||||
private List<DeviceV2DTO> list;
|
||||
private Integer total;
|
||||
private Integer page;
|
||||
private Integer pageSize;
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
package com.ycwl.basic.integration.device.dto.device;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DeviceV2WithConfigListResponse {
|
||||
private List<DeviceV2WithConfigDTO> list;
|
||||
private Integer total;
|
||||
private Integer page;
|
||||
private Integer pageSize;
|
||||
}
|
@@ -17,7 +17,7 @@ public class FilterDevicesByConfigsResponse {
|
||||
/**
|
||||
* 总数
|
||||
*/
|
||||
private String total;
|
||||
private Integer total;
|
||||
|
||||
/**
|
||||
* 页码
|
||||
|
@@ -0,0 +1,275 @@
|
||||
package com.ycwl.basic.integration.device.example;
|
||||
|
||||
import com.ycwl.basic.integration.common.response.PageResponse;
|
||||
import com.ycwl.basic.integration.device.dto.defaults.*;
|
||||
import com.ycwl.basic.integration.device.service.DeviceDefaultConfigIntegrationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 默认配置集成服务使用示例
|
||||
*
|
||||
* 通过在 application.yml 中设置 integration.device.example.default-config.enabled=true 来启用
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(name = "integration.device.example.default-config.enabled", havingValue = "true")
|
||||
public class DefaultConfigIntegrationExample implements CommandLineRunner {
|
||||
|
||||
private final DeviceDefaultConfigIntegrationService defaultConfigService;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
log.info("=== 默认配置集成服务使用示例 ===");
|
||||
|
||||
try {
|
||||
// 1. 基础查询操作示例(支持自动 Fallback)
|
||||
basicQueryExamples();
|
||||
|
||||
// 2. 配置管理操作示例(直接操作)
|
||||
configManagementExamples();
|
||||
|
||||
// 3. 批量操作示例
|
||||
batchOperationExamples();
|
||||
|
||||
// 4. 高级使用模式示例
|
||||
advancedUsageExamples();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("默认配置集成示例执行失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础查询操作示例(支持自动 Fallback)
|
||||
*/
|
||||
private void basicQueryExamples() {
|
||||
log.info("--- 基础查询操作示例(支持自动 Fallback)---");
|
||||
|
||||
try {
|
||||
// 获取默认配置列表(自动缓存,服务不可用时返回缓存数据)
|
||||
PageResponse<DefaultConfigResponse> configList = defaultConfigService.listDefaultConfigs(1, 10);
|
||||
log.info("默认配置列表: 总数={}, 当前页配置数={}",
|
||||
configList.getTotal(), configList.getList().size());
|
||||
|
||||
// 显示配置详情
|
||||
for (DefaultConfigResponse config : configList.getList()) {
|
||||
log.info("配置详情: key={}, value={}, type={}, description={}",
|
||||
config.getConfigKey(), config.getConfigValue(),
|
||||
config.getConfigType(), config.getDescription());
|
||||
|
||||
// 获取单个配置详情(自动缓存,服务不可用时返回缓存数据)
|
||||
DefaultConfigResponse detailConfig = defaultConfigService.getDefaultConfig(config.getConfigKey());
|
||||
if (detailConfig != null) {
|
||||
log.info("配置详情获取成功: usageCount={}, isActive={}",
|
||||
detailConfig.getUsageCount(), detailConfig.getIsActive());
|
||||
}
|
||||
break; // 只展示第一个
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("基础查询操作失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置管理操作示例(直接操作)
|
||||
*/
|
||||
private void configManagementExamples() {
|
||||
log.info("--- 配置管理操作示例(直接操作)---");
|
||||
|
||||
String testConfigKey = "example_test_config";
|
||||
|
||||
try {
|
||||
// 1. 创建默认配置(直接操作,失败时立即报错)
|
||||
DefaultConfigRequest createRequest = new DefaultConfigRequest();
|
||||
createRequest.setConfigKey(testConfigKey);
|
||||
createRequest.setConfigValue("1920x1080");
|
||||
createRequest.setConfigType("string");
|
||||
createRequest.setDescription("示例测试配置 - 默认分辨率");
|
||||
|
||||
boolean createResult = defaultConfigService.createDefaultConfig(createRequest);
|
||||
log.info("创建默认配置结果: {}", createResult ? "成功" : "失败");
|
||||
|
||||
// 2. 更新默认配置(直接操作,可能返回冲突信息)
|
||||
Map<String, Object> updates = new HashMap<>();
|
||||
updates.put("configValue", "3840x2160");
|
||||
updates.put("description", "更新后的默认分辨率 - 4K");
|
||||
|
||||
DefaultConfigConflict conflict = defaultConfigService.updateDefaultConfig(testConfigKey, updates);
|
||||
if (conflict != null) {
|
||||
log.warn("更新配置存在冲突: configKey={}, conflictType={}, deviceCount={}",
|
||||
conflict.getConfigKey(), conflict.getConflictType(), conflict.getDeviceCount());
|
||||
} else {
|
||||
log.info("配置更新成功,无冲突");
|
||||
}
|
||||
|
||||
// 3. 验证更新结果
|
||||
DefaultConfigResponse updatedConfig = defaultConfigService.getDefaultConfig(testConfigKey);
|
||||
if (updatedConfig != null) {
|
||||
log.info("更新后配置值: {}", updatedConfig.getConfigValue());
|
||||
}
|
||||
|
||||
// 4. 删除测试配置(直接操作)
|
||||
boolean deleteResult = defaultConfigService.deleteDefaultConfig(testConfigKey);
|
||||
log.info("删除默认配置结果: {}", deleteResult ? "成功" : "失败");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("配置管理操作失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量操作示例
|
||||
*/
|
||||
private void batchOperationExamples() {
|
||||
log.info("--- 批量操作示例 ---");
|
||||
|
||||
try {
|
||||
// 1. 使用构建器模式创建批量配置
|
||||
BatchDefaultConfigRequest batchRequest = defaultConfigService.createBatchConfigBuilder()
|
||||
.addVideoConfig("1920x1080", 30, "H264") // 添加视频配置组
|
||||
.addNetworkConfig("192.168.1.100", 554, "RTSP") // 添加网络配置组
|
||||
.addConfig("recording_enabled", "true", "bool", "是否启用录制")
|
||||
.addConfig("storage_path", "/data/recordings", "string", "录制存储路径")
|
||||
.addConfig("max_file_size", "1024", "int", "最大文件大小(MB)")
|
||||
.build();
|
||||
|
||||
log.info("准备批量创建 {} 个默认配置", batchRequest.getConfigs().size());
|
||||
|
||||
// 2. 执行批量更新(直接操作)
|
||||
BatchDefaultConfigResponse batchResult = defaultConfigService.batchUpdateDefaultConfigs(batchRequest);
|
||||
|
||||
// 3. 处理批量结果
|
||||
log.info("批量操作结果: 成功={}, 失败={}", batchResult.getSuccess(), batchResult.getFailed());
|
||||
|
||||
if (batchResult.getConflicts() != null && !batchResult.getConflicts().isEmpty()) {
|
||||
log.warn("发现 {} 个配置冲突:", batchResult.getConflicts().size());
|
||||
for (DefaultConfigConflict conflict : batchResult.getConflicts()) {
|
||||
log.warn("冲突配置: key={}, type={}, deviceCount={}",
|
||||
conflict.getConfigKey(), conflict.getConflictType(), conflict.getDeviceCount());
|
||||
}
|
||||
}
|
||||
|
||||
if (batchResult.getProcessedItems() != null) {
|
||||
log.info("处理详情:");
|
||||
batchResult.getProcessedItems().forEach(item ->
|
||||
log.info(" 配置 {}: status={}, action={}, finalType={}",
|
||||
item.getConfigKey(), item.getStatus(), item.getAction(), item.getFinalType())
|
||||
);
|
||||
}
|
||||
|
||||
if (batchResult.getErrors() != null && !batchResult.getErrors().isEmpty()) {
|
||||
log.error("批量操作错误:");
|
||||
batchResult.getErrors().forEach(error -> log.error(" {}", error));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("批量操作失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 高级使用模式示例
|
||||
*/
|
||||
private void advancedUsageExamples() {
|
||||
log.info("--- 高级使用模式示例 ---");
|
||||
|
||||
try {
|
||||
// 1. 设备类型特定的默认配置模式
|
||||
createDeviceTypeSpecificConfigs();
|
||||
|
||||
// 2. 配置验证和完整性检查模式
|
||||
validateConfigCompleteness();
|
||||
|
||||
// 3. 配置迁移和批量更新模式
|
||||
configMigrationPattern();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("高级使用模式示例失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建设备类型特定的默认配置
|
||||
*/
|
||||
private void createDeviceTypeSpecificConfigs() {
|
||||
log.info("创建设备类型特定的默认配置...");
|
||||
|
||||
// IPC摄像头默认配置
|
||||
BatchDefaultConfigRequest ipcDefaults = defaultConfigService.createBatchConfigBuilder()
|
||||
.addVideoConfig("1920x1080", 25, "H264")
|
||||
.addConfig("night_vision", "true", "bool", "夜视功能")
|
||||
.addConfig("motion_detection", "true", "bool", "移动检测")
|
||||
.addConfig("stream_profile", "main", "string", "码流类型")
|
||||
.build();
|
||||
|
||||
// NVR设备默认配置
|
||||
BatchDefaultConfigRequest nvrDefaults = defaultConfigService.createBatchConfigBuilder()
|
||||
.addConfig("max_channels", "16", "int", "最大通道数")
|
||||
.addConfig("storage_mode", "continuous", "string", "存储模式")
|
||||
.addConfig("backup_enabled", "true", "bool", "备份启用")
|
||||
.build();
|
||||
|
||||
log.info("IPC默认配置项数: {}, NVR默认配置项数: {}",
|
||||
ipcDefaults.getConfigs().size(), nvrDefaults.getConfigs().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置验证和完整性检查
|
||||
*/
|
||||
private void validateConfigCompleteness() {
|
||||
log.info("验证配置完整性...");
|
||||
|
||||
// 获取所有默认配置
|
||||
PageResponse<DefaultConfigResponse> allConfigs = defaultConfigService.listDefaultConfigs(1, 100);
|
||||
|
||||
// 检查必需的基础配置是否存在
|
||||
String[] requiredConfigs = {"resolution", "frameRate", "codec", "protocol"};
|
||||
for (String requiredConfig : requiredConfigs) {
|
||||
boolean exists = allConfigs.getList().stream()
|
||||
.anyMatch(config -> requiredConfig.equals(config.getConfigKey()));
|
||||
log.info("必需配置 {} 存在: {}", requiredConfig, exists ? "✓" : "✗");
|
||||
}
|
||||
|
||||
// 统计配置类型分布
|
||||
Map<String, Long> typeDistribution = new HashMap<>();
|
||||
allConfigs.getList().forEach(config ->
|
||||
typeDistribution.merge(config.getConfigType(), 1L, Long::sum)
|
||||
);
|
||||
|
||||
log.info("配置类型分布: {}", typeDistribution);
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置迁移和批量更新模式
|
||||
*/
|
||||
private void configMigrationPattern() {
|
||||
log.info("配置迁移模式示例...");
|
||||
|
||||
try {
|
||||
// 1. 获取需要升级的配置
|
||||
PageResponse<DefaultConfigResponse> oldConfigs = defaultConfigService.listDefaultConfigs(1, 50);
|
||||
|
||||
// 2. 创建升级配置批次
|
||||
BatchDefaultConfigRequest upgradeRequest = defaultConfigService.createBatchConfigBuilder()
|
||||
.addConfig("api_version", "v2", "string", "API版本")
|
||||
.addConfig("security_mode", "enhanced", "string", "安全模式")
|
||||
.build();
|
||||
|
||||
// 3. 执行批量升级
|
||||
BatchDefaultConfigResponse upgradeResult = defaultConfigService.batchUpdateDefaultConfigs(upgradeRequest);
|
||||
log.info("配置升级结果: 成功={}, 失败={}", upgradeResult.getSuccess(), upgradeResult.getFailed());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("配置迁移示例执行失败(这是正常的,因为是示例代码)", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package com.ycwl.basic.integration.device.example;
|
||||
|
||||
import com.ycwl.basic.integration.common.response.PageResponse;
|
||||
import com.ycwl.basic.integration.device.dto.device.*;
|
||||
import com.ycwl.basic.integration.device.dto.config.*;
|
||||
import com.ycwl.basic.integration.device.service.DeviceConfigIntegrationService;
|
||||
@@ -46,7 +47,7 @@ public class DeviceIntegrationExample {
|
||||
log.info("获取设备配置: {}", deviceWithConfig.getName());
|
||||
|
||||
// 分页查询景区设备列表
|
||||
DeviceV2ListResponse deviceList = deviceService.getScenicIpcDevices(1001L, 1, 10);
|
||||
PageResponse<DeviceV2DTO> deviceList = deviceService.getScenicIpcDevices(1001L, 1, 10);
|
||||
log.info("景区设备列表: 总数={}", deviceList.getTotal());
|
||||
|
||||
// 启用设备
|
||||
@@ -80,7 +81,7 @@ public class DeviceIntegrationExample {
|
||||
log.info("更新摄像头1排序为1(置顶)");
|
||||
|
||||
// 获取排序后的设备列表
|
||||
DeviceV2ListResponse sortedList = deviceService.listDevices(1, 10, null, null, null, 1, scenicId);
|
||||
PageResponse<DeviceV2DTO> sortedList = deviceService.listDevices(1, 10, null, null, null, 1, scenicId);
|
||||
log.info("排序后的设备列表:");
|
||||
for (DeviceV2DTO device : sortedList.getList()) {
|
||||
log.info(" - {}: 排序={}, 类型={}", device.getName(), device.getSort(), device.getType());
|
||||
@@ -147,7 +148,7 @@ public class DeviceIntegrationExample {
|
||||
log.info("将普通摄像头置顶(排序值: 1)");
|
||||
|
||||
// 查看最终排序结果
|
||||
DeviceV2ListResponse finalList = deviceService.listDevices(1, 10, null, null, null, 1, scenicId);
|
||||
PageResponse<DeviceV2DTO> finalList = deviceService.listDevices(1, 10, null, null, null, 1, scenicId);
|
||||
log.info("最终排序结果:");
|
||||
for (DeviceV2DTO device : finalList.getList()) {
|
||||
log.info(" - {}: 排序={}", device.getName(), device.getSort());
|
||||
|
@@ -0,0 +1,218 @@
|
||||
package com.ycwl.basic.integration.device.service;
|
||||
|
||||
import com.ycwl.basic.integration.common.exception.IntegrationException;
|
||||
import com.ycwl.basic.integration.common.response.CommonResponse;
|
||||
import com.ycwl.basic.integration.common.response.PageResponse;
|
||||
import com.ycwl.basic.integration.common.service.IntegrationFallbackService;
|
||||
import com.ycwl.basic.integration.device.client.DefaultConfigClient;
|
||||
import com.ycwl.basic.integration.device.dto.defaults.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 默认配置集成服务
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceDefaultConfigIntegrationService {
|
||||
|
||||
private final DefaultConfigClient defaultConfigClient;
|
||||
private final IntegrationFallbackService fallbackService;
|
||||
|
||||
private static final String SERVICE_NAME = "zt-device";
|
||||
|
||||
/**
|
||||
* 获取默认配置列表(支持 Fallback)
|
||||
*/
|
||||
public PageResponse<DefaultConfigResponse> listDefaultConfigs(int page, int pageSize) {
|
||||
return fallbackService.executeWithFallback(
|
||||
SERVICE_NAME,
|
||||
"defaults:list:" + page + ":" + pageSize,
|
||||
() -> {
|
||||
CommonResponse<PageResponse<DefaultConfigResponse>> response = defaultConfigClient.listDefaultConfigs(page, pageSize);
|
||||
return handleResponse(response, "获取默认配置列表失败");
|
||||
},
|
||||
PageResponse.class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置键获取默认配置(支持 Fallback)
|
||||
*/
|
||||
public DefaultConfigResponse getDefaultConfig(String configKey) {
|
||||
return fallbackService.executeWithFallback(
|
||||
SERVICE_NAME,
|
||||
"defaults:config:" + configKey,
|
||||
() -> {
|
||||
log.info("获取默认配置, configKey: {}", configKey);
|
||||
CommonResponse<DefaultConfigResponse> response = defaultConfigClient.getDefaultConfig(configKey);
|
||||
return handleResponse(response, "获取默认配置失败");
|
||||
},
|
||||
DefaultConfigResponse.class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建默认配置(直接操作,不支持 Fallback)
|
||||
*/
|
||||
public boolean createDefaultConfig(DefaultConfigRequest request) {
|
||||
log.info("创建默认配置, configKey: {}", request.getConfigKey());
|
||||
CommonResponse<String> response = defaultConfigClient.createDefaultConfig(request);
|
||||
String result = handleResponse(response, "创建默认配置失败");
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新默认配置(直接操作,不支持 Fallback)
|
||||
*/
|
||||
public DefaultConfigConflict updateDefaultConfig(String configKey, Map<String, Object> updates) {
|
||||
log.info("更新默认配置, configKey: {}, updates: {}", configKey, updates);
|
||||
CommonResponse<Map<String, Object>> response = defaultConfigClient.updateDefaultConfig(configKey, updates);
|
||||
Map<String, Object> result = handleResponse(response, "更新默认配置失败");
|
||||
|
||||
// 检查是否有冲突信息
|
||||
if (result != null && result.containsKey("conflict")) {
|
||||
Object conflictObj = result.get("conflict");
|
||||
if (conflictObj instanceof Map) {
|
||||
// 将Map转换为DefaultConfigConflict对象
|
||||
return mapToDefaultConfigConflict((Map<String, Object>) conflictObj);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除默认配置(直接操作,不支持 Fallback)
|
||||
*/
|
||||
public boolean deleteDefaultConfig(String configKey) {
|
||||
log.info("删除默认配置, configKey: {}", configKey);
|
||||
CommonResponse<String> response = defaultConfigClient.deleteDefaultConfig(configKey);
|
||||
String result = handleResponse(response, "删除默认配置失败");
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新默认配置(直接操作,不支持 Fallback)
|
||||
*/
|
||||
public BatchDefaultConfigResponse batchUpdateDefaultConfigs(BatchDefaultConfigRequest request) {
|
||||
log.info("批量更新默认配置, configs count: {}", request.getConfigs().size());
|
||||
CommonResponse<BatchDefaultConfigResponse> response = defaultConfigClient.batchUpdateDefaultConfigs(request);
|
||||
return handleResponse(response, "批量更新默认配置失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建批量配置请求构建器
|
||||
*/
|
||||
public BatchDefaultConfigRequestBuilder createBatchConfigBuilder() {
|
||||
return new BatchDefaultConfigRequestBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量配置请求构建器
|
||||
*/
|
||||
public static class BatchDefaultConfigRequestBuilder {
|
||||
private final BatchDefaultConfigRequest request = new BatchDefaultConfigRequest();
|
||||
|
||||
public BatchDefaultConfigRequestBuilder() {
|
||||
request.setConfigs(new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加配置项
|
||||
*/
|
||||
public BatchDefaultConfigRequestBuilder addConfig(String configKey, String configValue,
|
||||
String configType, String description) {
|
||||
DefaultConfigRequest item = new DefaultConfigRequest();
|
||||
item.setConfigKey(configKey);
|
||||
item.setConfigValue(configValue);
|
||||
item.setConfigType(configType);
|
||||
item.setDescription(description);
|
||||
request.getConfigs().add(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加视频配置
|
||||
*/
|
||||
public BatchDefaultConfigRequestBuilder addVideoConfig(String resolution, Integer frameRate, String codec) {
|
||||
addConfig("resolution", resolution, "string", "视频分辨率");
|
||||
addConfig("frameRate", frameRate.toString(), "int", "视频帧率");
|
||||
addConfig("codec", codec, "string", "视频编码格式");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加网络配置
|
||||
*/
|
||||
public BatchDefaultConfigRequestBuilder addNetworkConfig(String ipAddress, Integer port, String protocol) {
|
||||
addConfig("ipAddress", ipAddress, "string", "IP地址");
|
||||
addConfig("port", port.toString(), "int", "端口号");
|
||||
addConfig("protocol", protocol, "string", "网络协议");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建请求对象
|
||||
*/
|
||||
public BatchDefaultConfigRequest build() {
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Map转换为DefaultConfigConflict对象
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private DefaultConfigConflict mapToDefaultConfigConflict(Map<String, Object> map) {
|
||||
DefaultConfigConflict conflict = new DefaultConfigConflict();
|
||||
|
||||
if (map.containsKey("configKey")) {
|
||||
conflict.setConfigKey((String) map.get("configKey"));
|
||||
}
|
||||
if (map.containsKey("conflictType")) {
|
||||
conflict.setConflictType((String) map.get("conflictType"));
|
||||
}
|
||||
if (map.containsKey("deviceCount")) {
|
||||
Object deviceCount = map.get("deviceCount");
|
||||
if (deviceCount instanceof Number) {
|
||||
conflict.setDeviceCount(((Number) deviceCount).intValue());
|
||||
}
|
||||
}
|
||||
if (map.containsKey("currentType")) {
|
||||
conflict.setCurrentType((String) map.get("currentType"));
|
||||
}
|
||||
if (map.containsKey("proposedType")) {
|
||||
conflict.setProposedType((String) map.get("proposedType"));
|
||||
}
|
||||
if (map.containsKey("conflictDevices")) {
|
||||
Object conflictDevices = map.get("conflictDevices");
|
||||
if (conflictDevices instanceof Iterable) {
|
||||
conflict.setConflictDevices(new ArrayList<>());
|
||||
for (Object deviceId : (Iterable<?>) conflictDevices) {
|
||||
if (deviceId instanceof Number) {
|
||||
conflict.getConflictDevices().add(((Number) deviceId).longValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return conflict;
|
||||
}
|
||||
|
||||
private <T> T handleResponse(CommonResponse<T> response, String errorMessage) {
|
||||
if (response == null || !response.isSuccess()) {
|
||||
String msg = response != null && response.getMessage() != null
|
||||
? response.getMessage()
|
||||
: errorMessage;
|
||||
Integer code = response != null ? response.getCode() : 5000;
|
||||
throw new IntegrationException(code, msg, SERVICE_NAME);
|
||||
}
|
||||
return response.getData();
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@ import com.ycwl.basic.integration.common.exception.IntegrationException;
|
||||
import com.ycwl.basic.integration.common.response.CommonResponse;
|
||||
import com.ycwl.basic.integration.common.service.IntegrationFallbackService;
|
||||
import com.ycwl.basic.integration.device.client.DeviceV2Client;
|
||||
import com.ycwl.basic.integration.common.response.PageResponse;
|
||||
import com.ycwl.basic.integration.device.dto.device.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -91,20 +92,20 @@ public class DeviceIntegrationService {
|
||||
handleResponse(response, "删除设备失败");
|
||||
}
|
||||
|
||||
public DeviceV2ListResponse listDevices(Integer page, Integer pageSize, String name, String no,
|
||||
public PageResponse<DeviceV2DTO> listDevices(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<DeviceV2ListResponse> response = deviceV2Client.listDevices(
|
||||
CommonResponse<PageResponse<DeviceV2DTO>> response = deviceV2Client.listDevices(
|
||||
page, pageSize, name, no, type, isActive, scenicId);
|
||||
return handleResponse(response, "分页查询设备列表失败");
|
||||
}
|
||||
|
||||
public DeviceV2WithConfigListResponse listDevicesWithConfig(Integer page, Integer pageSize, String name, String no,
|
||||
public PageResponse<DeviceV2WithConfigDTO> 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<DeviceV2WithConfigListResponse> response = deviceV2Client.listDevicesWithConfig(
|
||||
CommonResponse<PageResponse<DeviceV2WithConfigDTO>> response = deviceV2Client.listDevicesWithConfig(
|
||||
page, pageSize, name, no, type, isActive, scenicId);
|
||||
return handleResponse(response, "分页查询设备带配置列表失败");
|
||||
}
|
||||
@@ -196,14 +197,14 @@ public class DeviceIntegrationService {
|
||||
/**
|
||||
* 获取景区的IPC设备列表
|
||||
*/
|
||||
public DeviceV2ListResponse getScenicIpcDevices(Long scenicId, Integer page, Integer pageSize) {
|
||||
public PageResponse<DeviceV2DTO> getScenicIpcDevices(Long scenicId, Integer page, Integer pageSize) {
|
||||
return listDevices(page, pageSize, null, null, "IPC", 1, scenicId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取景区的所有激活设备
|
||||
*/
|
||||
public DeviceV2ListResponse getScenicActiveDevices(Long scenicId, Integer page, Integer pageSize) {
|
||||
public PageResponse<DeviceV2DTO> getScenicActiveDevices(Long scenicId, Integer page, Integer pageSize) {
|
||||
return listDevices(page, pageSize, null, null, null, 1, scenicId);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user