NatsColdApi.go 842 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package nats_server
  2. import (
  3. "cold-logistics/common/nats"
  4. "cold-logistics/conf"
  5. "github.com/vmihailenco/msgpack/v5"
  6. "time"
  7. )
  8. func Cold_CompanyDeviceSensor_List_ByKey(T_sn string) (data []DeviceSensor_R, count int64, err error) {
  9. type T_Req struct {
  10. T_sn string `xml:"T_sn"`
  11. T_key string `xml:"T_key"`
  12. }
  13. t_Req := T_Req{
  14. T_sn: T_sn,
  15. T_key: conf.ExtConfig.Nats.Key,
  16. }
  17. b, _ := msgpack.Marshal(&t_Req)
  18. msg, err := nats.Nats.Request("Cold_CompanyDeviceSensor_List_ByKey", b, 3*time.Second)
  19. if err != nil {
  20. return
  21. }
  22. type T_R struct {
  23. Code int16 `xml:"Code"`
  24. Msg string `xml:"Msg"`
  25. Count int64 `xml:"Count"`
  26. Data []DeviceSensor_R `xml:"Data"` // 泛型
  27. }
  28. var t_R T_R
  29. err = msgpack.Unmarshal(msg.Data, &t_R)
  30. if err != nil {
  31. return
  32. }
  33. return t_R.Data, t_R.Count, nil
  34. }