|
@@ -182,7 +182,7 @@ func GetDeviceStatusByFields(device *models.Device, config *productconfig.Produc
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if reply.Status == "" {
|
|
if reply.Status == "" {
|
|
|
- r.JSON(http.StatusOK, DeviceStatusFieldResponse{Data: *gjson.New("")})
|
|
|
|
|
|
|
+ r.JSON(http.StatusOK, DeviceStatusFieldResponse{Data: map[string]interface{}{}})
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -193,22 +193,55 @@ func GetDeviceStatusByFields(device *models.Device, config *productconfig.Produc
|
|
|
r.JSON(http.StatusOK, renderError(ErrSystemFault, err))
|
|
r.JSON(http.StatusOK, renderError(ErrSystemFault, err))
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+ server.Log.Debugf("GetDeviceStatusByFields status keys: %v", func() []string {
|
|
|
|
|
+ keys := make([]string, 0, len(status))
|
|
|
|
|
+ for k := range status {
|
|
|
|
|
+ keys = append(keys, k)
|
|
|
|
|
+ }
|
|
|
|
|
+ return keys
|
|
|
|
|
+ }())
|
|
|
|
|
|
|
|
// 按指定字段过滤
|
|
// 按指定字段过滤
|
|
|
- j := gjson.New("")
|
|
|
|
|
|
|
+ filtered := make(map[string]interface{})
|
|
|
for _, field := range requestFields {
|
|
for _, field := range requestFields {
|
|
|
if val, ok := status[field]; ok {
|
|
if val, ok := status[field]; ok {
|
|
|
- _ = j.Set(field, val)
|
|
|
|
|
|
|
+ filtered[field] = val
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- r.JSON(http.StatusOK, DeviceStatusFieldResponse{Data: *j})
|
|
|
|
|
|
|
+ r.JSON(http.StatusOK, DeviceStatusFieldResponse{Data: filtered})
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// GetDeviceLatestStatus get device latest status
|
|
|
|
|
-func GetDeviceLatestStatus() {
|
|
|
|
|
|
|
+// GetDeviceLatestStatus 获取设备最新状态(直接查询,不触发上报)
|
|
|
|
|
+func GetDeviceLatestStatus(device *models.Device, config *productconfig.ProductConfig,
|
|
|
|
|
+ urlparams martini.Params, r render.Render) {
|
|
|
|
|
+ server.Log.Printf("ACTION GetDeviceLatestStatus, identifier:: %v", device.DeviceIdentifier)
|
|
|
|
|
+
|
|
|
|
|
+ // 直接从 DeviceManager 获取存储的状态数据
|
|
|
|
|
+ args := rpcs.ArgsGetStatus{Id: device.DeviceIdentifier}
|
|
|
|
|
+ reply := rpcs.ReplyStatus{}
|
|
|
|
|
+ err := server.RPCCallByName(nil, rpcs.DeviceManagerName, "DeviceManager.GetDeviceStatus", args, &reply)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ server.Log.Errorf("获取设备状态数据失败: %v", err)
|
|
|
|
|
+ r.JSON(http.StatusOK, renderError(ErrSystemFault, err))
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if reply.Status == "" {
|
|
|
|
|
+ r.JSON(http.StatusOK, DeviceStatusResponse{Data: map[string]interface{}{}})
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var status map[string]interface{}
|
|
|
|
|
+ if err := json.Unmarshal([]byte(reply.Status), &status); err != nil {
|
|
|
|
|
+ server.Log.Errorf("解析设备状态数据失败: %v", err)
|
|
|
|
|
+ r.JSON(http.StatusOK, renderError(ErrSystemFault, err))
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ r.JSON(http.StatusOK, DeviceStatusResponse{Data: status})
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// DeviceUpgrade 设备OTA升级
|
|
// DeviceUpgrade 设备OTA升级
|