| | |
| | | package esutil |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | | "io/ioutil" |
| | | "net/http" |
| | | "time" |
| | | "bytes" |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | | "io/ioutil" |
| | | "net/http" |
| | | "time" |
| | | |
| | | "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{}) []*protomsg.Baseinfo { |
| | | var baseinfos []*protomsg.Baseinfo |
| | | func Parsesources(sources []map[string]interface{}) (esinfos []*protomsg.Esinfo) { |
| | | var ok bool |
| | | for _, source := range sources { |
| | | var tmpinfo protomsg.Baseinfo |
| | | 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) |
| | | 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 |
| | | baseinfos = append(baseinfos, &tmpinfo) |
| | | // name, _:= Dbtablename(tmpinfo.TableId) |
| | | // tmpinfo.TableName= name |
| | | // binfos.Infos = append(binfos.Infos, &tmpinfo) |
| | | |
| | | } |
| | | return baseinfos |
| | | return |
| | | } |
| | | //解析底库人员结构 |
| | | func Dbpersonbyid(sources []map[string]interface{}) (tmpinfos []protomsg.Dbperson) { |
| | | var ok bool |
| | | |
| | | var tmpinfo protomsg.Dbperson |
| | | for _, source := range sources{ |
| | | tmpinfo.FaceFeature, ok = source["faceFeature"].(string) |
| | | if !ok { |
| | | continue |
| | | } |
| | | |
| | | tmpinfo.Id, 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) |
| | | Isnil("monitorLevel",ok) |
| | | tmpinfo.UpdateTime,ok = source["updateTime"].(string) |
| | | Isnil("updateTime",ok) |
| | | tmpinfo.Age,ok = source["age"].(string) |
| | | Isnil("age", ok) |
| | | |
| | | isDelete,ok := source["isDelete"].(float64) |
| | | if ok { |
| | | tmpinfo.IsDelete= int32(isDelete) |
| | | } |
| | | Isnil("isDelete", ok) |
| | | |
| | | enable,ok := source["enable"].(float64) |
| | | if ok { |
| | | tmpinfo.Enable= int32(enable) |
| | | } |
| | | Isnil("endTime", ok) |
| | | |
| | | tmpinfo.Reserved,ok = source["reserved"].(string) |
| | | Isnil("reserved",ok) |
| | | tmpinfo.PicDesc,ok = source["picDesc"].(string) |
| | | Isnil("picDesc",ok) |
| | | tmpinfo.CreateTime,ok = source["createTime"].(string) |
| | | Isnil("createTime",ok) |
| | | tmpinfo.CreateBy,ok = source["createBy"].(string) |
| | | Isnil("createBy",ok) |
| | | |
| | | //根据 tableid 获取 tablename |
| | | //name, _:= Dbtablename(tmpinfo.TableId) |
| | | //tmpinfo.TableName= name |
| | | tmpinfos = append(tmpinfos, tmpinfo) |
| | | } |
| | | |
| | | return tmpinfos |
| | | } |
| | | |
| | | //解析底库结构 |
| | | func Dbtablebyid(sources []map[string]interface{}) (tmpinfos []protomsg.Dbtable) { |
| | | var ok bool |
| | | |
| | | var tmpinfo protomsg.Dbtable |
| | | for _, source := range sources{ |
| | | |
| | | tmpinfo.Id, ok = source["id"].(string) |
| | | if !ok { |
| | | continue |
| | | } |
| | | tmpinfo.TableName,ok = source["tableName"].(string) |
| | | Isnil("tableName", ok) |
| | | tmpinfo.TableType,ok = source["tableType"].(string) |
| | | Isnil("tableType", ok) |
| | | tmpinfo.CreateBy,ok = source["createBy"].(string) |
| | | Isnil("createBy", ok) |
| | | tmpinfo.TableDesc,ok = source["tableDesc"].(string) |
| | | Isnil("tableDesc", ok) |
| | | tmpinfo.BwType,ok = source["bwType"].(string) |
| | | Isnil("bwType", ok) |
| | | tmpinfo.StartTime,ok = source["startTime"].(string) |
| | | Isnil("startTime", ok) |
| | | tmpinfo.EndTime,ok = source["endTime"].(string) |
| | | Isnil("endTime", ok) |
| | | |
| | | isDelete,ok := source["isDelete"].(float64) |
| | | if ok { |
| | | tmpinfo.IsDelete= int32(isDelete) |
| | | } |
| | | Isnil("isDelete", ok) |
| | | |
| | | enable,ok := source["enable"].(float64) |
| | | if ok { |
| | | tmpinfo.Enable= int32(enable) |
| | | } |
| | | Isnil("endTime", ok) |
| | | |
| | | tmpinfo.CreateTime,ok = source["createTime"].(string) |
| | | Isnil("createTime", ok) |
| | | tmpinfo.UpdateTime,ok = source["updateTime"].(string) |
| | | Isnil("updateTime", ok) |
| | | tmpinfo.IsForever,ok = source["isForever"].(string) |
| | | Isnil("isForever", ok) |
| | | tmpinfo.IsSync,ok = source["isSync"].(string) |
| | | Isnil("isSync", ok) |
| | | tmpinfo.AnalyServerId,ok = source["analyServerId"].(string) |
| | | Isnil("analyServerId", ok) |
| | | |
| | | tmpinfos = append(tmpinfos, tmpinfo) |
| | | } |
| | | |
| | | return tmpinfos |
| | | } |
| | | |
| | | func Sourcelist(buf []byte)(sources []map[string]interface{}, err error){ |
| | |
| | | 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!") |