支持ota升级结果相应处理
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -65,22 +64,34 @@ func NewAreaControllerResponse(ac *models.AreaController) (*AreaControllerRespon
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var props map[string]interface{}
|
||||
// 解析 firmware_version
|
||||
var firmwareVersion string
|
||||
// 使用模型上的辅助方法来解析强类型属性
|
||||
acProps := &models.AreaControllerProperties{}
|
||||
if err := ac.ParseProperties(acProps); err == nil {
|
||||
firmwareVersion = acProps.FirmwareVersion
|
||||
}
|
||||
// 如果解析出错,firmwareVersion 将保持为空字符串,这通常是可接受的降级行为
|
||||
|
||||
// 解析完整的 properties 以便向后兼容或用于其他未知属性
|
||||
var allProps map[string]interface{}
|
||||
if len(ac.Properties) > 0 && string(ac.Properties) != "null" {
|
||||
if err := json.Unmarshal(ac.Properties, &props); err != nil {
|
||||
return nil, fmt.Errorf("解析区域主控属性失败 (ID: %d): %w", ac.ID, err)
|
||||
// 这里我们使用通用的 ParseProperties 方法
|
||||
if err := ac.ParseProperties(&allProps); err != nil {
|
||||
return nil, fmt.Errorf("解析区域主控完整属性失败 (ID: %d): %w", ac.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
return &AreaControllerResponse{
|
||||
ID: ac.ID,
|
||||
Name: ac.Name,
|
||||
NetworkID: ac.NetworkID,
|
||||
Location: ac.Location,
|
||||
Status: ac.Status,
|
||||
Properties: props,
|
||||
CreatedAt: ac.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: ac.UpdatedAt.Format(time.RFC3339),
|
||||
ID: ac.ID,
|
||||
Name: ac.Name,
|
||||
NetworkID: ac.NetworkID,
|
||||
FirmwareVersion: firmwareVersion,
|
||||
Location: ac.Location,
|
||||
Status: ac.Status,
|
||||
Properties: allProps, // 填充完整的 properties
|
||||
CreatedAt: ac.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: ac.UpdatedAt.Format(time.RFC3339),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -78,14 +78,15 @@ type DeviceResponse struct {
|
||||
|
||||
// AreaControllerResponse 定义了返回给客户端的单个区域主控信息的结构
|
||||
type AreaControllerResponse struct {
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
NetworkID string `json:"network_id"`
|
||||
Location string `json:"location"`
|
||||
Status string `json:"status"`
|
||||
Properties map[string]interface{} `json:"properties"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
NetworkID string `json:"network_id"`
|
||||
FirmwareVersion string `json:"firmware_version"`
|
||||
Location string `json:"location"`
|
||||
Status string `json:"status"`
|
||||
Properties map[string]interface{} `json:"properties"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
// DeviceTemplateResponse 定义了返回给客户端的单个设备模板信息的结构
|
||||
|
||||
Reference in New Issue
Block a user