From 759c5b9f8ef6c503f62da3b766a580a4dd6fa026 Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期一, 09 十二月 2019 18:23:21 +0800 Subject: [PATCH] es模块儿做成so --- cache/cache.go | 71 ++++++++++++++++++++++++++++------- 1 files changed, 56 insertions(+), 15 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 74aff22..9f4381d 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -6,6 +6,7 @@ "basic.com/pubsub/protomsg.git" "basic.com/valib/gopherdiscovery.git" "basic.com/valib/logger.git" + "encoding/json" "errors" "fmt" "github.com/gogo/protobuf/proto" @@ -49,7 +50,9 @@ initTimeRules() //鍒濆鍖栨椂闂磋鍒欑紦瀛� - initCameraTaskRules() //鍒濆鍖栨憚鍍忔満浠诲姟瑙勫垯缂撳瓨 + initCameraTaskRules() //鍒濆鍖栨憚鍍忔満浠诲姟瑙勫垯缂撳瓨鎸夋憚鍍忔満 + + initCameraTaskRulesAll() // 鍒濆鍖栨憚鍍忔満浠诲姟瑙勫垯缂撳瓨鍏ㄩ儴 initCamera() //鍒濆鍖栨憚鍍忔満淇℃伅 @@ -84,6 +87,7 @@ initCameraTaskRules() case protomsg.TableChanged_T_CameraTaskArgs: //鏇存柊鎽勫儚鏈鸿鍒欓厤缃弬鏁� initCameraTaskRules() + initCameraTaskRulesAll() case protomsg.TableChanged_T_Sdk: //鏇存柊sdk閰嶇疆 initSdks() default: @@ -126,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 @@ -141,9 +155,13 @@ var api dbapi.DicApi flag, dics := api.FindByType("") if flag { - for key, dics := range dics.(map[string][]Dic) { - for _,dic := range dics { - cMap.Set(PREFIX_DIC+key+dic.value, dic) + var dicss map[string][]Dic + b, _ := json.Marshal(dics) + if err := json.Unmarshal(b, &dicss); err == nil { + for key, dics1 := range dicss { + for _, dic := range dics1 { + cMap.Set(PREFIX_DIC + key + dic.Value, dic) + } } } } @@ -158,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("") @@ -194,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) @@ -213,6 +245,15 @@ return nil } } +//鏍规嵁鎽勫儚鏈篿d浠庣紦瀛樹腑鑾峰彇鎽勫儚鏈虹殑浠诲姟瑙勫垯璁剧疆 +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) @@ -222,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 @@ -253,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"` } -- Gitblit v1.8.0