From f88a44f58396fb36a979cfe5640a36d6ac2d7289 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期四, 25 七月 2019 14:50:56 +0800 Subject: [PATCH] add discovery --- controllers/dbtablesCon.go | 44 ++++++++++++++++++++------------------------ 1 files changed, 20 insertions(+), 24 deletions(-) diff --git a/controllers/dbtablesCon.go b/controllers/dbtablesCon.go index 973a343..e74d046 100644 --- a/controllers/dbtablesCon.go +++ b/controllers/dbtablesCon.go @@ -4,13 +4,13 @@ "encoding/json" "fmt" "github.com/gin-gonic/gin" + "github.com/satori/go.uuid" + "log" "webserver/extend/code" "webserver/extend/config" "webserver/extend/esutil" "webserver/extend/util" "webserver/models" - "github.com/satori/go.uuid" - "log" ) type DbTableController struct { @@ -31,13 +31,13 @@ isSync := c.Params.ByName("isSync") syncTerm := "" if isSync == "1" { - syncTerm = ",{\"term\":{\"syncType\":\"1\"}}" // 鍚屾搴� + syncTerm = ",{\"term\":{\"isSync\":\"1\"}}" // 鍚屾搴� } else if isSync == "2" { - syncTerm = ",{\"term\":{\"syncType\":\"2\"}}" // / 鏈湴搴� + syncTerm = ",{\"term\":{\"isSync\":\"2\"}}" // / 鏈湴搴� } params := "{\"query\":{\"bool\":{\"must\":[" + - "{\"term\":{\"del_flag\":\"0\"}}" + syncTerm + "]}}," + - "\"from\":0,\"size\":100,\"sort\":{\"uuid\":{\"order\":\"asc\"}}}" + "{\"term\":{\"isDelete\":\"0\"}}" + syncTerm + "]}}," + + "\"from\":0,\"size\":100,\"sort\":{\"id\":{\"order\":\"asc\"}}}" fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, true) @@ -46,17 +46,13 @@ } // 渚濇嵁搴曞簱id 鏌ヨ鏁版嵁 -func QueryDbTableInfo(tableId string) map[string]interface{} { +func QueryDbTableInfo(tableId string) map[string]interface{} { url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.DbTables.IndexName +"/" + config.EsInfo.EsIndex.DbTables.IndexName + "/"+tableId + "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + tableId fmt.Print("璇锋眰url:%s;", url) data := esutil.GetEsDataInfo(url, true) return data - } - - - - +} // @Summary 淇敼搴曞簱 // @Description 淇敼鍚屾鎴栨湰鍦板簱 @@ -70,13 +66,13 @@ func (dbt DbTableController) UpdateDbTables(c *gin.Context) { dbtable := new(models.Dbtables) c.BindJSON(&dbtable) - uuid := c.Params.ByName("uuid") + uuid := c.Params.ByName("id") if uuid == "" { - uuid = dbtable.Uuid - fmt.Println("body涓幏鍙栧簳搴搖uid") + uuid = dbtable.Id + fmt.Println("body涓幏鍙栧簳搴搃d") } url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + uuid + "/_update" + "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + uuid + "/_update?refresh=wait_for" dbtable.PriUpdate() dbTableByte, err := json.Marshal(dbtable) if err != nil { @@ -110,9 +106,9 @@ dbtable := new(models.Dbtables) c.BindJSON(&dbtable) tableId := uuid.NewV4().String() - dbtable.Uuid = tableId + dbtable.Id = tableId url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + tableId + "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + tableId + "?refresh=wait_for" dbtable.PriInsert() // 娣诲姞鏃堕棿鍜屽垱寤轰汉 dbTableByte, err := json.Marshal(dbtable) if err != nil { @@ -121,7 +117,7 @@ //fmt.Printf("%s\n", dbTableByte) params := string(dbTableByte) fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) - data,_ := esutil.PutEsDataReq(url, params) + data, _ := esutil.PutEsDataReq(url, params) //c.JSON(200, changeEsRespData(data, "娣诲姞鎴愬姛")) result := changeEsRespData(data, "娣诲姞鎴愬姛") if result["success"].(bool) { @@ -141,12 +137,12 @@ // @Param uuid path string true "搴曞簱id " // @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" // @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" -// @Router /data/api-v/dbtable/deleteDBtablesById/{uuid} [POST] +// @Router /data/api-v/dbtable/deleteDBtablesById/{id} [POST] func (dbt DbTableController) DeleteDbTables(c *gin.Context) { - uuid := c.Params.ByName("uuid") + uuid := c.Params.ByName("id") url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + uuid + "/_update" - params := "{\"doc\":{\"del_flag\":\"1\"}}" + "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + uuid + "/_update?refresh=wait_for" + params := "{\"doc\":{\"isDelete\":\"1\"}}" fmt.Print("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, false) //c.JSON(200, changeEsRespData(data, "鍒犻櫎鎴愬姛")) -- Gitblit v1.8.0