qixiaoning
2025-07-08 fe724b50b3f1b3dfe2219eb9af4bcca96c89a158
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package controllers
 
import (
    "basic.com/valib/bhomeclient.git"
    "basic.com/valib/bhomedbapi.git"
    "basic.com/valib/logger.git"
    "fmt"
    "strconv"
    "strings"
    "vamicro/config"
    "vamicro/realtime-service/esutil"
)
 
type RealTimeController struct{}
 
type RealTimeArg struct {
    TreeNodes []string `json:"treeNodes"`
}
 
// @Security ApiKeyAuth
// @Summary 实时抓拍
// @Description 实时抓拍数据
// @Accept  json
// @Produce json
// @Tags realTime
// @Param obj body controllers.RealTimeArg true "底库数据"
// @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/realTime/capture [POST]
//实时抓拍
func (rc *RealTimeController) PostCapture(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var sApi bhomedbapi.SysSetApi
    flag, localConf := sApi.GetServerInfo()
    if !flag || localConf.AlarmIp == "" ||localConf.AlarmPort ==0 {
        return &bhomeclient.Reply{Success:false, Msg: "localConf err"}
    }
 
    var searchBody RealTimeArg
    c.BindJSON(&searchBody)
    index := config.EsInfo.EsIndex.AiOcean.IndexName
    cameraIdStr := ""
    linkTagInfoCameraIdStr := ""
    cameraId := searchBody.TreeNodes
    if cameraId != nil && len(cameraId) > 0 {
        esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1)
        cameraIdStr = "{\"terms\":{\"cameraId\":[\"" + esCameraId + "\"]}},"
        linkTagInfoCameraIdStr = "{\"terms\":{\"linkTagInfo.cameraId\":[\"" + esCameraId + "\"]}},"
    }
    serverId := config.Server.AnalyServerId
    //请求头
    if serverId == "" {
        logger.Debug("serverId is wrong!!!")
        return &bhomeclient.Reply{Success:false, Msg:"es config err"}
    }
    url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) +
        "/" + index + "/_search"
 
    analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + serverId + "\"}},"
    linkTagInfoAnalyServerFilterStr := "{\"term\":{\"linkTagInfo.analyServerId\":\"" + serverId + "\"}},"
    prama := "{\"query\":{\"bool\":{\"should\":[" +
        "{\"bool\":{\"filter\":[" +
        "{\"term\":{\"isAlarm\":true}}," +
        cameraIdStr +
        analyServerFilterStr +
        "{\"range\":{\"picDate\":{\"gte\":\"now+8h-15s\",\"lt\":\"now+8h\"}}}" +
        "]}}," +
        "{\"bool\":{\"filter\":[" +
        "{\"term\":{\"isAlarm\":true}}," +
        linkTagInfoCameraIdStr +
        linkTagInfoAnalyServerFilterStr +
        "{\"range\":{\"linkTagInfo.picDate\":{\"gte\":\"now+8h-15s\",\"lt\":\"now+8h\"}}}" +
        "]}}" +
        "],\"minimum_should_match\":1}}," +
        "\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," +
        "\"size\":\"1000\"," +
        "\"_source\":{\"includes\":[],\"excludes\":[\"*.feature\"]}}"
    tokenRes := esutil.GetEsDataReq(url, prama, true)
    tmpAllDate := esutil.ResponseData(tokenRes)
    return &bhomeclient.Reply{Success:true, Data:tmpAllDate}
}