panlei
2019-12-09 759c5b9f8ef6c503f62da3b766a580a4dd6fa026
cache/cache.go
@@ -50,7 +50,9 @@
   initTimeRules() //初始化时间规则缓存
   initCameraTaskRules() //初始化摄像机任务规则缓存
   initCameraTaskRules() //初始化摄像机任务规则缓存按摄像机
   initCameraTaskRulesAll() // 初始化摄像机任务规则缓存全部
   initCamera() //初始化摄像机信息
@@ -85,6 +87,7 @@
      initCameraTaskRules()
   case protomsg.TableChanged_T_CameraTaskArgs: //更新摄像机规则配置参数
      initCameraTaskRules()
      initCameraTaskRulesAll()
   case protomsg.TableChanged_T_Sdk: //更新sdk配置
      initSdks()
   default:
@@ -127,6 +130,16 @@
      cMap.Set(PREFIX_POLYGON+k, v)
   }
}
// 缓存区域并不根据id
func initPolygonsById() {
   var api dbapi.CameraApi
   data := api.FindAllPolygons()
   for _, item := range data {
      if item.Type != "line" {
         cMap.Set(PREFIX_POLYGON+item.Id, item)
      }
   }
}
func initTimeRules() {
   var api dbapi.CameraApi
@@ -144,17 +157,14 @@
   if flag {
      var dicss map[string][]Dic
      b, _ := json.Marshal(dics)
      if err := json.Unmarshal(b, &dicss) ; err == nil {
      if err := json.Unmarshal(b, &dicss); err == nil {
         for key, dics1 := range dicss {
            for _,dic := range dics1 {
               logger.Info("车牌字典:",dic.value,dic.Name,dic.Sort)
               logger.Debug("字典缓存初始化",PREFIX_DIC+key+dic.value, dic)
               cMap.Set(PREFIX_DIC+key+dic.value, dic)
            for _, dic := range dics1 {
               cMap.Set(PREFIX_DIC + key + dic.Value, dic)
            }
         }
      }
   }
   logger.Info("取字典缓存:",GetDic(PREFIX_DIC+"nCarColor1"))
}
func initCameraTaskRules() {
@@ -166,6 +176,11 @@
   }
}
func initCameraTaskRulesAll() {
   var api dbapi.CameraTaskArgsApi
   all := api.FindAll()
   cMap.Set(PREFIX_RULE, all)
}
func initSdks() {
   var api dbapi.SdkApi
   sdks := api.FindAll("")
@@ -202,6 +217,15 @@
   }
}
func GetPolygonsById(id string) *protomsg.CameraPolygon {
   obj, b := cMap.Get(PREFIX_POLYGON + id)
   if b {
      return obj.(*protomsg.CameraPolygon)
   } else {
      return nil
   }
}
//从缓存中获取时间规则
func GetTimeRuleById(id string) (exist bool, rule protomsg.CameraTimerule) {
   obj, b := cMap.Get(PREFIX_TIME + id)
@@ -221,6 +245,15 @@
      return nil
   }
}
//根据摄像机id从缓存中获取摄像机的任务规则设置
func GetCameraTaskRulesAll() []*protomsg.TaskGroupArgs {
   obj, b := cMap.Get(PREFIX_RULE)
   if b {
      return obj.([]*protomsg.TaskGroupArgs)
   } else {
      return nil
   }
}
func GetSdkById(sdkId string) (sdk protomsg.Sdk, err error) {
   obj, b := cMap.Get(PREFIX_SDK + sdkId)
@@ -230,16 +263,16 @@
      return sdk, errors.New("sdk not found")
   }
}
// 获取字典值
func GetDic(key string) (value string) {
   obj, b := cMap.Get(PREFIX_SDK + key)
func GetDic(key string) (name string) {
   obj, b := cMap.Get(PREFIX_DIC + key)
   if b {
      return obj.(Dic).value
      return obj.(Dic).Name
   } else {
      return ""
   }
}
func initSoData() {
   var api dbapi.SoApi
@@ -261,11 +294,11 @@
}
type Dic struct {
   Id          string
   value       string
   Name        string
   Type        string
   Description string
   Sort        int
   Parent_id   string
   Id          string `json:"id"`
   Value       string `json:"value"`
   Name        string `json:"name"`
   Type        string `json:"type"`
   Description string `json:"description"`
   Sort        int    `json:"sort"`
   Parent_id   string `json:"parent_id"`
}