| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "basic.com/pubsub/protomsg.git" |
| | | "encoding/json" |
| | | "log" |
| | | "strconv" |
| | | "time" |
| | | "webserver/discovery" |
| | | "webserver/extend/logger" |
| | | |
| | | "github.com/gin-gonic/gin" |
| | |
| | | "webserver/extend/esutil" |
| | | "webserver/extend/util" |
| | | "webserver/models" |
| | | esApi "basic.com/pubsub/esutil.git" |
| | | ) |
| | | |
| | | type DbPersonController struct { |
| | |
| | | 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, "添加成功") |
| | |
| | | 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 删除底库人员 |
| | |
| | | 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 { |
| | |
| | | //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) |
| | |
| | | |
| | | 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) |