From 24e2d92df7cad99e1e514fa581fe59765dbc4a12 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期五, 02 八月 2019 09:54:33 +0800 Subject: [PATCH] rm discovery server --- controllers/dbtableperson.go | 90 +++++++++++++++++++++++++++++++++++++-------- 1 files changed, 74 insertions(+), 16 deletions(-) diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go index 0ab08be..bad1888 100644 --- a/controllers/dbtableperson.go +++ b/controllers/dbtableperson.go @@ -2,10 +2,10 @@ import ( "encoding/json" - "fmt" "log" "strconv" "time" + "webserver/extend/logger" "github.com/gin-gonic/gin" "github.com/satori/go.uuid" @@ -55,11 +55,22 @@ "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + personId + "?refresh=wait_for" personbytes, e := json.Marshal(dbperson) if e != nil { - fmt.Print("Json marshaling failed锛�%s\n", e) + logger.Debug("Json marshaling failed锛�%s\n", e) } params := string(personbytes) - fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) + logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data, _ := esutil.PutEsDataReq(url, params) + //if data["_id"] !=""{ + // //閫氱煡姣斿杩涚▼缂撳瓨鏇存柊 + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTablePerson, + // PersonId: personId, + // TableId: []string{ dbperson.TableId }, + // Feature: dbperson.FaceFeature, + // Action: protomsg.DbAction_Insert, + // }) + //} + //c.JSON(200, changeEsRespData(data, "娣诲姞浜哄憳鎴愬姛")) result = changeEsRespData(data, "娣诲姞鎴愬姛") return result @@ -89,14 +100,31 @@ if err != nil { log.Fatalf("Json marshaling failed锛�%s", err) } - //fmt.Printf("%s\n", dbTableByte) + //logger.Debugf("%s\n", dbTableByte) params := "{\"doc\":" + string(dbTableByte) + "}" - fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) + logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, false) //c.JSON(200, changeEsRespData(data,"淇敼鎴愬姛")) result := changeEsRespData(data, "淇敼鎴愬姛") if result["success"].(bool) { //code.Success.Message = "淇敼搴曞簱浜哄憳鎴愬姛" + //if dbperson.Enable == 1 { + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTablePerson, + // PersonId: dbperson.Id, + // TableId: []string{ dbperson.TableId }, + // Feature: "", + // Action: protomsg.DbAction_Insert, + // }) + //} else { + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTablePerson, + // PersonId: dbperson.Id, + // TableId: []string{ dbperson.TableId }, + // Feature: "", + // Action: protomsg.DbAction_Delete, + // }) + //} util.ResponseFormat(c, code.Success, result["data"]) } else { //code.ServiceInsideError.Message += result["msg"].(string) @@ -119,7 +147,7 @@ url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + uuid + "/_update?refresh=wait_for" params := "{\"doc\":{\"isDelete\":\"1\",\"updateTime\":\"" + time.Now().Format("2006-01-02 15:04:05") + "\"}}" - fmt.Print("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) + logger.Debug("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, false) @@ -127,6 +155,20 @@ result := changeEsRespData(data, "鍒犻櫎鎴愬姛") if result["success"].(bool) { //code.Success.Message = "鍒犻櫎搴曞簱浜哄憳鎴愬姛" + //閫氱煡姣斿杩涚▼锛屾浜哄凡鍒犻櫎 + //dbperArr, e := esApi.Dbpersoninfosbyid([]string{uuid}, config.EsInfo.EsIndex.Dbtablepersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport) + //if e ==nil && len(dbperArr) > 0{ + // if dbperArr[0].TableId !=""{ + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTablePerson, + // PersonId: uuid, + // TableId: []string{ dbperArr[0].TableId }, + // Feature: "", + // Action: protomsg.DbAction_Delete, + // }) + // } + //} + util.ResponseFormat(c, code.Success, result["data"]) } else { //code.ServiceInsideError.Message += result["msg"].(string) @@ -149,15 +191,29 @@ bytes, _ := json.Marshal(uuids) s := string(bytes) url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh=wait_for" // + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + "/" + s + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh" // + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + "/" + s params := "{\"script\":{\"lang\":\"painless\",\"inline\":\"ctx._source.isDelete = \\\"1\\\";" + "ctx._source.updateTime = \\\"" + time.Now().Format("2006-01-02 15:04:05") + "\\\"\"},\"query\":{\"terms\":{\"_id\":" + s + "}}}" - fmt.Print("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) + logger.Debug("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, false) //c.JSON(200, changeEsRespData(data,"鍒犻櫎鎴愬姛")) //result := changeEsRespData(data, "鍒犻櫎鎴愬姛") if data["error"] == nil { //code.Success.Message = "鍒犻櫎搴曞簱浜哄憳鎴愬姛" + //dbperArr, e := esApi.Dbpersoninfosbyid(uuids, config.EsInfo.EsIndex.Dbtablepersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport) + //if e ==nil && len(dbperArr) > 0{ + // for _,esPer :=range dbperArr { + // if esPer.TableId !=""{ + // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{ + // Type: protomsg.EsCacheChanged_T_DbTablePerson, + // PersonId: esPer.Id, + // TableId: []string{ esPer.TableId }, + // Feature: "", + // Action: protomsg.DbAction_Delete, + // }) + // } + // } + //} util.ResponseFormat(c, code.Success, "鍒犻櫎搴曞簱浜哄憳鎴愬姛") } else { //code.ServiceInsideError.Message += result["msg"].(string) @@ -209,7 +265,7 @@ if tableId == "all" || tableId == "" { // / 鎵�鏈変汉鍛� } else { - syncTerm = ",{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳 + syncTerm = "{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳 } if contentValue != "" { contentParam = ",\"must\":[{\"multi_match\":{\"query\":\"" + contentValue + "\",\"type\":\"best_fields\"," + @@ -222,9 +278,9 @@ orderType = "asc" } - params := "{\"query\":{\"bool\":{\"filter\":[" + - "{\"term\":{\"isDelete\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" - fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) + params := "{\"query\":{\"bool\":{\"must_not\":[" + + "{\"term\":{\"isDelete\":\"1\"}}],\"filter\":[" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" + logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, true) //c.JSON(200, data) util.ResponseFormat(c, code.Success, data) @@ -280,7 +336,7 @@ if tableId == "all" || tableId == "" { // / 鎵�鏈変汉鍛� } else { - syncTerm = ",{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳 + syncTerm = "{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳 } if orderType == "desc" { orderType = "desc" @@ -288,9 +344,11 @@ orderType = "asc" } - params := "{\"query\":{\"bool\":{\"filter\":[" + - "{\"term\":{\"isDelete\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" - fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) + //params := "{\"query\":{\"bool\":{\"filter\":[" + + // "{\"term\":{\"isDelete\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" + params := "{\"query\":{\"bool\":{\"must_not\":[" + + "{\"term\":{\"isDelete\":\"1\"}}],\"filter\":[" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" + logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, true) featByte := make([]byte, 0, 1024) if len(faceUrl) > 3 { // linux -- Gitblit v1.8.0