package controllers
|
|
import (
|
"encoding/json"
|
"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"
|
)
|
|
type DbPersonController struct {
|
}
|
|
// @Summary 添加底库人员
|
// @Description 添加底库人员
|
// @Accept json
|
// @Produce json
|
// @Tags dbperson 底库人员
|
// @Param obj body models.Dbtablepersons true "底库人员数据"
|
// @Success 200 {object} json "{"code":200, msg:"目录结构数据", success:true}"
|
// @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}"
|
// @Failure 400 {object} json code.RequestParamError
|
// @Router /data/api-v/dbperson/addDbPerson [PUT]
|
func (dbc DbPersonController) AddDbPerson(c *gin.Context) {
|
dbperson := new(models.Dbtablepersons)
|
c.BindJSON(&dbperson)
|
if dbperson.TableId == "" {
|
// 底库id不存在
|
c.JSON(401, "TableId 不存在")
|
}
|
result := addDbPerson(dbperson)
|
if result["success"].(bool) {
|
//code.Success.Message = "添加底库人员成功"
|
util.ResponseFormat(c, code.Success, result["data"])
|
} else {
|
//code.ServiceInsideError.Message += result["msg"].(string)
|
util.ResponseFormat(c, code.ServiceInsideError, result["data"])
|
}
|
}
|
|
func addDbPerson(dbperson *models.Dbtablepersons) (result map[string]interface{}) {
|
|
personId := uuid.NewV4().String() // 以后替代 依据生成规则
|
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"
|
personbytes, e := json.Marshal(dbperson)
|
if e != nil {
|
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)
|
//c.JSON(200, changeEsRespData(data, "添加人员成功"))
|
result = changeEsRespData(data, "添加成功")
|
return result
|
}
|
|
// @Summary 修改底库人员
|
// @Description 修改底库人员
|
// @Accept json
|
// @Produce json
|
// @Tags dbperson 底库人员
|
// @Param person body models.Dbtablepersons true "底库人员数据"
|
// @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}"
|
// @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}"
|
// @Router /data/api-v/dbperson/updateDbPerson [POST]
|
func (dbc DbPersonController) UpdateDbPerson(c *gin.Context) {
|
var dbperson models.Dbtablepersons
|
c.BindJSON(&dbperson)
|
personid := dbperson.Id
|
if personid == "" {
|
util.ResponseFormat(c, code.RequestParamError, nil)
|
return
|
}
|
dbperson.PriUpdate()
|
url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
|
"/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + personid + "/_update?refresh=wait_for"
|
dbTableByte, err := json.Marshal(dbperson)
|
if err != nil {
|
log.Fatalf("Json marshaling failed:%s", err)
|
}
|
//logger.Debugf("%s\n", dbTableByte)
|
params := "{\"doc\":" + string(dbTableByte) + "}"
|
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 = "修改底库人员成功"
|
util.ResponseFormat(c, code.Success, result["data"])
|
} else {
|
//code.ServiceInsideError.Message += result["msg"].(string)
|
util.ResponseFormat(c, code.ServiceInsideError, result["data"])
|
}
|
}
|
|
// @Summary 删除底库人员
|
// @Description 删除库人员
|
// @Accept x-www-form-urlencoded
|
// @Produce json
|
// @Tags dbperson 底库人员
|
// @Param uuid path string true "底库人员id "
|
// @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\":{\"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 = "删除底库人员成功"
|
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
|
// @Produce json
|
// @Tags dbperson 底库人员
|
// @Param uuids body []string true "底库人员ids "
|
// @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)
|
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" // + 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, "删除底库人员成功")
|
} else {
|
//code.ServiceInsideError.Message += result["msg"].(string)
|
util.ResponseFormat(c, code.ServiceInsideError, data["error"])
|
}
|
}
|
|
// @Summary 查询底库人员列表
|
// @Description 查询库人员列表
|
// @Accept json
|
// @Produce json
|
// @Tags dbperson 底库人员
|
// @Param reqMap body map false "{"tableId":"","orderName":"uuid","orderType":"desc","contentValue":"","page":1,"size":8}"
|
// @Success 200 {string} json "{"code":200, "msg":"目录结构数据", "success":true,"data":{}}"
|
// @Failure 500 {string} json "{code:500, msg:"返回错误信息", success:false,data:{}}"
|
// @Router /data/api-v/dbperson/queryDbPersonsByTbId [POST]
|
func (dbc DbPersonController) QueryDbPersonsByTbId(c *gin.Context) {
|
url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
|
"/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_search"
|
reqBody := make(map[string]interface{}, 5)
|
c.BindJSON(&reqBody)
|
tableId := ""
|
if reqBody["tableId"] != nil {
|
tableId = reqBody["tableId"].(string)
|
}
|
orderName := "_id"
|
if reqBody["orderName"] != nil {
|
orderName = reqBody["orderName"].(string)
|
} // 列名
|
orderType := "desc"
|
if reqBody["orderType"] != nil {
|
orderType = reqBody["orderType"].(string)
|
} // 列类型
|
contentValue := ""
|
if reqBody["contentValue"] != nil {
|
contentValue = reqBody["contentValue"].(string)
|
} //输入框内容
|
page := 1
|
if reqBody["page"] != nil {
|
page = int(reqBody["page"].(float64))
|
} // 页码
|
size := 8
|
if reqBody["size"] != nil {
|
size = int(reqBody["size"].(float64))
|
} // 条数
|
from := (page - 1) * size
|
syncTerm := ""
|
contentParam := ""
|
if tableId == "all" || tableId == "" {
|
// / 所有人员
|
} else {
|
syncTerm = "{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 底库人员
|
}
|
if contentValue != "" {
|
contentParam = ",\"must\":[{\"multi_match\":{\"query\":\"" + contentValue + "\",\"type\":\"best_fields\"," +
|
"\"fields\":[\"personName\",\"sex\",\"idCard\",\"phoneNum\"],\"tie_breaker\":0.3}}]"
|
}
|
|
if orderType == "desc" {
|
orderType = "desc"
|
} else {
|
orderType = "asc"
|
}
|
|
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)
|
}
|
|
// @Summary 查询底库人员列表
|
// @Description 查询库人员列表
|
// @Accept json
|
// @Produce json
|
// @Tags dbperson 底库人员
|
// @Param reqMap body map false "{"tableId":"","orderName":"uuid","orderType":"desc","contentValue":"","page":1,"size":8}"
|
// @Success 200 {string} json "{"code":200, "msg":"目录结构数据", "success":true,"data":{}}"
|
// @Failure 500 {string} json "{code:500, msg:"返回错误信息", success:false,data:{}}"
|
// @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
|
reqBody := make(map[string]interface{}, 5)
|
c.BindJSON(&reqBody)
|
tableId := ""
|
if reqBody["tableId"] != nil {
|
tableId = reqBody["tableId"].(string)
|
}
|
orderName := "_id"
|
if reqBody["orderName"] != nil {
|
orderName = reqBody["orderName"].(string)
|
} // 列名
|
orderType := "desc"
|
if reqBody["orderType"] != nil {
|
orderType = reqBody["orderType"].(string)
|
} // 列类型
|
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) // 图片路径有问题
|
return
|
}
|
//输入框内容
|
page := 1
|
if reqBody["page"] != nil {
|
page = int(reqBody["page"].(float64))
|
} // 页码
|
size := 8
|
if reqBody["size"] != nil {
|
size = int(reqBody["size"].(float64))
|
} // 条数
|
from := (page - 1) * size
|
syncTerm := ""
|
contentParam := ""
|
if tableId == "all" || tableId == "" {
|
// / 所有人员
|
} else {
|
syncTerm = "{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 底库人员
|
}
|
if orderType == "desc" {
|
orderType = "desc"
|
} else {
|
orderType = "asc"
|
}
|
|
//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
|
/*fileName := picUrl // picIp 定义在 fileController weedfs 文件服务器 访问 路径 前缀
|
detect := gorun.GetSimpleFaceDetect(fileName)
|
if len(detect) != 1 {
|
util.ResponseFormat(c,code.TooManyFeatureFindError,"图片特征值过多")
|
return
|
}else {
|
featByte = detect[0]["feature"].([]byte)
|
}*/ // linux
|
}
|
to := page * size
|
datalist := sourceCompare(data["datalist"].([]interface{}), false, featByte, threshold)
|
total := len(datalist)
|
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)
|
}
|