| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "basic.com/dbapi.git" |
| | | "fmt" |
| | | "strconv" |
| | | "strings" |
| | |
| | | data := findEsData(searchBody) |
| | | util.ResponseFormat(c, code.Success, data) |
| | | } |
| | | //获取监控等级 |
| | | func getAlarmLevel(alarmlevel []int) ([]string) { |
| | | d := dbapi.DicApi{} |
| | | res,data := d.FindByType("ALARMLEVEL") |
| | | if data == nil { |
| | | fmt.Println("dsadasd") |
| | | } |
| | | fmt.Println(res) |
| | | // fmt.Println(data) |
| | | alarmLevel := make(map[int]string) |
| | | |
| | | tmp := data.(map[string]interface{}) |
| | | for _,value := range tmp["ALARMLEVEL"].([]interface{}) { |
| | | // fmt.Println(value.(map[string]interface{})["value"]," ",value.(map[string]interface{})["name"]) |
| | | val := value.(map[string]interface{})["value"].(string) |
| | | name := value.(map[string]interface{})["name"].(string) |
| | | vl,err := strconv.Atoi(val) |
| | | if err != nil { |
| | | fmt.Println("dsadas") |
| | | } |
| | | alarmLevel[vl] = name |
| | | } |
| | | alarmLevelRes := make([]string,len(alarmlevel)) |
| | | for i,v := range alarmlevel { |
| | | alarmLevelRes[i] = alarmLevel[v] |
| | | } |
| | | return alarmLevelRes |
| | | } |
| | | |
| | | func findEsData(searchBody map[string]interface{}) map[string]interface{} { |
| | | webPage := int(searchBody["page"].(float64)) |
| | |
| | | queryBody := searchBody["inputValue"].(string) |
| | | //检索框 |
| | | if queryBody != "" { |
| | | queryStr = "\"must\":[{\"multi_match\":{\"query\":\"" + queryBody + "\",\"fields\":[\"BaseName^1.5\",\"Gender^2.0\",\"Race^2.0\",\"content^1.0\",\"idcard^1.8\",\"picAddress^1.0\"]," + |
| | | queryStr = "\"must\":[{\"multi_match\":{\"query\":\"" + queryBody + "\",\"fields\":[\"alarmRules.alarmLevel^1.5\",\"ageDescription^1.5\",\"taskName^1.5\",\"baseInfo.tableName^1.5\",\"sex^2.0\",\"race^2.0\",\"content^1.0\",\"baseInfo.idCard^1.8\",\"cameraAddr^1.0\"]," + |
| | | "\"type\":\"cross_fields\",\"operator\":\"OR\",\"slop\":0,\"prefix_length\":0,\"max_expansions\":50,\"zero_terms_query\":\"NONE\",\"auto_generate_synonyms_phrase_query\":true,\"fuzzy_transpositions\":true,\"boost\":1}}]," |
| | | } |
| | | gteDate := searchBody["searchTime"].([]interface{})[0].(string) |
| | |
| | | taskIdStr = "{\"terms\":{\"taskId\":[\"" + esTaskId + "\"]}}," |
| | | } |
| | | //判断摄像机ID |
| | | videoReqNumStr := "" |
| | | videoReqNum := searchBody["treeNodes"].([]interface{}) |
| | | if videoReqNum != nil && len(videoReqNum) > 0 { |
| | | esVideoReqNum := strings.Replace(strings.Trim(fmt.Sprint(videoReqNum), "[]"), " ", "\",\"", -1) |
| | | videoReqNumStr = "{\"terms\":{\"videoReqNum\":[\"" + esVideoReqNum + "\"]}}," |
| | | cameraIdStr := "" |
| | | cameraId := searchBody["treeNodes"].([]interface{}) |
| | | if cameraId != nil && len(cameraId) > 0 { |
| | | esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1) |
| | | cameraIdStr = "{\"terms\":{\"cameraId\":[\"" + esCameraId + "\"]}}," |
| | | } |
| | | |
| | | //判断库表ID |
| | |
| | | if tableId != nil && len(tableId) > 0 { |
| | | esTableId = strings.Replace(strings.Trim(fmt.Sprint(tableId), "[]"), " ", "\",\"", -1) |
| | | index = config.EsInfo.EsIndex.VideoPersons.IndexName |
| | | esTableIdStr = "{\"terms\":{\"tableId\":[\"" + esTableId + "\"]}}," |
| | | esTableIdStr = "{\"terms\":{\"baseInfo.tableId\":[\"" + esTableId + "\"]}}," |
| | | } |
| | | collectionStr := "" |
| | | collection := searchBody["collection"].(string) |
| | | if collection != "" { |
| | | collectionStr = "{\"term\":{\"collection\":\"" + collection + "\"}}," |
| | | //判断收藏状态 |
| | | isCollectStr := "" |
| | | isCollect := searchBody["collection"].(string) |
| | | if isCollect != "" { |
| | | isCollectStr = "{\"term\":{\"isCollect\":\"" + isCollect + "\"}}," |
| | | } |
| | | |
| | | //判断布防等级id |
| | | alarmLevelId :=searchBody["alarmlevel"].([]int) |
| | | alarmLevelStr := "" |
| | | defenceStateStr := "" |
| | | if len(alarmLevelId) > 0 { |
| | | flag := false |
| | | for i,v := range alarmLevelId { |
| | | if v == -1 { |
| | | alarmLevelId = append(alarmLevelId[:i], alarmLevelId[i+1:]...) |
| | | defenceStateStr = "{\"term\":{\"alarmRules.defenceState\":false}}," |
| | | flag = true |
| | | break |
| | | } |
| | | } |
| | | if len(alarmLevelId) > 0{ |
| | | if flag == false { |
| | | defenceStateStr = "{\"term\":{\"alarmRules.defenceState\":true}}," |
| | | } |
| | | id := strings.Replace(strings.Trim(fmt.Sprint(getAlarmLevel(alarmLevelId)), "[]"), " ", "\",\"", -1) |
| | | alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel\":[\"" + id + "\"]}}," |
| | | } |
| | | } |
| | | |
| | | //使用es底层机制处理分页 |
| | | //请求头 |
| | | url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + |
| | | "/" + index + "/_search?search_type=dfs_query_then_fetch" |
| | | var setApi dbapi.SysSetApi |
| | | _, sysconf := setApi.GetServerInfo() |
| | | analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + sysconf.ServerId + "\"}}," |
| | | |
| | | //请求体 |
| | | prama := "{\"from\":\"" + from + "\"," + |
| | | "\"size\":\"" + size + "\"," + |
| | | "\"query\":{\"bool\":{" + queryStr + |
| | | "\"filter\":[" + |
| | | videoReqNumStr + |
| | | cameraIdStr + |
| | | alarmLevelStr + |
| | | defenceStateStr + |
| | | taskIdStr + |
| | | collectionStr + |
| | | isCollectStr + |
| | | esTableIdStr + |
| | | analyServerFilterStr + |
| | | "{\"range\":{\"picDate\":{\"from\":\"" + gteDate + "\",\"to\":\"" + lteDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}]}}," + |
| | | "\"sort\":[{\"_score\":{\"order\":\"desc\"}},{\"picDate\":{\"order\":\"desc\"}}]," + |
| | | "\"_source\":[\"baseInfo\",\"gender\",\"indeviceName\",\"sdkType\",\"ageDescription\",\"content\",\"ID\",\"picAddress\",\"picMaxUrl\",\"picDate\",\"race\",\"videoNum\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"IDCard\",\"videoIp\",\"videoReqNum\"]" + |
| | | "\"_source\":[\"baseInfo\",\"alarmRules\",\"sex\",\"analyServerName\",\"sdkName\",\"ageDescription\",\"content\",\"id\",\"cameraAddr\",\"picMaxUrl\",\"picDate\",\"race\",\"videoUrl\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"isAlarm\",\"analyServerIp\",\"cameraId\"]" + |
| | | "}" |
| | | fmt.Println(prama) |
| | | //数据解析 |
| | |
| | | return tokenRes |
| | | } |
| | | |
| | | //sdkTYype字典"\"_source\":[\"BaseName\",\"Gender\",\"Race\",\"content\",\"idcard\",\"picAddress\",\"picDate\",\"sdkType\",\"Age\",\"personId\",\"personIsHub\",\"personPicUrl\",\"picLocalUrl\",\"picSmUrl\",\"videoIp\",\"videoNum\",\"videoReqNum\",\"ageDescription\",\"likePer\"]" + |
| | | //sdkTYype字典"\"_source\":[\"BaseName\",\"Gender\",\"Race\",\"content\",\"idcard\",\"picAddress\",\"picDate\",\"sdkType\",\"Age\",\"personId\",\"personIsHub\",\"personPicUrl\",\"picLocalUrl\",\"picSmUrl\",\"videoIp\",\"videoNum\",\"cameraId\",\"ageDescription\",\"likePer\"]" + |
| | | //func sdkTypeToValue(i int) string { |
| | | // value := []string{"人脸", "车辆", "人体", "入侵", "拥挤", "靠右行", "人员异常", "个体静止"} |
| | | // return value[i-1] |