|
@ -856,7 +856,9 @@ |
|
|
**修改时间**: 2024年 |
|
|
**修改时间**: 2024年 |
|
|
**修改文件**: |
|
|
**修改文件**: |
|
|
- `CoreAgent.Domain/Models/System/DeviceInfo.cs` |
|
|
- `CoreAgent.Domain/Models/System/DeviceInfo.cs` |
|
|
|
|
|
- `CoreAgent.Domain/Models/System/DeviceInfoResponse.cs` (新建) |
|
|
- `CoreAgent.Infrastructure/Services/System/DeviceService.cs` |
|
|
- `CoreAgent.Infrastructure/Services/System/DeviceService.cs` |
|
|
|
|
|
- `CoreAgent.Application/Commands/System/GetSerialNumberCommand.cs` |
|
|
- `CoreAgent.Application/Handlers/System/GetSerialNumberCommandHandler.cs` |
|
|
- `CoreAgent.Application/Handlers/System/GetSerialNumberCommandHandler.cs` |
|
|
|
|
|
|
|
|
**修改内容**: |
|
|
**修改内容**: |
|
@ -866,6 +868,12 @@ |
|
|
- 用于标识是否成功获取到序列号 |
|
|
- 用于标识是否成功获取到序列号 |
|
|
- 提供更准确的成功/失败状态判断 |
|
|
- 提供更准确的成功/失败状态判断 |
|
|
|
|
|
|
|
|
|
|
|
2. **创建DeviceInfoResponse模型** |
|
|
|
|
|
- 创建专门用于API响应的模型 |
|
|
|
|
|
- 只包含 `SerialNumber` 和 `Timestamp` 字段 |
|
|
|
|
|
- 不包含内部状态字段 `IsSuccess` |
|
|
|
|
|
- 确保API响应简洁明了 |
|
|
|
|
|
|
|
|
2. **ParseSerialNumber方法优化** |
|
|
2. **ParseSerialNumber方法优化** |
|
|
- 返回类型从 `string` 改为 `string?`(可空字符串) |
|
|
- 返回类型从 `string` 改为 `string?`(可空字符串) |
|
|
- 失败时返回 `null` 而不是固定字符串 |
|
|
- 失败时返回 `null` 而不是固定字符串 |
|
@ -879,15 +887,17 @@ |
|
|
- 失败时设置 `IsSuccess = false` |
|
|
- 失败时设置 `IsSuccess = false` |
|
|
- 添加更详细的日志记录 |
|
|
- 添加更详细的日志记录 |
|
|
|
|
|
|
|
|
4. **GetSerialNumberCommandHandler优化** |
|
|
4. **GetSerialNumberCommand和GetSerialNumberCommandHandler优化** |
|
|
|
|
|
- 修改命令返回类型为 `ApiActionResult<DeviceInfoResponse>` |
|
|
- 在Handle方法中检查 `deviceInfo.IsSuccess` 字段 |
|
|
- 在Handle方法中检查 `deviceInfo.IsSuccess` 字段 |
|
|
- 成功时返回 `ApiActionResult<DeviceInfo>.Ok()` |
|
|
- 成功时创建 `DeviceInfoResponse` 对象返回,不包含IsSuccess字段 |
|
|
- 失败时返回 `ApiActionResult<DeviceInfo>.Error()` 并设置错误代码 `DEVICE_SN_NOT_FOUND` |
|
|
- 失败时返回 `ApiActionResult<DeviceInfoResponse>.Error()` 并设置错误代码 `DEVICE_SN_NOT_FOUND` |
|
|
- 提供更准确的错误信息 |
|
|
- 提供更准确的错误信息 |
|
|
|
|
|
- 确保API返回的响应模型不包含内部状态字段 |
|
|
|
|
|
|
|
|
5. **具体实现**: |
|
|
5. **具体实现**: |
|
|
```csharp |
|
|
```csharp |
|
|
// DeviceInfo模型 |
|
|
// DeviceInfo模型(内部使用) |
|
|
public class DeviceInfo |
|
|
public class DeviceInfo |
|
|
{ |
|
|
{ |
|
|
public bool IsSuccess { get; set; } |
|
|
public bool IsSuccess { get; set; } |
|
@ -895,6 +905,13 @@ |
|
|
public DateTime Timestamp { get; set; } = DateTime.UtcNow; |
|
|
public DateTime Timestamp { get; set; } = DateTime.UtcNow; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DeviceInfoResponse模型(API响应) |
|
|
|
|
|
public class DeviceInfoResponse |
|
|
|
|
|
{ |
|
|
|
|
|
public string SerialNumber { get; set; } = string.Empty; |
|
|
|
|
|
public DateTime Timestamp { get; set; } = DateTime.UtcNow; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// ParseSerialNumber方法 |
|
|
// ParseSerialNumber方法 |
|
|
private string? ParseSerialNumber(string output) |
|
|
private string? ParseSerialNumber(string output) |
|
|
{ |
|
|
{ |
|
@ -939,11 +956,17 @@ |
|
|
// GetSerialNumberCommandHandler中的使用 |
|
|
// GetSerialNumberCommandHandler中的使用 |
|
|
if (deviceInfo.IsSuccess) |
|
|
if (deviceInfo.IsSuccess) |
|
|
{ |
|
|
{ |
|
|
return ApiActionResult<DeviceInfo>.Ok(deviceInfo, "获取设备序列号成功"); |
|
|
// 创建DeviceInfoResponse对象,不包含IsSuccess字段 |
|
|
|
|
|
var resultDeviceInfo = new DeviceInfoResponse |
|
|
|
|
|
{ |
|
|
|
|
|
SerialNumber = deviceInfo.SerialNumber, |
|
|
|
|
|
Timestamp = deviceInfo.Timestamp |
|
|
|
|
|
}; |
|
|
|
|
|
return ApiActionResult<DeviceInfoResponse>.Ok(resultDeviceInfo, "获取设备序列号成功"); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
return ApiActionResult<DeviceInfo>.Error("获取设备序列号失败", "DEVICE_SN_NOT_FOUND"); |
|
|
return ApiActionResult<DeviceInfoResponse>.Error("获取设备序列号失败", "DEVICE_SN_NOT_FOUND"); |
|
|
} |
|
|
} |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|