| | |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | | "io" |
| | | "io/ioutil" |
| | | "net/http" |
| | | "strconv" |
| | | "strings" |
| | | "time" |
| | | |
| | | "basic.com/pubsub/protomsg.git" |
| | | ) |
| | | |
| | | func GetEsDataReq(url string, parama string, isSource bool) map[string]interface{} { |
| | | //fmt.Println("es 查询请求路径" + url) // 配置信息 获取 |
| | | var dat map[string]interface{} |
| | | req, err := http.NewRequest("POST", url, strings.NewReader(parama)) |
| | | req.Header.Add("Content-Type", "application/json") |
| | | timeout := time.Duration(10 * time.Second) //超时时间50ms |
| | | client := &http.Client{Timeout: timeout} |
| | | resp, err := client.Do(req) |
| | | if err != nil { |
| | | fmt.Println(err) |
| | | return dat |
| | | } |
| | | defer resp.Body.Close() |
| | | dec := json.NewDecoder(resp.Body) |
| | | if err := dec.Decode(&dat); err == io.EOF { |
| | | fmt.Println(err.Error()) |
| | | return dat |
| | | } else if err != nil { |
| | | fmt.Println(err.Error()) |
| | | return dat |
| | | } |
| | | // 是否需要 解析 es 返回的 source |
| | | if isSource { |
| | | dat = dat["hits"].(map[string]interface{}) |
| | | var data = make(map[string]interface{}, 2) |
| | | data["total"] = dat["total"] |
| | | sources := []interface{}{} |
| | | for _, value := range dat["hits"].([]interface{}) { |
| | | source := value.(map[string]interface{})["_source"].(map[string]interface{}) |
| | | //source["id"] = source["id"] |
| | | /*sdkType := source["sdkType"] |
| | | if sdkType != nil { |
| | | sdk, _ := strconv.Atoi(sdkType.(string)) |
| | | source["sdkType"] = sdkTypeToValue(sdk) |
| | | }*/ |
| | | sources = append(sources, source) |
| | | } |
| | | data["datalist"] = sources |
| | | return data |
| | | } else { |
| | | return dat |
| | | } |
| | | |
| | | } |
| | | |
| | | func Parsesources(sources []map[string]interface{}) (esinfos []*protomsg.Esinfo) { |
| | | var ok bool |
| | |
| | | esinfos = append(esinfos, &tmpinfo) |
| | | |
| | | // tmpinfo.PersonName,ok = source["personName"].(string) |
| | | // Isnil("personName", ok) |
| | | // //Isnil("personName", ok) |
| | | // tmpinfo.PersonPicUrl,ok = source["personPicUrl"].(string) |
| | | // Isnil("personPicUrl", ok) |
| | | // //Isnil("personPicUrl", ok) |
| | | // tmpinfo.PhoneNum,ok = source["phoneNum"].(string) |
| | | // Isnil("phoneNum", ok) |
| | | // //Isnil("phoneNum", ok) |
| | | // tmpinfo.Sex,ok = source["sex"].(string) |
| | | // Isnil("sex", ok) |
| | | // //Isnil("sex", ok) |
| | | // tmpinfo.Idcard,ok = source["idCard"].(string) |
| | | // Isnil("idCard", ok) |
| | | // //Isnil("idCard", ok) |
| | | // tmpinfo.MonitorLevel,ok = source["monitorLevel"].(string) |
| | | |
| | | // 根据 tableid 获取 tablename |
| | |
| | | } |
| | | |
| | | tmpinfo.PicDate,ok = source["picDate"].(string) |
| | | Isnil("picDate", ok) |
| | | //Isnil("picDate", ok) |
| | | tmpinfo.PicMaxUrl,ok = source["picMaxUrl"].(string) |
| | | Isnil("picMaxUrl", ok) |
| | | //Isnil("picMaxUrl", ok) |
| | | tmpinfo.TaskId,ok = source["taskId"].(string) |
| | | Isnil("taskId", ok) |
| | | //Isnil("taskId", ok) |
| | | tmpinfo.TaskName,ok = source["taskName"].(string) |
| | | Isnil("taskName", ok) |
| | | //Isnil("taskName", ok) |
| | | tmpinfo.SdkName,ok = source["sdkName"].(string) |
| | | Isnil("sdkName", ok) |
| | | //Isnil("sdkName", ok) |
| | | tmpinfo.Content,ok = source["content"].(string) |
| | | Isnil("content",ok) |
| | | //Isnil("content",ok) |
| | | tmpinfo.LikeDate,ok = source["likeDate"].(string) |
| | | Isnil("likeDate",ok) |
| | | //Isnil("likeDate",ok) |
| | | tmpinfo.DetectScore,ok = source["detectScore"].(string) |
| | | Isnil("detectScore", ok) |
| | | //Isnil("detectScore", ok) |
| | | tmpinfo.Sex,ok = source["sex"].(string) |
| | | Isnil("sex",ok) |
| | | //Isnil("sex",ok) |
| | | |
| | | age,ok := source["age"].(float64) |
| | | if ok { |
| | | tmpinfo.Age= int32(age) |
| | | } |
| | | Isnil("age", ok) |
| | | //Isnil("age", ok) |
| | | |
| | | tmpinfo.AgeDescription,ok = source["ageDescription"].(string) |
| | | Isnil("ageDescription",ok) |
| | | //Isnil("ageDescription",ok) |
| | | tmpinfo.Race,ok = source["race"].(string) |
| | | Isnil("race",ok) |
| | | //Isnil("race",ok) |
| | | tmpinfo.SmileLevel,ok = source["smileLevel"].(string) |
| | | Isnil("smileLevel",ok) |
| | | //Isnil("smileLevel",ok) |
| | | tmpinfo.BeautyLevel,ok = source["beautyLevel"].(string) |
| | | Isnil("beautyLevel",ok) |
| | | //Isnil("beautyLevel",ok) |
| | | if source["picSmUrl"] != nil { |
| | | //fmt.Println(source["picSmUrl"]) |
| | | for _,v := range source["picSmUrl"].([]interface{}) { |
| | | tmpinfo.PicSmUrl = append(tmpinfo.PicSmUrl, v.(string)) |
| | | } |
| | | fmt.Println(tmpinfo.PicSmUrl) |
| | | //fmt.Println(tmpinfo.PicSmUrl) |
| | | } |
| | | tmpinfo.VideoUrl,ok = source["videoUrl"].(string) |
| | | Isnil("videoUrl",ok) |
| | | //Isnil("videoUrl",ok) |
| | | tmpinfo.AnalyServerId,ok = source["analyServerId"].(string) |
| | | Isnil("analyServerId",ok) |
| | | //Isnil("analyServerId",ok) |
| | | tmpinfo.AnalyServerName,ok = source["analyServerName"].(string) |
| | | Isnil("analyServerName",ok) |
| | | //Isnil("analyServerName",ok) |
| | | tmpinfo.AnalyServerIp,ok = source["analyServerIp"].(string) |
| | | Isnil("analyServerIp",ok) |
| | | //Isnil("analyServerIp",ok) |
| | | tmpinfo.ClusterId,ok = source["clusterId"].(string) |
| | | Isnil("clusterId",ok) |
| | | //Isnil("clusterId",ok) |
| | | |
| | | isAlarm,ok := source["isAlarm"].(float64) |
| | | fmt.Println(ok) |
| | | //fmt.Println(ok) |
| | | if ok { |
| | | tmpinfo.IsAlarm= strconv.FormatFloat(isAlarm, 'E', -1, 64)//float64 |
| | | } |
| | | Isnil("isAlarm",ok) |
| | | //Isnil("isAlarm",ok) |
| | | |
| | | isAckAlarm,ok := source["isAckAlarm"].(float64) |
| | | fmt.Println(ok) |
| | | //fmt.Println(ok) |
| | | if ok { |
| | | tmpinfo.IsAckAlarm= strconv.FormatFloat(isAckAlarm, 'E', -1, 64)//float64 |
| | | } |
| | | Isnil("isAckAlarm",ok) |
| | | //Isnil("isAckAlarm",ok) |
| | | |
| | | isCollect,ok := source["isCollect"].(float64) |
| | | if ok { |
| | | tmpinfo.IsDelete= int32(isCollect) |
| | | } |
| | | Isnil("isCollect", ok) |
| | | //Isnil("isCollect", ok) |
| | | |
| | | isDelete,ok := source["isDelete"].(float64) |
| | | if ok { |
| | | tmpinfo.IsDelete= int32(isDelete) |
| | | } |
| | | Isnil("isDelete", ok) |
| | | //Isnil("isDelete", ok) |
| | | |
| | | if source["alarmRules"] != nil { |
| | | fmt.Println(source["alarmRules"]) |
| | | //fmt.Println(source["alarmRules"]) |
| | | for _,v := range source["alarmRules"].([]interface{}) { |
| | | m := v.(map[string]interface{}) |
| | | var ar protomsg.AlarmRules |
| | | //ar := protomsg.AlarmRules{} |
| | | ar.GroupId,ok = m["groupId"].(string) |
| | | Isnil("groupId",ok) |
| | | //Isnil("groupId",ok) |
| | | ar.AlarmLevel,ok = m["alarmLevel"].(string) |
| | | Isnil("alarmLevel",ok) |
| | | //Isnil("alarmLevel",ok) |
| | | ar.RuleText,ok = m["ruleText"].(string) |
| | | Isnil("ruleText",ok) |
| | | //Isnil("ruleText",ok) |
| | | ar.DefenceState,ok = m["defenceState"].(bool) |
| | | Isnil("DefenceState",ok) |
| | | //Isnil("DefenceState",ok) |
| | | tmpinfo.AlarmRules = append(tmpinfo.AlarmRules, &ar) |
| | | } |
| | | |
| | | } |
| | | |
| | | if source["baseInfo"] != nil { |
| | | fmt.Println(source["baseInfo"]) |
| | | //fmt.Println(source["baseInfo"]) |
| | | for _,v := range source["baseInfo"].([]interface{}) { |
| | | m := v.(map[string]interface{}) |
| | | fmt.Println("m:",m) |
| | | //fmt.Println("m:",m) |
| | | var bi protomsg.BaseInfo |
| | | //bi := protomsg.BaseInfo{} |
| | | bi.TableId,ok = m["tableId"].(string) |
| | | Isnil("tableId",ok) |
| | | //Isnil("tableId",ok) |
| | | bi.TableName,ok = m["tableName"].(string) |
| | | Isnil("tableName",ok) |
| | | //Isnil("tableName",ok) |
| | | compareScore,ok := m["compareScore"].(float64) |
| | | if ok { |
| | | bi.CompareScore= float32(compareScore) |
| | | } |
| | | Isnil("compareScore", ok) |
| | | //Isnil("compareScore", ok) |
| | | |
| | | bi.PersonId,ok = m["personId"].(string) |
| | | Isnil("personId",ok) |
| | | //Isnil("personId",ok) |
| | | bi.PersonName,ok = m["personName"].(string) |
| | | Isnil("personName",ok) |
| | | //Isnil("personName",ok) |
| | | bi.PersonPicUrl,ok = m["personPicUrl"].(string) |
| | | Isnil("personPicUrl",ok) |
| | | //Isnil("personPicUrl",ok) |
| | | bi.PhoneNum,ok = m["phoneNum"].(string) |
| | | Isnil("phoneNum",ok) |
| | | //Isnil("phoneNum",ok) |
| | | bi.Sex,ok = m["sex"].(string) |
| | | Isnil("sex",ok) |
| | | //Isnil("sex",ok) |
| | | bi.IdCard,ok = m["idCard"].(string) |
| | | Isnil("idCard",ok) |
| | | //Isnil("idCard",ok) |
| | | bi.MonitorLevel,ok = m["monitorLevel"].(string) |
| | | Isnil("monitorLevel",ok) |
| | | //Isnil("monitorLevel",ok) |
| | | bi.Content,ok = m["content"].(string) |
| | | Isnil("content",ok) |
| | | //Isnil("content",ok) |
| | | bwType,ok := m["bwType"].(float64) |
| | | if ok { |
| | | bi.BwType= int32(bwType) |
| | | } |
| | | Isnil("bwType", ok) |
| | | //Isnil("bwType", ok) |
| | | |
| | | tmpinfo.BaseInfo = append(tmpinfo.BaseInfo, &bi) |
| | | } |
| | |
| | | //根据 tableid 获取 tablename |
| | | //name, _:= Dbtablename(tmpinfo.TableId) |
| | | //tmpinfo.TableName= name |
| | | fmt.Println(tmpinfos) |
| | | //fmt.Println(tmpinfos) |
| | | tmpinfos = append(tmpinfos, tmpinfo) |
| | | } |
| | | |
| | | return tmpinfos |
| | | } |
| | | |
| | | |
| | | //解析底库人员结构 |
| | | func Dbpersonbyid(sources []map[string]interface{}) (tmpinfos []protomsg.Dbperson) { |
| | |
| | | } |
| | | |
| | | tmpinfo.PersonName,ok = source["personName"].(string) |
| | | Isnil("personName", ok) |
| | | //Isnil("personName", ok) |
| | | tmpinfo.PersonPicUrl,ok = source["personPicUrl"].(string) |
| | | Isnil("personPicUrl", ok) |
| | | //Isnil("personPicUrl", ok) |
| | | tmpinfo.PhoneNum,ok = source["phoneNum"].(string) |
| | | Isnil("phoneNum", ok) |
| | | //Isnil("phoneNum", ok) |
| | | tmpinfo.Sex,ok = source["sex"].(string) |
| | | Isnil("sex", ok) |
| | | //Isnil("sex", ok) |
| | | tmpinfo.IdCard,ok = source["idCard"].(string) |
| | | Isnil("idCard", ok) |
| | | //Isnil("idCard", ok) |
| | | tmpinfo.MonitorLevel,ok = source["monitorLevel"].(string) |
| | | Isnil("monitorLevel",ok) |
| | | //Isnil("monitorLevel",ok) |
| | | tmpinfo.UpdateTime,ok = source["updateTime"].(string) |
| | | Isnil("updateTime",ok) |
| | | //Isnil("updateTime",ok) |
| | | tmpinfo.Age,ok = source["age"].(string) |
| | | Isnil("age", ok) |
| | | //Isnil("age", ok) |
| | | |
| | | isDelete,ok := source["isDelete"].(float64) |
| | | if ok { |
| | | tmpinfo.IsDelete= int32(isDelete) |
| | | } |
| | | Isnil("isDelete", ok) |
| | | //Isnil("isDelete", ok) |
| | | |
| | | enable,ok := source["enable"].(float64) |
| | | if ok { |
| | | tmpinfo.Enable= int32(enable) |
| | | } |
| | | Isnil("endTime", ok) |
| | | //Isnil("endTime", ok) |
| | | |
| | | tmpinfo.Reserved,ok = source["reserved"].(string) |
| | | Isnil("reserved",ok) |
| | | //Isnil("reserved",ok) |
| | | tmpinfo.PicDesc,ok = source["picDesc"].(string) |
| | | Isnil("picDesc",ok) |
| | | //Isnil("picDesc",ok) |
| | | tmpinfo.CreateTime,ok = source["createTime"].(string) |
| | | Isnil("createTime",ok) |
| | | //Isnil("createTime",ok) |
| | | tmpinfo.CreateBy,ok = source["createBy"].(string) |
| | | Isnil("createBy",ok) |
| | | //Isnil("createBy",ok) |
| | | |
| | | //根据 tableid 获取 tablename |
| | | //name, _:= Dbtablename(tmpinfo.TableId) |
| | |
| | | continue |
| | | } |
| | | tmpinfo.TableName,ok = source["tableName"].(string) |
| | | Isnil("tableName", ok) |
| | | //Isnil("tableName", ok) |
| | | tmpinfo.TableType,ok = source["tableType"].(string) |
| | | Isnil("tableType", ok) |
| | | //Isnil("tableType", ok) |
| | | tmpinfo.CreateBy,ok = source["createBy"].(string) |
| | | Isnil("createBy", ok) |
| | | //Isnil("createBy", ok) |
| | | tmpinfo.TableDesc,ok = source["tableDesc"].(string) |
| | | Isnil("tableDesc", ok) |
| | | //Isnil("tableDesc", ok) |
| | | tmpinfo.BwType,ok = source["bwType"].(string) |
| | | Isnil("bwType", ok) |
| | | //Isnil("bwType", ok) |
| | | tmpinfo.StartTime,ok = source["startTime"].(string) |
| | | Isnil("startTime", ok) |
| | | //Isnil("startTime", ok) |
| | | tmpinfo.EndTime,ok = source["endTime"].(string) |
| | | Isnil("endTime", ok) |
| | | //Isnil("endTime", ok) |
| | | |
| | | isDelete,ok := source["isDelete"].(float64) |
| | | if ok { |
| | | tmpinfo.IsDelete= int32(isDelete) |
| | | } |
| | | Isnil("isDelete", ok) |
| | | //Isnil("isDelete", ok) |
| | | |
| | | enable,ok := source["enable"].(float64) |
| | | if ok { |
| | | tmpinfo.Enable= int32(enable) |
| | | } |
| | | Isnil("endTime", ok) |
| | | //Isnil("endTime", ok) |
| | | |
| | | tmpinfo.CreateTime,ok = source["createTime"].(string) |
| | | Isnil("createTime", ok) |
| | | //Isnil("createTime", ok) |
| | | tmpinfo.UpdateTime,ok = source["updateTime"].(string) |
| | | Isnil("updateTime", ok) |
| | | //Isnil("updateTime", ok) |
| | | tmpinfo.IsForever,ok = source["isForever"].(string) |
| | | Isnil("isForever", ok) |
| | | //Isnil("isForever", ok) |
| | | tmpinfo.IsSync,ok = source["isSync"].(string) |
| | | Isnil("isSync", ok) |
| | | //Isnil("isSync", ok) |
| | | tmpinfo.AnalyServerId,ok = source["analyServerId"].(string) |
| | | Isnil("analyServerId", ok) |
| | | //Isnil("analyServerId", ok) |
| | | |
| | | tmpinfos = append(tmpinfos, tmpinfo) |
| | | } |
| | |
| | | } |
| | | |
| | | // 赋值时检测是否能够赋值 |
| | | func Isnil(key string, ok bool){ |
| | | if !ok { |
| | | fmt.Println(key, "is nil can not asign") |
| | | } |
| | | } |
| | | //func //Isnil(key string, ok bool){ |
| | | // if !ok { |
| | | // fmt.Println(key, "is nil can not asign") |
| | | // } |
| | | //} |