panlei
2019-08-30 77a05fa27d55ea7e39aee47f71cb5f74308e5e0e
ruleserver/timeTicker.go
@@ -3,6 +3,7 @@
import (
   "fmt"
   "ruleprocess/logger"
   "ruleprocess/structure"
   "strings"
   "time"
)
@@ -18,7 +19,7 @@
   InitN        int       // 赋值后就不变的初始值
   BufferFlag   int       // 缓冲容错位 连续n帧false才为false
   AlarmFlag    bool      // 报警标志位 定时器开启后第一次报警时会被置为true 往后再来报警也不会插进ES
   CacheSdkData ResultMsg // 定时器的缓存数据 持续时间类的开启定时器时要缓存一帧
   CacheSdkData structure.ResultMsg // 定时器的缓存数据 持续时间类的开启定时器时要缓存一帧
   GroupId      string    // 联动规则需要记录下此时的规则组id
   RuleResults  []*RuleResult
}
@@ -28,12 +29,12 @@
   Sort        int32     // 摄像机在规则组中序号
   Result      string    // 摄像机过滤数据得出的结果
   RuleWithPre string    // 摄像机之间的连接符
   CacheData   ResultMsg // 缓存当前帧数据
   CacheData   structure.ResultMsg // 缓存当前帧数据
}
func TimeTicker() {
   logger.Info("定时器执行了")
   fmt.Println("定时器执行了")
   //logger.Info("定时器执行了")
   //fmt.Println("定时器执行了")
   ticker := time.NewTicker(1 * time.Second)
   go func(ticker *time.Ticker) {
      defer ticker.Stop()
@@ -69,7 +70,7 @@
}
// 判断是否符合定时器条件
func TimerAlarm(args map[string]interface{}, groupId string, result bool) (string) {
func TimerAlarm(oth *structure.Others, groupId string, result bool) (string) {
   var flagTime string //
   // 判断有无此规则组的定时器
   flag := false
@@ -86,15 +87,15 @@
               if timeEle.N == 0 && timeEle.AlarmFlag {
                  logger.Debug("-------------------------符合持续时间规则但并不是首次,不报警")
                  flagTime = "11"
                  args["timeLabel"] = flagTime
                  oth.TimeLabel = flagTime
               }
               if timeEle.N == 0 && !timeEle.AlarmFlag { // 这组规则的定时器要全部等于0   暂且认为一组规则只有一个定时器
                  logger.Debug("———————————-------------首次符合持续时间规则并报警")
                  flagTime = "10"
                  timeEle.AlarmFlag = true
                  args["cacheData"] = []ResultMsg{}
                  args["cacheData"] = append(args["cacheData"].([]ResultMsg),timeEle.CacheSdkData)
                  args["timeLabel"] = flagTime
                  oth.CacheData = []structure.ResultMsg{}
                  oth.CacheData = append(oth.CacheData,timeEle.CacheSdkData)
                  oth.TimeLabel = flagTime
               }
               if timeEle.N != 0 {
                  flagTime = "00"
@@ -111,7 +112,7 @@
                  if timeEle.BufferFlag == 0 {
                     logger.Debug("------------------------------杀死定时器,报警此帧状态改变的数据,此时的计数器的值为", timeEle.N)
                     flagTime = "12"
                     args["timeLabel"] = flagTime
                     oth.TimeLabel = flagTime
                     delete(TimeEleList, k)
                  } else {
                     if timeEle.BufferFlag > 0 {
@@ -127,7 +128,7 @@
   } else { // 无定时器
      if result {
         flagTime = "01"
         args["timeLabel"] = flagTime
         oth.TimeLabel = flagTime
      } else {
         flagTime = "00"
      }
@@ -143,7 +144,7 @@
func (p SubList) Less(i, j int) bool { return p[i].Sort < p[j].Sort }
// 结构体根据某字段排序
type resultList []*LittleRuleResult
type resultList []*structure.LittleRuleResult
func (p resultList) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func (p resultList) Len() int           { return len(p) }