From b2412719dc4cb05e4e3eef1dcfe0a1f4d7f10000 Mon Sep 17 00:00:00 2001 From: PandaX <18610165312@163.com> Date: Wed, 18 Oct 2023 11:21:51 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=98=E5=8C=96]=E4=BD=BF=E7=94=A8tsl?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=BB=98=E8=AE=A4=E5=80=BC=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=BD=B1=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/device/api/device.go | 15 --------------- iothub/hook_message_work/hook_message_work.go | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/apps/device/api/device.go b/apps/device/api/device.go index 800d611..87bc243 100644 --- a/apps/device/api/device.go +++ b/apps/device/api/device.go @@ -10,13 +10,11 @@ import ( "github.com/PandaXGO/PandaKit/biz" "github.com/PandaXGO/PandaKit/model" "github.com/PandaXGO/PandaKit/restfulx" - "pandax/apps/device/tsl" "pandax/apps/device/util" "pandax/pkg/cache" "pandax/pkg/global" "pandax/pkg/global_model" "pandax/pkg/shadow" - "pandax/pkg/tool" "strings" "time" @@ -116,19 +114,6 @@ func (p *DeviceApi) GetDeviceStatus(rc *restfulx.ReqCtx) { if v, ok := rs[tel.Key]; ok { sdv.Value = v.Value sdv.Time = v.UpdatedAt - // 如果 - if classify == global.TslTelemetryType && (tel.Type == "bool" || tel.Type == "enum") { - var boolDefine tsl.ValueType - err := tool.MapToStruct(tel.Define, &boolDefine) - if err != nil { - continue - } - boolDefine.Type = tel.Type - value := boolDefine.ConvertValue(v.Value) - if val, ok := value.(string); ok && val != "" { - sdv.Value = val - } - } } else { if classify == global.TslAttributesType { if value, ok := tel.Define["default_value"]; ok { diff --git a/iothub/hook_message_work/hook_message_work.go b/iothub/hook_message_work/hook_message_work.go index c0a7666..58a3049 100644 --- a/iothub/hook_message_work/hook_message_work.go +++ b/iothub/hook_message_work/hook_message_work.go @@ -7,6 +7,7 @@ import ( "github.com/PandaXGO/PandaKit/biz" "pandax/apps/device/entity" "pandax/apps/device/services" + "pandax/apps/device/tsl" ruleEntity "pandax/apps/rule/entity" ruleService "pandax/apps/rule/services" "pandax/iothub/netbase" @@ -178,7 +179,20 @@ func SetDeviceShadow(etoken *global_model.DeviceAuth, msgVals map[string]interfa biz.ErrIsNilAppendErr(err, "设置设备影子点失败") } if message.TelemetryMes == msgType { - err := shadow.DeviceShadowInstance.SetDevicePoint(etoken.Name, global.TslTelemetryType, tel.Key, msgVals[tel.Key]) + var value interface{} + // tsl转化 + var tslValue tsl.ValueType + err := tool.MapToStruct(tel.Define, &tslValue) + if err != nil { + value = msgVals[tel.Key] + } else { + tslValue.Type = tel.Type + value = tslValue.ConvertValue(msgVals[tel.Key]) + if value == nil { + value = msgVals[tel.Key] + } + } + err = shadow.DeviceShadowInstance.SetDevicePoint(etoken.Name, global.TslTelemetryType, tel.Key, value) biz.ErrIsNilAppendErr(err, "设置设备影子点失败") } }