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
package controllers
 
import (
    "basic.com/pubsub/esutil.git"
    "basic.com/valib/logger.git"
    "fmt"
    "github.com/gin-gonic/gin"
    "strconv"
    "webserver/cache"
    "webserver/extend/code"
    "webserver/extend/config"
    "webserver/extend/util"
)
 
type DeleteDataController struct{}
 
type deleteParams struct {
    StartTime string `json:"startTime"`
    EndTime   string `json:"endTime"`
}
 
func (cdc *DeleteDataController) DeleteEsData(c *gin.Context) {
    var cp deleteParams
    localConf, err := cache.GetServerInfo()
    if err != nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
        logger.Debug("localConfig is wrong!!!")
        util.ResponseFormat(c, code.ComError, "es config err")
        return
    }
    ip := localConf.AlarmIp
    port := strconv.Itoa(int(localConf.AlarmPort))
    analyServerId := localConf.ServerId
    c.BindJSON(&cp)
    startTime := cp.StartTime
    endTime := cp.EndTime
    queryRes, queryErr := esutil.QueryAnalyServerData(ip, port, config.EsInfo.EsIndex.AiOcean.IndexName, startTime, endTime, analyServerId)
    if queryErr != nil {
        util.ResponseFormat(c, code.InvalidRequest, "校验数据失败")
        return
    }
    if queryRes != true {
        util.ResponseFormat(c, code.InvalidRequest, "数据已删除或该时间段无数据")
        return
    }
    fmt.Println("asgdasgdjhas: ", ip, port, config.BasicFS.IndexName, startTime, endTime, analyServerId)
    addRes, addErr := esutil.AddDelTask(ip, port, config.BasicFS.IndexName, startTime, endTime, analyServerId)
    if addErr != nil {
        fmt.Println("错误为u:   ", addErr)
        util.ResponseFormat(c, code.InvalidRequest, "追加任务出错")
        return
    }
    if addRes != true {
        util.ResponseFormat(c, code.InvalidRequest, "追加任务失败")
        return
    }
    deleteRes, deleteErr := esutil.DeleteAnalyServerData(ip, port, config.EsInfo.EsIndex.AiOcean.IndexName, startTime, endTime, analyServerId)
    if deleteErr != nil {
        util.ResponseFormat(c, code.InvalidRequest, "数据删除出错")
        return
    }
    if deleteRes != true {
        util.ResponseFormat(c, code.InvalidRequest, "数据删除失败")
        return
    }
    util.ResponseFormat(c, code.Success, deleteRes)
    return
}