person_command.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package mqtt_utils
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "git.getensh.com/common/gopkgs/logger"
  7. "go.uber.org/zap"
  8. "property-mqtt/pb"
  9. pb_v1 "property-mqtt/pb/v1"
  10. )
  11. type PersonInfo struct {
  12. CustomId string `json:"customId"`
  13. Name string `json:"name"`
  14. PersonType int `json:"personType"`
  15. TempCardType int `json:"tempCardType"`
  16. PicURI string `json:"picURI"`
  17. }
  18. type EditPersonsNew struct {
  19. Operator string `json:"operator"`
  20. MessageId string `json:"messageId"`
  21. DataBegin string `json:"DataBegin"`
  22. DataEnd string `json:"DataEnd"`
  23. PersonNum int `json:"PersonNum"`
  24. Info []PersonInfo `json:"info"`
  25. }
  26. type SucInfo struct {
  27. CustomId string `json:"customId"`
  28. }
  29. type ErrInfo struct {
  30. CustomId string `json:"customId"`
  31. ErrCode int `json:"errcode"`
  32. }
  33. type EditPersonsNewResInfo struct {
  34. FaceId string `json:"facesluiceId"`
  35. AddErrNum int `json:"AddErrNum"`
  36. AddSucNum int `json:"AddSucNum"`
  37. AddErrInfo []ErrInfo `json:"AddErrInfo"`
  38. AddSucInfo []SucInfo `json:"AddSucInfo"`
  39. Result string `json:"result"`
  40. Detail string `json:"detail"`
  41. }
  42. type EditPersonsNewRes struct {
  43. Operator string `json:"operator"`
  44. MessageId string `json:"messageId"`
  45. Info EditPersonsNewResInfo `json:"info"`
  46. }
  47. // 获取到下发白名单响应后
  48. func DownPersonCommandHandle(command string, res string) {
  49. fmt.Printf("下发白名单响应处理:command:%s\n res:%s\n", command, res)
  50. cmdRes := EditPersonsNewRes{}
  51. DelWait(cmdRes.Info.FaceId)
  52. json.Unmarshal([]byte(res), &cmdRes)
  53. mreq := pb_v1.GateCommandResultRequest{Sn: cmdRes.Info.FaceId, CmdCode: DownCommand, Content: res, Protocol: GateProtocolSaiboMqttV1}
  54. mreq.ResultStatus = 1
  55. if cmdRes.Info.AddErrNum > 0 {
  56. mreq.ResultStatus = 2
  57. mreq.ResultDesc = "添加失败"
  58. s, _ := json.Marshal(cmdRes.Info.AddErrInfo)
  59. logger.Error("mqtt_face_set_white",
  60. zap.String("error", string(s)))
  61. }
  62. if cmdRes.Info.Result != "ok" {
  63. s, _ := json.Marshal(cmdRes)
  64. logger.Error("mqtt_face_set_white err",
  65. zap.String("error", string(s)))
  66. mreq.ResultStatus = 2
  67. mreq.ResultDesc = cmdRes.Info.Detail
  68. }
  69. _, err := pb.Device.GateCommandResult(context.Background(), &mreq)
  70. if err != nil {
  71. logger.Error("func",
  72. zap.String("call", "pb.Device.GateCommandResult"),
  73. zap.String("error", err.Error()))
  74. }
  75. }