mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[fix] 设备属性读取错误
This commit is contained in:
@@ -88,7 +88,7 @@ func (p *DeviceApi) GetDevice(rc *restfulx.ReqCtx) {
|
||||
}
|
||||
|
||||
// GetDeviceStatus 获取Device状态信息
|
||||
func (p *DeviceApi) GetDeviceStatus(rc *restfulx.ReqCtx) {
|
||||
func (p *DeviceApi) GetDevigitceStatus(rc *restfulx.ReqCtx) {
|
||||
id := restfulx.PathParam(rc, "id")
|
||||
classify := restfulx.QueryParam(rc, "classify")
|
||||
device, err := p.DeviceApp.FindOne(id)
|
||||
@@ -114,16 +114,9 @@ func (p *DeviceApi) GetDeviceStatus(rc *restfulx.ReqCtx) {
|
||||
}
|
||||
// 有直接从设备影子中查询,没有查询时序数据库最后一条记录
|
||||
if point, ok := rs[tel.Key]; ok {
|
||||
if classify == global.TslTelemetryType {
|
||||
value := point.Value
|
||||
sdv.Time = point.UpdatedAt
|
||||
sdv.Value = value
|
||||
}
|
||||
if classify == global.TslAttributesType {
|
||||
if value, ok := tel.Define["default_value"]; ok {
|
||||
sdv.Value = value
|
||||
}
|
||||
}
|
||||
value := point.Value
|
||||
sdv.Time = point.UpdatedAt
|
||||
sdv.Value = value
|
||||
} else {
|
||||
var table string
|
||||
if classify == global.TslTelemetryType {
|
||||
@@ -136,6 +129,15 @@ func (p *DeviceApi) GetDeviceStatus(rc *restfulx.ReqCtx) {
|
||||
one, err := global.TdDb.GetOne(sql, strings.ToLower(tel.Key), table)
|
||||
if err == nil {
|
||||
sdv.Value = one[strings.ToLower(tel.Key)]
|
||||
sdv.Time = time.Now()
|
||||
} else {
|
||||
if value, ok := tel.Define["default_value"]; ok {
|
||||
sdv.Value = value
|
||||
sdv.Time = time.Now()
|
||||
} else {
|
||||
sdv.Value = "未知"
|
||||
sdv.Time = time.Now()
|
||||
}
|
||||
}
|
||||
}
|
||||
res = append(res, sdv)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"pandax/kit/biz"
|
||||
"pandax/kit/model"
|
||||
"pandax/kit/restfulx"
|
||||
@@ -65,8 +66,9 @@ func (p *ProductTemplateApi) InsertProductTemplate(rc *restfulx.ReqCtx) {
|
||||
stable := data.Pid + "_" + data.Classify
|
||||
if data.Classify == entity.TELEMETRY_TSL {
|
||||
if data.Type == "string" {
|
||||
if maxLength, ok := data.Define["maxLength"].(float64); ok {
|
||||
len = int(maxLength)
|
||||
if maxLength, ok := data.Define["maxLength"].(json.Number); ok {
|
||||
length, _ := maxLength.Int64()
|
||||
len = int(length)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +97,10 @@ func (p *ProductTemplateApi) UpdateProductTemplate(rc *restfulx.ReqCtx) {
|
||||
if data.Classify == entity.TELEMETRY_TSL {
|
||||
stable = data.Pid + "_" + entity.TELEMETRY_TSL
|
||||
if data.Type == "string" {
|
||||
len = int(data.Define["length"].(int64))
|
||||
if maxLength, ok := data.Define["maxLength"].(json.Number); ok {
|
||||
length, _ := maxLength.Int64()
|
||||
len = int(length)
|
||||
}
|
||||
}
|
||||
global.TdDb.DelSTableField(stable, one.Key)
|
||||
err := global.TdDb.AddSTableField(stable, data.Key, data.Type, len)
|
||||
|
||||
Reference in New Issue
Block a user