diff --git a/iothub/hook_message_work/hook_message_work.go b/iothub/hook_message_work/hook_message_work.go index 4827582..45ada5a 100644 --- a/iothub/hook_message_work/hook_message_work.go +++ b/iothub/hook_message_work/hook_message_work.go @@ -116,12 +116,13 @@ func getRuleChain(etoken *global_model.DeviceAuth) *ruleEntity.RuleDataJson { get, err := cache.ComputeIfAbsentProductRule(key, func(k any) (any, error) { one := services.ProductModelDao.FindOne(k.(string)) rule := ruleService.RuleChainModelDao.FindOne(one.RuleChainId) - var lfData ruleEntity.LfData + var lfData ruleEntity.RuleDataJson err := tool.StringToStruct(rule.RuleDataJson, &lfData) if err != nil { return nil, err } - return ruleEntity.RuleDataJson{Id: rule.Id, LfData: lfData}, nil + lfData.Id = rule.Id + return lfData, nil }) biz.ErrIsNil(err, "缓存读取规则链失败") if ruleData, ok := get.(ruleEntity.RuleDataJson); ok { diff --git a/iothub/netbase/hook_base.go b/iothub/netbase/hook_base.go index 89db010..d3a206c 100644 --- a/iothub/netbase/hook_base.go +++ b/iothub/netbase/hook_base.go @@ -2,6 +2,7 @@ package netbase import ( "encoding/json" + "log" "pandax/apps/device/entity" "pandax/apps/device/services" "pandax/iothub/server/emqxserver/protobuf" @@ -37,6 +38,7 @@ func Auth(authToken string) bool { return false } etoken = services.GetDeviceToken(&device.Device) + log.Println("设置设备协议", device.Product.ProtocolName) etoken.DeviceProtocol = device.Product.ProtocolName err = cache.SetDeviceEtoken(authToken, etoken.GetMarshal(), time.Hour*24*365) if err != nil { diff --git a/pkg/initialize/event.go b/pkg/initialize/event.go index 96e90d4..11f7a4d 100644 --- a/pkg/initialize/event.go +++ b/pkg/initialize/event.go @@ -19,10 +19,11 @@ func InitEvents() { RuleChainId: ruleId, }) if list != nil { - var lfData ruleEntity.LfData + var lfData ruleEntity.RuleDataJson tool.StringToStruct(codeData, &lfData) + lfData.Id = ruleId for _, product := range *list { - cache.PutProductRule(product.Id, ruleEntity.RuleDataJson{Id: ruleId, LfData: lfData}) + cache.PutProductRule(product.Id, lfData) } } }) diff --git a/pkg/rule_engine/engine_data.go b/pkg/rule_engine/engine_data.go index e993d53..d7d771c 100644 --- a/pkg/rule_engine/engine_data.go +++ b/pkg/rule_engine/engine_data.go @@ -22,12 +22,14 @@ func GetDebugDataPage(page, pageSize int, ruleId, nodeId string) (int64, []messa } offset := pageSize * (page - 1) if data, ok := ruleChainDebugData.Data[ruleId]; ok { - total := len(data.Get(nodeId).Items) - end := offset + pageSize - if end >= total { - end = total - 1 + if data.Get(nodeId) != nil { + total := len(data.Get(nodeId).Items) + end := offset + pageSize + if end >= total { + end = total - 1 + } + return int64(total), data.Get(nodeId).Items[offset:end] } - return int64(total), data.Get(nodeId).Items[offset:end] } return 0, nil } diff --git a/pkg/rule_engine/message/node_debug_data.go b/pkg/rule_engine/message/node_debug_data.go index de3ac2b..73cc869 100644 --- a/pkg/rule_engine/message/node_debug_data.go +++ b/pkg/rule_engine/message/node_debug_data.go @@ -119,7 +119,7 @@ func (d *NodeDebugData) Clear(nodeId string) { // DebugData 调试数据 // OnDebug 回调函数提供的数据 type DebugData struct { - Ts string + Ts string `json:"ts"` NodeId string `json:"nodeId"` MsgId string `json:"msgId"` DebugType string `json:"debugType"` // In or Out