sunty
2019-07-30 f86d25d5143847692779dd4e81b7e47d9b25376e
controllers/taglist.go
@@ -35,8 +35,44 @@
      tokenRes["key"] = value.(map[string]interface{})["id"].(string)
      tokenRes["title"] = value.(map[string]interface{})["tableName"].(string)
      tokenRes["value"] = value.(map[string]interface{})["id"].(string)
      tokenRes["status"] = value.(map[string]interface{})["isDelete"]
      tokenRes["status"] = int(value.(map[string]interface{})["isDelete"])
      if tokenRes["status"] == 1  {
         if GetTotalFromDb(tokenRes["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 := 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
}