From 4622e4986f10bcb6fbccff97b04c225d7dcf58fe Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期五, 16 八月 2019 15:21:27 +0800 Subject: [PATCH] test --- controllers/dbtableperson.go | 126 +++++++++++++++++++++++++++++++++++++----- 1 files changed, 111 insertions(+), 15 deletions(-) diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go index 738128d..205d473 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,21 @@ "/" + 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) 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,19 +99,76 @@ 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) util.ResponseFormat(c, code.ServiceInsideError, result["data"]) } +} + +func UpdateDbPersonsOfDbTable(id string) (message string) { + url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh" + jsonDSL := ` + { + "script": { + "lang": "painless", + "inline": "ctx._source.enable = 0" + }, + "query": { + "term": { + "tableId": "` + id + `" + } + } +} +` + buf, err := esutil.EsReq("POST", url, []byte(jsonDSL)) + if err != nil { + logger.Debug("http request info is err!") + message = "淇敼澶辫触" + } + var info interface{} + json.Unmarshal(buf, &info) + out, ok := info.(map[string]interface{}) + if !ok { + logger.Debug("http response interface can not change map[string]interface{}") + message = "淇敼澶辫触" + } + middle, ok := out["updated"].(float64) + if !ok { + logger.Debug("first result change error!") + message = "淇敼澶辫触" + } + if middle >= 0 { + logger.Debug("淇敼鎴愬姛") + message = "淇敼鎴愬姛,鏇存柊鐘舵�佹潯鏁颁负" + strconv.Itoa(int(middle)) + } + return message } // @Summary 鍒犻櫎搴曞簱浜哄憳 @@ -119,7 +186,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 +194,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 +230,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 +304,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\"," + @@ -223,8 +318,7 @@ } params := "{\"query\":{\"bool\":{\"must_not\":[" + - "{\"term\":{\"isDelete\":\"1\"}}],\"must_not\":[" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" - fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) + "{\"term\":{\"isDelete\":\"1\"}}],\"filter\":[" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" data := esutil.GetEsDataReq(url, params, true) //c.JSON(200, data) util.ResponseFormat(c, code.Success, data) @@ -280,7 +374,7 @@ if tableId == "all" || tableId == "" { // / 鎵�鏈変汉鍛� } else { - syncTerm = ",{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳 + syncTerm = "{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳 } if orderType == "desc" { orderType = "desc" @@ -288,9 +382,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