[fix] 规则链解析失败

This commit is contained in:
PandaX
2023-10-30 09:26:01 +08:00
parent 3811401667
commit 036e3c32b7
5 changed files with 16 additions and 10 deletions

View File

@@ -116,12 +116,13 @@ func getRuleChain(etoken *global_model.DeviceAuth) *ruleEntity.RuleDataJson {
get, err := cache.ComputeIfAbsentProductRule(key, func(k any) (any, error) { get, err := cache.ComputeIfAbsentProductRule(key, func(k any) (any, error) {
one := services.ProductModelDao.FindOne(k.(string)) one := services.ProductModelDao.FindOne(k.(string))
rule := ruleService.RuleChainModelDao.FindOne(one.RuleChainId) rule := ruleService.RuleChainModelDao.FindOne(one.RuleChainId)
var lfData ruleEntity.LfData var lfData ruleEntity.RuleDataJson
err := tool.StringToStruct(rule.RuleDataJson, &lfData) err := tool.StringToStruct(rule.RuleDataJson, &lfData)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return ruleEntity.RuleDataJson{Id: rule.Id, LfData: lfData}, nil lfData.Id = rule.Id
return lfData, nil
}) })
biz.ErrIsNil(err, "缓存读取规则链失败") biz.ErrIsNil(err, "缓存读取规则链失败")
if ruleData, ok := get.(ruleEntity.RuleDataJson); ok { if ruleData, ok := get.(ruleEntity.RuleDataJson); ok {

View File

@@ -2,6 +2,7 @@ package netbase
import ( import (
"encoding/json" "encoding/json"
"log"
"pandax/apps/device/entity" "pandax/apps/device/entity"
"pandax/apps/device/services" "pandax/apps/device/services"
"pandax/iothub/server/emqxserver/protobuf" "pandax/iothub/server/emqxserver/protobuf"
@@ -37,6 +38,7 @@ func Auth(authToken string) bool {
return false return false
} }
etoken = services.GetDeviceToken(&device.Device) etoken = services.GetDeviceToken(&device.Device)
log.Println("设置设备协议", device.Product.ProtocolName)
etoken.DeviceProtocol = device.Product.ProtocolName etoken.DeviceProtocol = device.Product.ProtocolName
err = cache.SetDeviceEtoken(authToken, etoken.GetMarshal(), time.Hour*24*365) err = cache.SetDeviceEtoken(authToken, etoken.GetMarshal(), time.Hour*24*365)
if err != nil { if err != nil {

View File

@@ -19,10 +19,11 @@ func InitEvents() {
RuleChainId: ruleId, RuleChainId: ruleId,
}) })
if list != nil { if list != nil {
var lfData ruleEntity.LfData var lfData ruleEntity.RuleDataJson
tool.StringToStruct(codeData, &lfData) tool.StringToStruct(codeData, &lfData)
lfData.Id = ruleId
for _, product := range *list { for _, product := range *list {
cache.PutProductRule(product.Id, ruleEntity.RuleDataJson{Id: ruleId, LfData: lfData}) cache.PutProductRule(product.Id, lfData)
} }
} }
}) })

View File

@@ -22,12 +22,14 @@ func GetDebugDataPage(page, pageSize int, ruleId, nodeId string) (int64, []messa
} }
offset := pageSize * (page - 1) offset := pageSize * (page - 1)
if data, ok := ruleChainDebugData.Data[ruleId]; ok { if data, ok := ruleChainDebugData.Data[ruleId]; ok {
total := len(data.Get(nodeId).Items) if data.Get(nodeId) != nil {
end := offset + pageSize total := len(data.Get(nodeId).Items)
if end >= total { end := offset + pageSize
end = total - 1 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 return 0, nil
} }

View File

@@ -119,7 +119,7 @@ func (d *NodeDebugData) Clear(nodeId string) {
// DebugData 调试数据 // DebugData 调试数据
// OnDebug 回调函数提供的数据 // OnDebug 回调函数提供的数据
type DebugData struct { type DebugData struct {
Ts string Ts string `json:"ts"`
NodeId string `json:"nodeId"` NodeId string `json:"nodeId"`
MsgId string `json:"msgId"` MsgId string `json:"msgId"`
DebugType string `json:"debugType"` // In or Out DebugType string `json:"debugType"` // In or Out