sunty
2019-11-19 df4e05af6aee00109360e40b9c2132da8d13f5f8
fix esutil
2个文件已修改
331 ■■■■ 已修改文件
EsApi.go 57 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
EsClient.go 274 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
EsApi.go
@@ -104,8 +104,8 @@
}
// 根据抓拍人员id查询抓拍人员信息
func Videopersonsinfosbyid (id []string, indexName string, serverIp string, serverPort string) ([]protomsg.Videopersons, error) {
    var videopersonsInfo []protomsg.Videopersons
func AIOceaninfosbyid (id []string, indexName string, serverIp string, serverPort string) ([]protomsg.AIOcean, error) {
    var aIOceanInfo []protomsg.AIOcean
    videopersonsPersonId := strings.Replace(strings.Trim(fmt.Sprint(id), "[]"), " ", "\",\"", -1)
    var dbinfoRequest = `
            {
@@ -125,17 +125,17 @@
        `
    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(dbinfoRequest))
    if err != nil {
        return videopersonsInfo,  err
        return aIOceanInfo,  err
    }
    sources, err := Sourcelist(buf)
    if err != nil {
        return videopersonsInfo , err
        return aIOceanInfo , err
    }
    videoperson := Videopersonsbyid(sources)
    println(videoperson)
    return videoperson,nil
    aIOcean := AIOceanAnalysis(sources)
    println(aIOcean)
    return aIOcean,nil
}
// 根据底库人员id查询底库人员信息
@@ -505,8 +505,8 @@
}
//初始化实时抓拍
func InitRealTimeCapture(serverIp string, serverPort string, indexName string, isAlarm bool    ,quantity int) ([]protomsg.Videopersons, error){
    var videopersonsInfo []protomsg.Videopersons
func InitRealTimeCapture(serverIp string, serverPort string, indexName string, isAlarm bool    ,quantity int) ([]protomsg.AIOcean, error){
    var aIOceanInfo []protomsg.AIOcean
    url := "http://" + serverIp + ":" + serverPort +
        "/" + indexName + "/_search"
    queryStr := ""
@@ -520,7 +520,7 @@
            "filter":[
                {
                    "term":{
                        "isAlarm":1
                        "isAlarm":true
                    }
                }
            ]
@@ -531,26 +531,26 @@
    "size":`+strconv.Itoa(quantity)+`,
    `+queryStr+`
    "sort":[{"picDate":{"order":"desc"}}],
    "_source": ["baseInfo", "alarmRules", "sex", "analyServerName", "sdkName", "ageDescription", "content", "id", "cameraAddr", "picMaxUrl", "picDate", "race", "videoUrl", "picSmUrl", "taskName", "personIsHub", "isAlarm", "analyServerIp", "cameraId"]
    "_source": {"includes":[],"excludes":["*.feature"]}
    }`
    buf, err := EsReq("POST", url, []byte(DSLJson))
    if err != nil {
        return videopersonsInfo, err
        return aIOceanInfo, err
    }
    sources, err := Sourcelist(buf)
    if err != nil {
        return videopersonsInfo, err
        return aIOceanInfo, err
    }
    videoperson := Videopersonsbyid(sources)
    aIOcean := AIOceanAnalysis(sources)
    //fmt.Println(len(videoperson))
    return videoperson, nil
    return aIOcean, nil
}
//实时抓拍
func RealTimeCapture(serverIp string, serverPort string, indexName string, isAlarm bool    ) ([]protomsg.Videopersons, error){
    var videopersonsInfo []protomsg.Videopersons
func RealTimeCapture(serverIp string, serverPort string, indexName string, isAlarm bool    ) ([]protomsg.AIOcean, error){
    var aIOceanInfo []protomsg.AIOcean
    url := "http://" + serverIp + ":" + serverPort +
        "/" + indexName + "/_search"
    queryStr := ""
@@ -587,24 +587,24 @@
    buf, err := EsReq("POST", url, []byte(DSLJson))
    if err != nil {
        return videopersonsInfo, err
        return aIOceanInfo, err
    }
    sources, err := Sourcelist(buf)
    if err != nil {
        return videopersonsInfo, err
        return aIOceanInfo, err
    }
    videoperson := Videopersonsbyid(sources)
    fmt.Println(len(videoperson))
    return videoperson, nil
    aIOcean := AIOceanAnalysis(sources)
    fmt.Println(len(aIOcean))
    return aIOcean, nil
}
//综合统计
func StatisticsComprehensive(serverIp string, serverPort string, indexName string, isAlarm bool) (total int, err error){
    isAlarmStr := ""
    if isAlarm == true {
        isAlarmStr = `,{"term":{"isAlarm":1}}`
        isAlarmStr = `,{"term":{"isAlarm":true}}`
    }
    url := "http://" + serverIp + ":" + serverPort +
        "/" + indexName + "/_search"
@@ -662,9 +662,9 @@
        }
    },
    "aggs":{
        "sdkName_status":{
        "sdkId_status":{
            "terms":{
                "field":"taskName.raw"
                "field":"taskId"
            }
        }
    }
@@ -683,7 +683,7 @@
    if !ok {
        return nil, errors.New("first hits change error!")
    }
    sdkName_status, ok := middle["sdkName_status"].(map[string]interface{})
    sdkName_status, ok := middle["sdkId_status"].(map[string]interface{})
    if !ok {
        return nil, errors.New("first hits change error!")
    }
@@ -695,9 +695,9 @@
            fmt.Println("change to source error!")
            continue
        }
        sdkName := tmpbuf["key"].(string)
        sdkId := tmpbuf["key"].(string)
        count := int(tmpbuf["doc_count"].(float64))
        source["name"] = sdkName
        source["id"] = sdkId
        source["value"] = count
        sources = append(sources, source)
    }
@@ -705,6 +705,7 @@
    return sources,nil
}
//聚合任务列表,taskId+taskName
func AggregateTaskList(serverIp string, serverPort string, indexName string, analyServerId string) (sources []map[string]interface{},err error){
    url := "http://" + serverIp + ":" + serverPort +
EsClient.go
@@ -1,6 +1,7 @@
package esutil
import (
    "basic.com/pubsub/protomsg.git"
    "bytes"
    "encoding/json"
    "errors"
@@ -8,10 +9,8 @@
    "io"
    "io/ioutil"
    "net/http"
    "strconv"
    "time"
    "strings"
    "basic.com/pubsub/protomsg.git"
    "time"
)
func GetEsDataReq(url string, parama string, isSource bool) map[string]interface{} {
@@ -100,171 +99,198 @@
}
//解析抓拍库人员结构
func Videopersonsbyid(sources []map[string]interface{}) (tmpinfos []protomsg.Videopersons) {
func AIOceanAnalysis(sources []map[string]interface{}) (tmpinfos []protomsg.AIOcean) {
    var ok bool
    for _, source := range  sources{
        var tmpinfo protomsg.Videopersons
        var tmpinfo protomsg.AIOcean
        tmpinfo.Id, ok =   source["id"].(string)
        if !ok {
            continue
        }
        tmpinfo.CameraId, ok    =   source["cameraId"].(string)
        if !ok {
            continue
        }
        tmpinfo.CameraAddr, ok     =   source["cameraAddr"].(string)
        if !ok {
            continue
        }
        tmpinfo.PicDate,ok  =   source["picDate"].(string)
        //Isnil("picDate", ok)
        tmpinfo.PicMaxUrl,ok =  source["picMaxUrl"].(string)
        //Isnil("picMaxUrl", ok)
        tmpinfo.TaskId,ok     =  source["taskId"].(string)
        //Isnil("taskId", ok)
        tmpinfo.TaskName,ok          =  source["taskName"].(string)
        //Isnil("taskName", ok)
        tmpinfo.SdkName,ok       =  source["sdkName"].(string)
        //Isnil("sdkName", ok)
        tmpinfo.Content,ok =  source["content"].(string)
        //Isnil("content",ok)
        tmpinfo.LikeDate,ok = source["likeDate"].(string)
        //Isnil("likeDate",ok)
        tmpinfo.DetectScore,ok =  source["detectScore"].(string)
        //Isnil("detectScore", ok)
        tmpinfo.Sex,ok = source["sex"].(string)
        //Isnil("sex",ok)
        age,ok  :=   source["age"].(float64)
        if ok {
            tmpinfo.Age= int32(age)
        }
        //Isnil("age", ok)
        tmpinfo.AgeDescription,ok = source["ageDescription"].(string)
        //Isnil("ageDescription",ok)
        tmpinfo.Race,ok = source["race"].(string)
        //Isnil("race",ok)
        tmpinfo.SmileLevel,ok = source["smileLevel"].(string)
        //Isnil("smileLevel",ok)
        tmpinfo.BeautyLevel,ok = source["beautyLevel"].(string)
        //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)
        }
        tmpinfo.VideoUrl,ok = source["videoUrl"].(string)
        //Isnil("videoUrl",ok)
        tmpinfo.AnalyServerId,ok = source["analyServerId"].(string)
        //Isnil("analyServerId",ok)
        tmpinfo.AnalyServerName,ok = source["analyServerName"].(string)
        //Isnil("analyServerName",ok)
        tmpinfo.AnalyServerIp,ok = source["analyServerIp"].(string)
        //Isnil("analyServerIp",ok)
        tmpinfo.ClusterId,ok = source["clusterId"].(string)
        //Isnil("clusterId",ok)
        isAlarm,ok := source["isAlarm"].(float64)
        //fmt.Println(ok)
        if ok {
            tmpinfo.IsAlarm= strconv.FormatFloat(isAlarm, 'E', -1, 64)//float64
        tmpinfo.TaskId, ok = source["taskId"].(string)
        tmpinfo.TaskName, ok = source["taskName"].(string)
        tmpinfo.SdkName, ok = source["sdkName"].(string)
        tmpinfo.PicMaxUrl, ok = source["picMaxUrl"].(string)
        tmpinfo.VideoUrl, ok = source["videoUrl"].(string)
        tmpinfo.PicDate, ok = source["picDate"].(string)
        if source["targetInfo"] != nil {
            for _, v := range source["targetInfo"].([]interface{}) {
                m := v.(map[string]interface{})
                var ti protomsg.TargetInfo
                ti.TargetId, ok = m["targetId"].(string)
                ti.TargetScore, ok = m["targetScore"].(float64)
                ti.Feature, ok = m["feature"].(string)
                ti.PicSmUrl, ok = m["picSmUrl"].(string)
                targetLocation := m["targetLocation"].(map[string]interface{})
                topLeft := targetLocation["topLeft"].(map[string]interface{})
                tx := topLeft["x"].(float64)
                ty := topLeft["y"].(float64)
                bottomRight := targetLocation["bottomRight"].(map[string]interface{})
                bx := bottomRight["x"].(float64)
                by := bottomRight["y"].(float64)
                ti.TargetLocation = &protomsg.TargetLocation{
                    TopLeft: &protomsg.Location{
                        X: tx,
                        Y: ty,
                    },
                    BottomRight: &protomsg.Location{
                        X: bx,
                        Y: by,
                    },
        }
        //Isnil("isAlarm",ok)
        isAckAlarm,ok := source["isAckAlarm"].(float64)
        //fmt.Println(ok)
        if ok {
            tmpinfo.IsAckAlarm= strconv.FormatFloat(isAckAlarm, 'E', -1, 64)//float64
                tmpinfo.TargetInfo = append(tmpinfo.TargetInfo, &ti)
        }
        //Isnil("isAckAlarm",ok)
        isCollect,ok  :=   source["isCollect"].(float64)
        if ok {
            tmpinfo.IsDelete= int32(isCollect)
        }
        //Isnil("isCollect", ok)
        isDelete,ok  :=   source["isDelete"].(float64)
        if ok {
            tmpinfo.IsDelete= int32(isDelete)
        tmpinfo.OtherLabels, ok = source["otherLabels"].(string)
        tmpinfo.ShowLabels, ok = source["showLabels"].(string)
        tmpinfo.LikeDate, ok = source["likeDate"].(string)
        if source["baseInfo"] != nil {
            for _, v := range source["baseInfo"].([]interface{}) {
                m := v.(map[string]interface{})
                var bi protomsg.BaseInfo
                bi.TableId, ok = m["tableId"].(string)
                bi.TableName, ok = m["tableName"].(string)
                bi.CompareScore, ok = m["compareScore"].(float64)
                bi.BwType, ok = m["bwType"].(string)
                bi.TargetId, ok = m["targetId"].(string)
                bi.TableName, ok = m["tableName"].(string)
                bi.TargetPicUrl, ok = m["targetPicUrl"].(string)
                bi.MonitorLevel, ok = m["monitorLevel"].(string)
                bi.Labels, ok = m["labels"].(string)
                bi.Content, ok = m["content"].(string)
                tmpinfo.BaseInfo = append(tmpinfo.BaseInfo, &bi)
        }
        //Isnil("isDelete", ok)
        }
        tmpinfo.IsAlarm, ok = source["isAlarm"].(bool)
        tmpinfo.IsAckAlarm, ok = source["isAckAlarm"].(bool)
        if source["alarmRules"] != nil {
            //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)
                ar.AlarmLevel,ok = m["alarmLevel"].(string)
                //Isnil("alarmLevel",ok)
                ar.RuleText,ok = m["ruleText"].(string)
                //Isnil("ruleText",ok)
                ar.DefenceState,ok = m["defenceState"].(bool)
                //Isnil("DefenceState",ok)
                ar.IsLink,ok = m["isLink"].(bool)
                ar.LinkInfo,ok = m["linkInfo"].(string)
                tmpinfo.AlarmRules = append(tmpinfo.AlarmRules, &ar)
            }
        }
        if source["baseInfo"] != nil {
            //fmt.Println(source["baseInfo"])
            for _,v := range source["baseInfo"].([]interface{}) {
                m := v.(map[string]interface{})
                //fmt.Println("m:",m)
                var bi protomsg.BaseInfo
                //bi := protomsg.BaseInfo{}
                bi.TableId,ok = m["tableId"].(string)
                //Isnil("tableId",ok)
                bi.TableName,ok = m["tableName"].(string)
                //Isnil("tableName",ok)
                compareScore,ok := m["compareScore"].(float64)
                if ok {
                    bi.CompareScore= float32(compareScore)
        tmpinfo.IsCollect, ok = source["isCollect"].(bool)
        tmpinfo.IsDelete, ok = source["isDelete"].(bool)
        tmpinfo.Content, ok = source["content"].(string)
        tmpinfo.LinkTag, ok = source["linkTag"].(string)
        if source["linkTagInfo"] != nil {
            for _, v := range source["linkTagInfo"].([]interface{}) {
                var lti protomsg.EsDataBase
                lm := v.(map[string]interface{})
                lti.Id, ok = lm["id"].(string)
                if !ok {
                    continue
                }
                //Isnil("compareScore", ok)
                lti.CameraId, ok = lm["cameraId"].(string)
                if !ok {
                    continue
                }
                lti.CameraAddr, ok = lm["cameraAddr"].(string)
                if !ok {
                    continue
                }
                lti.AnalyServerId, ok = lm["analyServerId"].(string)
                lti.AnalyServerName, ok = lm["analyServerName"].(string)
                lti.AnalyServerIp, ok = lm["analyServerIp"].(string)
                lti.ClusterId, ok = lm["clusterId"].(string)
                lti.TaskId, ok = lm["taskId"].(string)
                lti.TaskName, ok = lm["taskName"].(string)
                lti.SdkName, ok = lm["sdkName"].(string)
                lti.PicMaxUrl, ok = lm["picMaxUrl"].(string)
                lti.VideoUrl, ok = lm["videoUrl"].(string)
                lti.PicDate, ok = lm["picDate"].(string)
                if lm["targetInfo"] != nil {
                    for _, v := range lm["targetInfo"].([]interface{}) {
                        m := v.(map[string]interface{})
                        var ti protomsg.TargetInfo
                        ti.TargetId, ok = m["targetId"].(string)
                        ti.TargetScore, ok = m["targetScore"].(float64)
                        ti.Feature, ok = m["feature"].(string)
                        ti.PicSmUrl, ok = m["picSmUrl"].(string)
                        targetLocation := m["targetLocation"].(map[string]interface{})
                        topLeft := targetLocation["topLeft"].(map[string]interface{})
                        tx := topLeft["x"].(float64)
                        ty := topLeft["y"].(float64)
                        bottomRight := targetLocation["bottomRight"].(map[string]interface{})
                        bx := bottomRight["x"].(float64)
                        by := bottomRight["y"].(float64)
                        ti.TargetLocation = &protomsg.TargetLocation{
                            TopLeft: &protomsg.Location{
                                X: tx,
                                Y: ty,
                            },
                            BottomRight: &protomsg.Location{
                                X: bx,
                                Y: by,
                            },
                        }
                        lti.TargetInfo = append(lti.TargetInfo, &ti)
                    }
                bi.PersonId,ok = m["personId"].(string)
                //Isnil("personId",ok)
                bi.PersonName,ok = m["personName"].(string)
                //Isnil("personName",ok)
                bi.PersonPicUrl,ok = m["personPicUrl"].(string)
                //Isnil("personPicUrl",ok)
                bi.PhoneNum,ok = m["phoneNum"].(string)
                //Isnil("phoneNum",ok)
                bi.Sex,ok = m["sex"].(string)
                //Isnil("sex",ok)
                bi.IdCard,ok = m["idCard"].(string)
                //Isnil("idCard",ok)
                bi.MonitorLevel,ok = m["monitorLevel"].(string)
                //Isnil("monitorLevel",ok)
                bi.Content,ok = m["content"].(string)
                //Isnil("content",ok)
                }
                lti.OtherLabels, ok = lm["otherLabels"].(string)
                lti.ShowLabels, ok = lm["showLabels"].(string)
                lti.LikeDate, ok = lm["likeDate"].(string)
                if lm["baseInfo"] != nil {
                    for _, v := range lm["baseInfo"].([]interface{}) {
                        m := v.(map[string]interface{})
                        var bi protomsg.BaseInfo
                        bi.TableId, ok = m["tableId"].(string)
                        bi.TableName, ok = m["tableName"].(string)
                        bi.CompareScore, ok = m["compareScore"].(float64)
                bi.BwType,ok = m["bwType"].(string)
                //Isnil("bwType", ok)
                        bi.TargetId, ok = m["targetId"].(string)
                        bi.TableName, ok = m["tableName"].(string)
                        bi.TargetPicUrl, ok = m["targetPicUrl"].(string)
                        bi.MonitorLevel, ok = m["monitorLevel"].(string)
                        bi.Labels, ok = m["labels"].(string)
                        bi.Content, ok = m["content"].(string)
                tmpinfo.BaseInfo = append(tmpinfo.BaseInfo, &bi)
            }
        }
        //根据 tableid 获取 tablename
        //name, _:= Dbtablename(tmpinfo.TableId)
        //tmpinfo.TableName= name
        //fmt.Println(tmpinfos)
        tmpinfos = append(tmpinfos, tmpinfo)
                lti.IsAlarm, ok = lm["isAlarm"].(bool)
                lti.IsAckAlarm, ok = lm["isAckAlarm"].(bool)
                if lm["alarmRules"] != nil {
                    for _, v := range lm["alarmRules"].([]interface{}) {
                        m := v.(map[string]interface{})
                        var ar protomsg.AlarmRules
                        ar.GroupId, ok = m["groupId"].(string)
                        ar.AlarmLevel, ok = m["alarmLevel"].(string)
                        ar.RuleText, ok = m["ruleText"].(string)
                        ar.DefenceState, ok = m["defenceState"].(bool)
                        ar.LinkInfo, ok = m["linkInfo"].(string)
                        lti.AlarmRules = append(lti.AlarmRules, &ar)
    }
                }
                lti.IsCollect, ok = lm["isCollect"].(bool)
                lti.IsDelete, ok = lm["isDelete"].(bool)
                lti.Content, ok = lm["content"].(string)
                tmpinfo.LinkTagInfo = append(tmpinfo.LinkTagInfo, &lti)
            }
        }
        tmpinfos = append(tmpinfos, tmpinfo)
    }
    return tmpinfos
}