---
panlei
2019-06-22 7af9bc6b2a6a5beffccb19205afd263da1853f45
ruleserver/ruleToformula.go
@@ -188,11 +188,17 @@
// 将字符串格式的坐标序列化为Point格式
func Json2points(areaPoints string) []Point {
   var pts []Point
   err := json.Unmarshal([]byte(areaPoints), &pts)
   if err != nil {
      fmt.Println("json.Unmarshal错误", err)
      panic("序列化坐标异常,程序退出")
   if areaPoints == "" {
      pts = append(pts,Point{0,0})
      pts = append(pts,Point{0,540})
      pts = append(pts,Point{960,540})
      pts = append(pts,Point{960,0})
   } else {
      err := json.Unmarshal([]byte(areaPoints), &pts)
      if err != nil {
         fmt.Println("json.Unmarshal错误", err)
         panic("序列化坐标异常,程序退出")
      }
   }
   return pts
}
@@ -300,14 +306,20 @@
         filterRule(groupRule.Rules[j], &areaMap)
      }
      for j := 0; j < len(groupRule.Rules); j++ {
         // 再过其他数据 这步直接得到结果(真或假)
         // 再过其他数据 这步直接得到结果(真或假) 过目标数量
         flag := transferParameters(groupRule.Rules[j], &areaMap)
         if flag != "" {
            fmt.Println("得出的结果", flag)
            completeFormula = completeFormula + groupRule.Rules[j].RuleWithPre + "" + flag
         }
      }
      if completeFormula == "" {
         flag := splice1(&areaMap)
         if flag != "" {
            fmt.Println("强行拼凑一个人数是否大于0的结果", flag)
            completeFormula = flag
         }
      }
      for j := 0; j < len(groupRule.Rules); j++ {
         // 这步过的是时间规则(时间段等)
         flag := timeRuleResult(groupRule.Rules[j], &areaMap)
@@ -316,10 +328,12 @@
            completeFormula = completeFormula + groupRule.Rules[j].RuleWithPre + "" + flag
         }
      }
      for j := 0; j < len(groupRule.Rules); j++ {
         // 最后过持续时间等时间维度的条件
         duration(groupRule.Rules[j], &areaMap)
      }
   }
   fmt.Println("拼出的数学公式为:==== ", completeFormula)
   if completeFormula != "" {
@@ -405,13 +419,12 @@
               formula = strconv.FormatFloat(arg.size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式
            }
            expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式
            result, _ := expression.Evaluate(nil)                      // 得到数学公式的结果
            result, _ := expression.Evaluate(nil)          // 得到数学公式的结果
            if result.(bool) {
               am.filterData = append(am.filterData, arg) // 得到符合条件的过滤数据
            }
         }
         am.targetNum = len(am.filterData) // 把符合条件的目标数量更新到targetNum字段
         //fmt.Println("筛选完后的内容:", am)
      }
   }
}
@@ -439,7 +452,14 @@
      }
   }
}
// 冗余拼接
func splice1 (am *AreaMap) string {
   args := am.targetNum
   formula := strconv.Itoa(args) + " "  + ">" + "0"
   expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式
   result, _ := expression.Evaluate(nil)                      // 得到数学公式的结果
   return strconv.FormatBool(result.(bool))
}
// 给数据库的规则表达式代参 args: 一条子规则,区域数据
func transferParameters(rule *protomsg.Rule, am *AreaMap) string {
   if rule.PolygonId == am.areaId { // 首先规则所对应的区域id要跟区域数据的id对的上
@@ -473,6 +493,8 @@
         } else {
            return "false"
         }
      } else {
      }
   }