From 7c811247ecf143e08c576986a884bedadc57dd66 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期五, 05 六月 2020 18:29:41 +0800 Subject: [PATCH] add refresh token to resp --- controllers/taglist.go | 70 ++++++++++++++++++++--------------- 1 files changed, 40 insertions(+), 30 deletions(-) diff --git a/controllers/taglist.go b/controllers/taglist.go index d4a2a08..689dae7 100644 --- a/controllers/taglist.go +++ b/controllers/taglist.go @@ -2,58 +2,67 @@ import ( "basic.com/dbapi.git" + "basic.com/valib/logger.git" "encoding/json" "fmt" - - "github.com/gin-gonic/gin" + "strconv" + "webserver/cache" "webserver/extend/code" "webserver/extend/config" "webserver/extend/esutil" "webserver/extend/util" + + "github.com/gin-gonic/gin" ) -//鏍囩鍒楄〃 -//浠诲姟鍒楄〃 +// @Security ApiKeyAuth // @Summary 鏍囩鍒楄〃 // @Description 杩斿洖搴曞簱鏍囩 // @Accept json // @Produce json // @Tags es -// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" -// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" -// @Router /data/api-v/es/taskList [POST] +// @Success 200 {string} json "{"code":200, msg:"", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"", success:false}" +// @Router /data/api-v/es/tagList [POST] func (sc *EsSearchController) PostEsTagList(c *gin.Context) { - url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/_search" - var setApi dbapi.SysSetApi - _, sysconf := setApi.GetServerInfo() - prama := "{\"query\":{\"bool\":{\"filter\":[{\"terms\":{\"analyServerId\":[\"\",\"" + sysconf.ServerId + "\"]}}]}},\"size\":1000}" - tokenRes := esutil.GetEsDataReq(url, prama, true) - sources := make([]map[string]interface{}, 0) - for _, value := range tokenRes["datalist"].([]interface{}) { - tokenRes := make(map[string]interface{}) - key := value.(map[string]interface{})["id"].(string) - tokenRes["key"] = key - tokenRes["title"] = value.(map[string]interface{})["tableName"].(string) - tokenRes["value"] = value.(map[string]interface{})["id"].(string) - status := int(value.(map[string]interface{})["isDelete"].(float64)) - tokenRes["status"] = status - if status == 1 { - if GetTotalFromDb(key) == false { - continue + var dtApi dbapi.DbTableApi + dts, err := dtApi.FindAllDbTablesByCurServer("-1") + if err == nil { + if dts !=nil { + sources := make([]map[string]interface{}, 0) + for _, dt := range dts { + tokenRes := make(map[string]interface{}) + tokenRes["key"] = dt.Id + tokenRes["title"] = dt.TableName + tokenRes["value"] = dt.Id + tokenRes["status"] = dt.IsDelete + tokenRes["bwType"] = dt.BwType //0锛氱櫧鍚嶅崟锛�1锛氶粦鍚嶅崟 + tokenRes["analyServerId"] = dt.AnalyServerId //涓虹┖鏄悓姝ュ簱锛屼笉涓虹┖鏄湰鍦板簱 + if dt.IsDelete == 1 { + if GetTotalFromDb(dt.Id) == false { + continue + } + } + sources = append(sources, tokenRes) } + util.ResponseFormat(c, code.Success, sources) + return } - sources = append(sources, tokenRes) } - util.ResponseFormat(c, code.Success, sources) + util.ResponseFormat(c,code.ComError,"鏌ヨ搴曞簱鏍囩澶辫触") } //鍒ゆ柇搴曞簱鏄惁鏈夋暟鎹� func GetTotalFromDb(id string) (flag bool) { flag = false - url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/_search" + localConf, err2 := cache.GetServerInfo() + if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" { + logger.Debug("localConfig is wrong!!!") + return false + } + url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) + + "/" + config.EsInfo.EsIndex.AiOcean.IndexName + "/_search" prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"baseInfo.tableId\":\"" + id + "\"}}]}},\"size\":0}" buf, err := esutil.EsReq("POST", url, []byte(prama)) if err != nil { @@ -72,9 +81,10 @@ fmt.Println("first hits change error!") return } + total := int(middle["total"].(float64)) if total > 0 { flag = true } return flag -} +} \ No newline at end of file -- Gitblit v1.8.0