From cfeba2dea02c1de54cde6c95f2a3f46c121d34aa Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期五, 16 八月 2019 15:16:14 +0800 Subject: [PATCH] dev add publicDomain --- controllers/dbtableperson.go | 151 +++++++++++++++++++++++++++++++------------------- 1 files changed, 93 insertions(+), 58 deletions(-) diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go index 3a987c0..205d473 100644 --- a/controllers/dbtableperson.go +++ b/controllers/dbtableperson.go @@ -1,12 +1,10 @@ package controllers import ( - "basic.com/pubsub/protomsg.git" "encoding/json" "log" "strconv" "time" - "webserver/discovery" "webserver/extend/logger" "github.com/gin-gonic/gin" @@ -16,7 +14,6 @@ "webserver/extend/esutil" "webserver/extend/util" "webserver/models" - esApi "basic.com/pubsub/esutil.git" ) type DbPersonController struct { @@ -61,18 +58,17 @@ logger.Debug("Json marshaling failed锛�%s\n", e) } params := string(personbytes) - 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, - }) - } + //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, "娣诲姞鎴愬姛") @@ -111,28 +107,68 @@ 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, - }) - } + //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 鍒犻櫎搴曞簱浜哄憳 @@ -159,18 +195,18 @@ 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, - }) - } - } + //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 { @@ -203,20 +239,20 @@ //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, - }) - } - } - } + //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) @@ -283,7 +319,6 @@ 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) -- Gitblit v1.8.0