liuxiaolong
2019-07-30 ffa86a861692056ca78943059b1b5c04c78d17c9
controllers/taglist.go
@@ -1,6 +1,7 @@
package controllers
import (
   "encoding/json"
   "fmt"
   "github.com/gin-gonic/gin"
@@ -8,7 +9,6 @@
   "webserver/extend/config"
   "webserver/extend/esutil"
   "webserver/extend/util"
   "strconv"
)
//标签列表
@@ -26,19 +26,56 @@
   url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
      "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/_search"
   prama := "{\"query\":{\"bool\":{\"filter\":[]}},\"_source\":[\"tableName\",\"id\",\"isDelete\"]}"
   prama := "{\"query\":{\"bool\":{\"filter\":[]}},\"size\":10000,\"_source\":[\"tableName\",\"id\",\"isDelete\"]}"
   tokenRes := esutil.GetEsDataReq(url, prama, true)
   sources := make([]map[string]interface{}, 0)
   fmt.Println(tokenRes["datalist"].([]interface{}))
   for _, value := range tokenRes["datalist"].([]interface{}) {
      tokenRes := make(map[string]interface{})
      tokenRes["key"] = value.(map[string]interface{})["id"].(string)
      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"] = strconv.Itoa(status)
      tokenRes["status"] = status
      if status == 1  {
         if GetTotalFromDb(key) == false{
            continue
         }
      }
      sources = append(sources, tokenRes)
   }
   util.ResponseFormat(c, code.Success, sources)
}
//判断底库是否有数据
func GetTotalFromDb(id string) (flag bool) {
   flag = false
   url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
      "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/_search"
   prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"baseInfo.tableId\":\""+id+"\"}}]}},\"size\":0}"
   buf, err := esutil.EsReq("POST", url, []byte(prama))
            if err != nil {
                fmt.Println("http request info is err!")
                return
            }
            var info interface{}
            json.Unmarshal(buf, &info)
            out, ok := info.(map[string]interface{})
            if !ok {
                fmt.Println("http response interface can not change map[string]interface{}")
                return
            }
            middle, ok := out["hits"].(map[string]interface{})
            if !ok {
                fmt.Println("first hits change error!")
                return
            }
            total := int(middle["total"].(float64))
         fmt.Println(total)
         if total > 0 {
            flag=true
         }
            return flag
}