sunty
2020-08-20 9303b69ea569bcb5e581147543a3fd58e90d0d25
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package controllers
 
import (
    "basic.com/valib/logger.git"
    "fmt"
    "github.com/gin-gonic/gin"
    "strconv"
    "strings"
    "webserver/cache"
    "webserver/extend/code"
    "webserver/extend/config"
    "webserver/extend/esutil"
    "webserver/extend/util"
)
 
type InitForData struct {
}
 
// @Security ApiKeyAuth
// @Summary 抓拍实时图数据初始化
// @Description 实时获取数据
// @Accept  json
// @Produce json
// @Tags realTime
// @Param obj body controllers.RealTimeArg false "抓拍实时图初始化参数"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"", success:false}"
// @Router /data/api-v/realTime/initForCaptureData [POST]
//实时抓拍数据初始化
func (rc *RealTimeController) InitForCaptureData(c *gin.Context) {
    //searchBody := make(map[string]interface{}, 0)
    var searchBody RealTimeArg
    c.BindJSON(&searchBody)
    index := config.EsInfo.EsIndex.AiOcean.IndexName
    localConf, err2 := cache.GetServerInfo()
    if err2 != nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
        logger.Debug("localConfig is wrong!!!")
        util.ResponseFormat(c, code.ComError, "localConf wrong")
        return
    }
    url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) +
        "/" + index + "/_search"
    cameraIdStr := ""
    linkTagInfoCameraIdStr := ""
    if searchBody.TreeNodes != nil {
        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 + "\"]}},"
        }
    }
 
    analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}}"
    linkTagInfoAnalyServerFilterStr := "{\"term\":{\"linkTagInfo.analyServerId\":\"" + localConf.ServerId + "\"}}"
 
    prama := "{\"query\":{\"bool\":{\"should\":[" +
        "{\"bool\":{\"filter\":[" +
        "{\"term\":{\"isAlarm\":true}}," +
        cameraIdStr +
        analyServerFilterStr +
        "]}}," +
        "{\"bool\":{\"filter\":[" +
        "{\"term\":{\"isAlarm\":true}}," +
        linkTagInfoCameraIdStr +
        linkTagInfoAnalyServerFilterStr +
        "]}}" +
        "],\"minimum_should_match\":1}}," +
        "\"size\":\"20\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," +
        "\"_source\":{\"includes\":[],\"excludes\":[\"*.feature\"]}" +
        "}"
    logger.Debug("InitForCaptureData:", prama)
    tokenRes := esutil.GetEsDataReq(url, prama, true)
    tmpAllDate := esutil.ResponseData(tokenRes)
    util.ResponseFormat(c, code.Success, tmpAllDate)
}
 
type InitForMonitorArg struct {
    TreeNodes []string `json:"treeNodes"`
    Tasks     []string `json:"tasks"`
}
 
// @Security ApiKeyAuth
// @Summary 实时任务监控数据初始化
// @Description 实时监控比对数据
// @Accept  json
// @Produce json
// @Tags realTime
// @Param obj body controllers.InitForMonitorArg true "实时任务监控参数"
// @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/realTime/initForMonitoringData [POST]
func (rc *RealTimeController) InitForMonitoringData(c *gin.Context) {
    //searchBody := make(map[string]interface{}, 0)
    var searchBody InitForMonitorArg
    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 + "\"]}},"
    }
    //判断任务ID
    taskIdStr := ""
    linkTagInfoTaskIdStr := ""
    taskId := searchBody.Tasks
    if taskId != nil && len(taskId) > 0 {
        esTaskId := strings.Replace(strings.Trim(fmt.Sprint(taskId), "[]"), " ", "\",\"", -1)
        taskIdStr = "{\"terms\":{\"taskId\":[\"" + esTaskId + "\"]}},"
        linkTagInfoTaskIdStr = "{\"terms\":{\"linkTagInfo.taskId\":[\"" + esTaskId + "\"]}},"
    }
    //请求头
    localConf, err2 := cache.GetServerInfo()
    if err2 != nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
        logger.Debug("localConfig is wrong!!!")
        util.ResponseFormat(c, code.ComError, "localConf wrong")
        return
    }
    url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) +
        "/" + index + "/_search"
 
    analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}}"
    linkTagInfoAnalyServerFilterStr := "{\"term\":{\"linkTagInfo.analyServerId\":\"" + localConf.ServerId + "\"}}"
 
    prama := "{\"query\":{\"bool\":{\"should\":[" +
        "{\"bool\":{\"filter\":[" +
        taskIdStr +
        cameraIdStr +
        analyServerFilterStr +
        "]}}," +
        "{\"bool\":{\"filter\":[" +
        linkTagInfoTaskIdStr +
        linkTagInfoCameraIdStr +
        linkTagInfoAnalyServerFilterStr +
        "]}}" +
        "],\"minimum_should_match\":1}}," +
        "\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," +
        "\"size\":\"20\"," +
        "\"_source\":{\"includes\":[],\"excludes\":[\"*.feature\"]}}"
    //logger.Debug("url:", url)
    //logger.Debug("InitForMonitoringData:", prama)
    tokenRes := esutil.GetEsDataReq(url, prama, true)
    tmpAllDate := esutil.ResponseData(tokenRes)
    util.ResponseFormat(c, code.Success, tmpAllDate)
}