liuxiaolong
2019-08-01 978757c6cd702684d736ddf733f1d718a8c67060
controllers/dbtableperson.go
@@ -1,11 +1,13 @@
package controllers
import (
   "basic.com/pubsub/protomsg.git"
   "encoding/json"
   "fmt"
   "log"
   "strconv"
   "time"
   "webserver/discovery"
   "webserver/extend/logger"
   "github.com/gin-gonic/gin"
   "github.com/satori/go.uuid"
@@ -14,6 +16,7 @@
   "webserver/extend/esutil"
   "webserver/extend/util"
   "webserver/models"
   esApi "basic.com/pubsub/esutil.git"
)
type DbPersonController struct {
@@ -55,11 +58,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 +103,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 +150,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 +158,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 +194,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 +268,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 +282,8 @@
   }
   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 + "\"}}}"
   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 +339,7 @@
   if tableId == "all" || tableId == "" {
      // / 所有人员
   } else {
      syncTerm = ",{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 底库人员
      syncTerm = "{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 底库人员
   }
   if orderType == "desc" {
      orderType = "desc"
@@ -288,9 +347,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