You've already forked FrameTour-BE
feat(device): 新增批量配置设备参数接口
- 新增 BatchUpdateResponse 和 ProcessedConfigItem 类用于批量更新响应 - 修改 DeviceConfigV2Client 接口返回类型为 BatchUpdateResponse - 在 DeviceConfigIntegrationService 中实现新的批量更新逻辑 - 更新 DeviceIntegrationExample 和 CLAUDE.md 文档,添加新的批量配置示例
This commit is contained in:
@@ -163,11 +163,28 @@ configService.setDeviceFramerate(deviceId, 60);
|
||||
// Get flat configuration
|
||||
Map<String, Object> config = configService.getDeviceFlatConfig(deviceId);
|
||||
|
||||
// Batch update configurations
|
||||
// Batch update configurations (simple way)
|
||||
Map<String, Object> batchConfigs = new HashMap<>();
|
||||
batchConfigs.put("brightness", "50");
|
||||
batchConfigs.put("contrast", "80");
|
||||
configService.batchFlatUpdateDeviceConfig(deviceId, batchConfigs);
|
||||
|
||||
// New batch configuration API with detailed results
|
||||
BatchDeviceConfigRequest request = configService.createBatchConfigBuilder()
|
||||
.addVideoConfig("4K", 30, "H265") // Add video configuration
|
||||
.addNetworkConfig("192.168.1.100", 554, "RTSP") // Add network configuration
|
||||
.addAuthConfig("admin", "password") // Add authentication configuration
|
||||
.addConfig("recording_enabled", "true") // Use default configuration
|
||||
.addConfig("custom_setting", "value", "string", "Custom setting") // Custom configuration
|
||||
.build();
|
||||
|
||||
BatchUpdateResponse result = configService.batchUpdateDeviceConfigWithResult(deviceId, request);
|
||||
if (result.getFailed() > 0) {
|
||||
// Handle partial failure
|
||||
result.getProcessedItems().stream()
|
||||
.filter(item -> "failed".equals(item.getStatus()))
|
||||
.forEach(item -> log.warn("Config {} failed: {}", item.getConfigKey(), item.getMessage()));
|
||||
}
|
||||
```
|
||||
|
||||
#### Device Management Patterns
|
||||
@@ -193,6 +210,57 @@ for (DeviceV2DTO device : activeDevices.getList()) {
|
||||
}
|
||||
```
|
||||
|
||||
### Enhanced Batch Configuration API
|
||||
|
||||
Device Integration now supports an enhanced batch configuration API that provides detailed processing results and supports default configuration rules.
|
||||
|
||||
#### Default Configuration Rules
|
||||
The system uses `device_id = 0` configurations as default templates:
|
||||
- **Configurations with defaults**: System enforces default `config_type` and `description`, only `configValue` is updated
|
||||
- **Configurations without defaults**: Allows custom `config_type` and `description`
|
||||
|
||||
#### Usage Examples
|
||||
```java
|
||||
// 1. Using Builder Pattern
|
||||
BatchDeviceConfigRequest request = configService.createBatchConfigBuilder()
|
||||
.addVideoConfig("1920x1080", 30, "H264") // Video settings
|
||||
.addNetworkConfig("192.168.1.100", 554, "RTSP") // Network settings
|
||||
.addAuthConfig("admin", "password123") // Authentication
|
||||
.addConfig("recording_enabled", "true") // Use default config rule
|
||||
.addConfig("custom_path", "/data", "string", "Storage path") // Custom config
|
||||
.build();
|
||||
|
||||
BatchUpdateResponse result = configService.batchUpdateDeviceConfigWithResult(deviceId, request);
|
||||
|
||||
// 2. Processing Results
|
||||
log.info("Batch update: {} success, {} failed", result.getSuccess(), result.getFailed());
|
||||
|
||||
for (ProcessedConfigItem item : result.getProcessedItems()) {
|
||||
if ("success".equals(item.getStatus())) {
|
||||
log.info("✅ {} updated (action: {}, hasDefault: {})",
|
||||
item.getConfigKey(), item.getAction(), item.getHasDefault());
|
||||
} else {
|
||||
log.warn("❌ {} failed: {}", item.getConfigKey(), item.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Error Handling
|
||||
if (result.getFailed() > 0) {
|
||||
result.getErrors().forEach(error -> log.warn("Error: {}", error));
|
||||
}
|
||||
```
|
||||
|
||||
#### Response Format
|
||||
- **200 OK**: All configurations updated successfully
|
||||
- **202 Accepted**: Partial success (some configurations failed)
|
||||
- **400 Bad Request**: All configurations failed
|
||||
|
||||
Each processed item includes:
|
||||
- `status`: "success" or "failed"
|
||||
- `action`: "create" or "update"
|
||||
- `hasDefault`: Whether default configuration rules were applied
|
||||
- `finalType`/`finalDescription`: Actually used type and description
|
||||
|
||||
### Device Types
|
||||
- **IPC**: IP Camera devices for video monitoring
|
||||
- **CUSTOM**: Custom device types for sensors, controllers, etc.
|
||||
|
Reference in New Issue
Block a user