liuxiulin 1 ngày trước cách đây
mục cha
commit
85a29cc1bc
1 tập tin đã thay đổi với 7 bổ sung3 xóa
  1. 7 3
      pkg/ruleEngine/nodes/temp_alarm_node.go

+ 7 - 3
pkg/ruleEngine/nodes/temp_alarm_node.go

@@ -26,6 +26,7 @@ type TempAlarmNode struct {
 
 func (t *TempAlarmNode) Init(ctx ruleEngine.Context, config string) error {
 	t.pool = grpool.New(10)
+	fmt.Printf("initConfig:---------------------------%s\r\n", config)
 	if config == "" {
 		t.config = &TempAlarmNodeConfig{}
 	} else {
@@ -156,7 +157,10 @@ func (t *TempAlarmNode) evaluateConditions(message *protocol.Message) bool {
 
 	data := make(map[string]interface{})
 	var ok bool
-	if data, ok = message.MetaData["status"].(map[string]interface{}); !ok {
+	j := gjson.New(message.Data)
+	fmt.Printf("Data------------------:%s\r\n", j.MustToJsonString())
+	status := j.Get("status")
+	if data, ok = status.(map[string]interface{}); !ok {
 		return false
 	}
 	// 判断设备是否开机
@@ -167,7 +171,7 @@ func (t *TempAlarmNode) evaluateConditions(message *protocol.Message) bool {
 	for _, rule := range t.config.Rules {
 		var results []bool
 		for _, cond := range rule.Conditions {
-			results = append(results, t.CheckValue(cond.Value, data[cond.Field], cond.Type, cond.Operator))
+			results = append(results, t.checkValue(cond.Value, data[cond.Field], cond.Type, cond.Operator))
 		}
 		// 应用逻辑运算
 		if rule.LogicalOp == 1 {
@@ -267,7 +271,7 @@ func (t *TempAlarmNode) checkInt(target, value, operator int) bool {
 }
 
 // CheckValue 目标值验证
-func (t *TempAlarmNode) CheckValue(target string, value interface{}, fieldType, operator int) bool {
+func (t *TempAlarmNode) checkValue(target string, value interface{}, fieldType, operator int) bool {
 	var strValue string
 	var intValue int
 	switch value.(type) {