reboot_command.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. "strconv"
  11. )
  12. type RebootDeviceInfo struct {
  13. }
  14. type RebootDeviceCmd struct {
  15. Operator string `json:"operator"`
  16. MessageId string `json:"messageId"`
  17. Info RebootDeviceInfo `json:"info"`
  18. }
  19. type RebootDeviceCmdResInfo struct {
  20. Result string `json:"result"`
  21. FaceId string `json:"facesluiceId"`
  22. Detail string `json:"detail"`
  23. }
  24. type RebootDeviceCmdRes struct {
  25. Operator string `json:"operator"`
  26. MessageId string `json:"messageId"`
  27. Info RebootDeviceCmdResInfo `json:"info"`
  28. }
  29. func RebootCommandHandle(command string, res string) {
  30. fmt.Printf("重启响应处理:command:%s\n res:%s\n", command, res)
  31. cmdRes := RebootDeviceCmdRes{}
  32. json.Unmarshal([]byte(res), &cmdRes)
  33. result := 2
  34. if cmdRes.Info.Result == "ok" {
  35. result = 1
  36. }
  37. cmdId, _ := strconv.ParseInt(cmdRes.MessageId, 10, 64)
  38. mreq := pb_v1.GateCommandResultRequest{Sn: cmdRes.Info.FaceId, CmdCode: RebootCommand, Content: res, Protocol: GateProtocolSaiboMqttV1, Id: cmdId}
  39. mreq.ResultStatus = int32(result)
  40. mreq.ResultDesc = cmdRes.Info.Detail
  41. _, err := pb.Device.GateCommandResult(context.Background(), &mreq)
  42. if err != nil {
  43. logger.Error("func",
  44. zap.String("call", "pb.Device.GateCommandResult"),
  45. zap.String("error", err.Error()))
  46. }
  47. }