支持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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user