From 720cbb945fbf143c2957c2c20384fd272a2d6d2b Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期二, 06 八月 2019 15:25:38 +0800
Subject: [PATCH] new fx fy in ReadFromUploadImg
---
controllers/dbtableperson.go | 185 ++++++++++++++++++++++++++++++++++++----------
1 files changed, 144 insertions(+), 41 deletions(-)
diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go
index c41586f..205d473 100644
--- a/controllers/dbtableperson.go
+++ b/controllers/dbtableperson.go
@@ -2,18 +2,18 @@
import (
"encoding/json"
- "fmt"
"log"
"strconv"
"time"
+ "webserver/extend/logger"
"github.com/gin-gonic/gin"
+ "github.com/satori/go.uuid"
"webserver/extend/code"
"webserver/extend/config"
"webserver/extend/esutil"
"webserver/extend/util"
"webserver/models"
- "github.com/satori/go.uuid"
)
type DbPersonController struct {
@@ -49,17 +49,27 @@
func addDbPerson(dbperson *models.Dbtablepersons) (result map[string]interface{}) {
personId := uuid.NewV4().String() // 浠ュ悗鏇夸唬 渚濇嵁鐢熸垚瑙勫垯
- dbperson.Uuid = personId
+ dbperson.Id = personId
dbperson.PriInsert()
url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + personId+"?refresh=wait_for"
+ "/" + 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)
+ 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
@@ -77,7 +87,7 @@
func (dbc DbPersonController) UpdateDbPerson(c *gin.Context) {
var dbperson models.Dbtablepersons
c.BindJSON(&dbperson)
- personid := dbperson.Uuid
+ personid := dbperson.Id
if personid == "" {
util.ResponseFormat(c, code.RequestParamError, nil)
return
@@ -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 鍒犻櫎搴曞簱浜哄憳
@@ -113,23 +180,41 @@
// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}"
// @Router /data/api-v/dbperson/deleteDbPersonById/{uuid} [POST]
+
func (dbc DbPersonController) DeleteDbPerson(c *gin.Context) {
uuid := c.Params.ByName("uuid")
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\":{\"del_flag\":\"1\",\"update_time\":\"" + time.Now().Format("2006-01-02 15:04:05") + "\"}}"
- fmt.Print("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
+ params := "{\"doc\":{\"isDelete\":\"1\",\"updateTime\":\"" + time.Now().Format("2006-01-02 15:04:05") + "\"}}"
+ 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 = "鍒犻櫎搴曞簱浜哄憳鎴愬姛"
+ //閫氱煡姣斿杩涚▼锛屾浜哄凡鍒犻櫎
+ //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)
util.ResponseFormat(c, code.ServiceInsideError, result["data"])
}
}
+
// @Summary 鍒犻櫎搴曞簱浜哄憳
// @Description 鍒犻櫎搴撲汉鍛�
// @Accept json
@@ -139,25 +224,39 @@
// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}"
// @Router /data/api-v/dbperson/deleteMoreDbPerson [POST]
-func (dbc DbPersonController) DeleteMoreDbPerson(c *gin.Context) {
- uuids := make([]string,0,5)
+func (dbc DbPersonController) DeleteMoreDbPerson(c *gin.Context) {
+ uuids := make([]string, 0, 5)
c.BindJSON(&uuids)
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
- params := "{\"script\":{\"lang\":\"painless\",\"inline\":\"ctx._source.del_flag = \\\"1\\\";" +
- "ctx._source.update_time = \\\"" + time.Now().Format("2006-01-02 15:04:05") + "\\\"\"},\"query\":{\"terms\":{\"_id\":"+s+"}}}"
- fmt.Print("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
+ "/" + 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 + "}}}"
+ 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 = "鍒犻櫎搴曞簱浜哄憳鎴愬姛"
- util.ResponseFormat(c, code.Success,"鍒犻櫎搴曞簱浜哄憳鎴愬姛" )
+ //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)
- util.ResponseFormat(c, code.ServiceInsideError,data["error"])
+ util.ResponseFormat(c, code.ServiceInsideError, data["error"])
}
}
@@ -205,11 +304,11 @@
if tableId == "all" || tableId == "" {
// / 鎵�鏈変汉鍛�
} else {
- syncTerm = ",{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳
+ syncTerm = "{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳
}
if contentValue != "" {
contentParam = ",\"must\":[{\"multi_match\":{\"query\":\"" + contentValue + "\",\"type\":\"best_fields\"," +
- "\"fields\":[\"personName\",\"sex\",\"idcard\",\"phoneNum\"],\"tie_breaker\":0.3}}]"
+ "\"fields\":[\"personName\",\"sex\",\"idCard\",\"phoneNum\"],\"tie_breaker\":0.3}}]"
}
if orderType == "desc" {
@@ -218,14 +317,12 @@
orderType = "asc"
}
- params := "{\"query\":{\"bool\":{\"filter\":[" +
- "{\"term\":{\"del_flag\":\"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 + "\"}}}"
data := esutil.GetEsDataReq(url, params, true)
//c.JSON(200, data)
util.ResponseFormat(c, code.Success, data)
}
-
// @Summary 鏌ヨ搴曞簱浜哄憳鍒楄〃
// @Description 鏌ヨ搴撲汉鍛樺垪琛�
@@ -238,7 +335,7 @@
// @Router /data/api-v/dbperson/queryDbPersonsByCampare [POST]
func (dbc DbPersonController) QueryDbPersonsByCampare(c *gin.Context) {
url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_search" // ?refresh=wait_for
+ "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_search" // ?refresh=wait_for
reqBody := make(map[string]interface{}, 5)
c.BindJSON(&reqBody)
tableId := ""
@@ -253,12 +350,13 @@
if reqBody["orderType"] != nil {
orderType = reqBody["orderType"].(string)
} // 鍒楃被鍨�
- faceUrl := ""; var threshold float32
- if reqBody["faceUrl"] != nil && reqBody["threshold"] != nil{
+ faceUrl := ""
+ var threshold float32
+ if reqBody["faceUrl"] != nil && reqBody["threshold"] != nil {
faceUrl = reqBody["faceUrl"].(string)
threshold = float32(reqBody["threshold"].(float64))
- }else {
- util.ResponseFormat(c, code.RequestParamError, nil); // 鍥剧墖璺緞鏈夐棶棰�
+ } else {
+ util.ResponseFormat(c, code.RequestParamError, nil) // 鍥剧墖璺緞鏈夐棶棰�
return
}
//杈撳叆妗嗗唴瀹�
@@ -276,7 +374,7 @@
if tableId == "all" || tableId == "" {
// / 鎵�鏈変汉鍛�
} else {
- syncTerm = ",{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳
+ syncTerm = "{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳
}
if orderType == "desc" {
orderType = "desc"
@@ -284,11 +382,13 @@
orderType = "asc"
}
- params := "{\"query\":{\"bool\":{\"filter\":[" +
- "{\"term\":{\"del_flag\":\"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)
+ featByte := make([]byte, 0, 1024)
if len(faceUrl) > 3 { // linux
/*fileName := picUrl // picIp 瀹氫箟鍦� fileController weedfs 鏂囦欢鏈嶅姟鍣� 璁块棶 璺緞 鍓嶇紑
detect := gorun.GetSimpleFaceDetect(fileName)
@@ -299,14 +399,17 @@
featByte = detect[0]["feature"].([]byte)
}*/ // linux
}
- to := page*size
- datalist := sourceCompare(data["datalist"].([]interface{}),false,featByte,threshold )
+ to := page * size
+ datalist := sourceCompare(data["datalist"].([]interface{}), false, featByte, threshold)
total := len(datalist)
- if from > total { from = total }
- if to > total { to = total }
+ if from > total {
+ from = total
+ }
+ if to > total {
+ to = total
+ }
data["datalist"] = datalist[from:to]
data["total"] = len(datalist)
//c.JSON(200, data)
util.ResponseFormat(c, code.Success, data)
}
-
--
Gitblit v1.8.0