From f86d25d5143847692779dd4e81b7e47d9b25376e Mon Sep 17 00:00:00 2001
From: sunty <suntianyu0923@163.com>
Date: 星期二, 30 七月 2019 11:16:15 +0800
Subject: [PATCH] fix delete dbtable add GetTotalFromDb and EsReq

---
 controllers/taglist.go |   38 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/controllers/taglist.go b/controllers/taglist.go
index 27e679d..774f21d 100644
--- a/controllers/taglist.go
+++ b/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
 }
\ No newline at end of file

--
Gitblit v1.8.0