From b0500fee9c01e17c81b9293b244c8ed88dc9ca29 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期五, 11 十月 2019 15:12:25 +0800 Subject: [PATCH] add swagger --- controllers/es.go | 68 +++++++++++++++------------------- 1 files changed, 30 insertions(+), 38 deletions(-) diff --git a/controllers/es.go b/controllers/es.go index fe2afbc..d566366 100644 --- a/controllers/es.go +++ b/controllers/es.go @@ -1,12 +1,13 @@ package controllers import ( - "basic.com/dbapi.git" + "basic.com/valib/logger.git" "fmt" "github.com/gin-gonic/gin" "math/rand" "strconv" "strings" + "webserver/cache" "webserver/extend/code" "webserver/extend/config" "webserver/extend/esutil" @@ -33,40 +34,28 @@ util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎") return } - databases := searchBody.DataBases - from := 0 - to := 0 - - data := make(map[string]interface{}) - searchBody.Page = 1 - searchBody.Size = 15000 - - if len(databases) == 1 && databases[0] == "esData" { - searchBody.IsAggs = false - } else { - data = service.QueryDbPersonsForCompare(*searchBody) + if searchBody.CompareNum !="" { + //浜屾鎼滅储锛屼笉闇�瑕佸啀姣斿浜� + co := service.GetCompResultByNum(searchBody.CompareNum) + if co != nil { + //浜屾鎼滅储鍜屾帓搴� + twiceM := GetCompareDataTwice(co,searchBody) + util.ResponseFormat(c,code.Success,twiceM) + return + } else { + m :=make(map[string]interface{},0) + m["compareNum"] = searchBody.CompareNum + m["total"] = 0 + m["totalList"] = []CompareResult{} + util.ResponseFormat(c,code.CompareResultGone,m) + return + } } - sources := data["datalist"].([]interface{}) - - if len(sources) > 0 { - //杩涜姣斿 - } else { - fmt.Println("鏌ヨ鏉′欢涓嬫棤鏁版嵁 source 鏁版嵁涓虹┖锛�" + string(len(sources))) - } - dataLen := len(sources) - if from > dataLen-1 { - from = 0 - to = 0 - } - if to > dataLen { - to = dataLen - } - - dmap := make(map[string]interface{}, 2) - dmap["datalist"] = sources - dmap["total"] = dataLen - util.ResponseFormat(c, code.Success, dmap) - + m :=make(map[string]interface{},0) + m["compareNum"] = searchBody.CompareNum + m["total"] = 0 + m["totalList"] = []CompareResult{} + util.ResponseFormat(c,code.CompareResultGone,m) } func searchEsData(searchBody models.EsSearch) map[string]interface{} { @@ -115,12 +104,15 @@ esSize := strconv.Itoa(webSize) //浣跨敤es搴曞眰鏈哄埗澶勭悊鍒嗛〉 //璇锋眰澶� - url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + + localConf, err2 := cache.GetServerInfo() + if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" { + logger.Debug("localConfig is wrong!!!") + return nil + } + url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) + "/" + index + "/_search?search_type=dfs_query_then_fetch" - var setApi dbapi.SysSetApi - _, sysconf := setApi.GetServerInfo() - analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + sysconf.ServerId + "\"}}," + analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}}," //璇锋眰浣� prama := "{\"from\":\"" + esFrom + "\",\"size\":\"" + esSize + "\"," + -- Gitblit v1.8.0