NatsColdVerify.go 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package NatsServer
  2. import (
  3. "Cold_Api/controllers/lib"
  4. "errors"
  5. "github.com/beego/beego/v2/core/logs"
  6. "github.com/vmihailenco/msgpack/v5"
  7. "time"
  8. )
  9. func Update_Task_BySN(T_sn string, T_CalibrationTime time.Time) error {
  10. type T_Req struct {
  11. T_sn string `xml:"T_sn"`
  12. T_CalibrationTime string `xml:"T_CalibrationTime"`
  13. }
  14. v := T_Req{
  15. T_sn: T_sn,
  16. T_CalibrationTime: T_CalibrationTime.Format("2006-01-02 15:04:05"),
  17. }
  18. logs.Debug("Nats =>", lib.FuncName(), v)
  19. b, err := msgpack.Marshal(&v)
  20. if err != nil {
  21. return err
  22. }
  23. msg, err := lib.Nats.Request("ColdVerify_Server_Update_Task_BySN", b, 3*time.Second)
  24. if err != nil {
  25. return err
  26. }
  27. type T_R struct {
  28. Code int16 `xml:"Code"`
  29. Msg string `xml:"Msg"`
  30. Data interface{} `xml:"Data"`
  31. }
  32. var t_R T_R
  33. err = msgpack.Unmarshal(msg.Data, &t_R)
  34. if err != nil {
  35. return err
  36. }
  37. if t_R.Code != 200 {
  38. return errors.New(t_R.Msg)
  39. }
  40. return nil
  41. }