From ac4bfc72bf9cd06e8b349a00278047c056d186ed Mon Sep 17 00:00:00 2001 From: 554325746@qq.com <554325746@qq.com> Date: 星期四, 11 七月 2019 10:09:46 +0800 Subject: [PATCH] fix cache --- esutil/EsClient.go | 108 +++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 78 insertions(+), 30 deletions(-) diff --git a/esutil/EsClient.go b/esutil/EsClient.go index d022703..8761092 100644 --- a/esutil/EsClient.go +++ b/esutil/EsClient.go @@ -8,41 +8,90 @@ "net/http" "time" "bytes" + + "basic.com/pubsub/protomsg.git" ) -func GetDbinfo(dbinforequest string)([]byte, error) { - buf , err := EsReq("POST", "http://192.168.1.182:9200/dbtablepersons/dbpersons/_search", []byte(dbinforequest)) - return buf, err -} - - -func Parsesources(sources []map[string]interface{}) []Baseinfo { - var tmpinfo Baseinfo - var baseinfos []Baseinfo +func Parsesources(sources []map[string]interface{}) (esinfos []*protomsg.Esinfo) { var ok bool for _, source := range sources { - + var tmpinfo protomsg.Esinfo tmpinfo.FaceFeature, ok = source["faceFeature"].(string) - Isnil("faceFeature", ok) - tmpinfo.PersonId, ok = source["id"].(string) - Isnil("id", ok) - tmpinfo.TableId, ok = source["tableId"].(string) - Isnil("tableId", ok) - tmpinfo.PersonName,ok = source["personName"].(string) - Isnil("personName", ok) - tmpinfo.PersonPicUrl,ok = source["personPicUrl"].(string) - Isnil("personPicUrl", ok) - tmpinfo.PhoneNum,ok = source["phoneNum"].(string) - Isnil("phoneNum", ok) - tmpinfo.Sex,ok = source["sex"].(string) - Isnil("sex", ok) - tmpinfo.Idcard,ok = source["idCard"].(string) - Isnil("idCard", ok) - tmpinfo.MonitorLevel,ok = source["monitorLevel"].(string) - baseinfos = append(baseinfos, tmpinfo) + if !ok { + continue + } + + tmpinfo.Id, ok = source["id"].(string) + if !ok { + continue + } + tmpinfo.Tableid, ok = source["tableId"].(string) + if !ok { + continue + } + + esinfos = append(esinfos, &tmpinfo) + +// tmpinfo.PersonName,ok = source["personName"].(string) +// Isnil("personName", ok) +// tmpinfo.PersonPicUrl,ok = source["personPicUrl"].(string) +// Isnil("personPicUrl", ok) +// tmpinfo.PhoneNum,ok = source["phoneNum"].(string) +// Isnil("phoneNum", ok) +// tmpinfo.Sex,ok = source["sex"].(string) +// Isnil("sex", ok) +// tmpinfo.Idcard,ok = source["idCard"].(string) +// Isnil("idCard", ok) +// tmpinfo.MonitorLevel,ok = source["monitorLevel"].(string) + + // 鏍规嵁 tableid 鑾峰彇 tablename +// name, _:= Dbtablename(tmpinfo.TableId) +// tmpinfo.TableName= name +// binfos.Infos = append(binfos.Infos, &tmpinfo) + } - return baseinfos + return +} + +func Dbpersonbyid(sources []map[string]interface{}) (protomsg.Baseinfo) { + var ok bool + + var tmpinfo protomsg.Baseinfo + for _, source := range sources{ + tmpinfo.FaceFeature, ok = source["faceFeature"].(string) + if !ok { + continue + } + + tmpinfo.PersonId, ok = source["id"].(string) + if !ok { + continue + } + + tmpinfo.TableId, ok = source["tableId"].(string) + if !ok { + continue + } + + tmpinfo.PersonName,ok = source["personName"].(string) + Isnil("personName", ok) + tmpinfo.PersonPicUrl,ok = source["personPicUrl"].(string) + Isnil("personPicUrl", ok) + tmpinfo.PhoneNum,ok = source["phoneNum"].(string) + Isnil("phoneNum", ok) + tmpinfo.Sex,ok = source["sex"].(string) + Isnil("sex", ok) + tmpinfo.Idcard,ok = source["idCard"].(string) + Isnil("idCard", ok) + tmpinfo.MonitorLevel,ok = source["monitorLevel"].(string) + + //鏍规嵁 tableid 鑾峰彇 tablename + name, _:= Dbtablename(tmpinfo.TableId) + tmpinfo.TableName= name + } + + return tmpinfo } func Sourcelist(buf []byte)(sources []map[string]interface{}, err error){ @@ -52,6 +101,7 @@ if !ok { return nil, errors.New("http response interface can not change map[string]interface{}") } + middle, ok := out["hits"].(map[string]interface{}) if !ok { return nil, errors.New("first hits change error!") @@ -93,13 +143,11 @@ } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err) return nil , err } - return body, nil } -- Gitblit v1.8.0