|
@@ -3,13 +3,13 @@ package Nats
|
|
import (
|
|
import (
|
|
"Cold_Api/conf"
|
|
"Cold_Api/conf"
|
|
"Cold_Api/controllers/lib"
|
|
"Cold_Api/controllers/lib"
|
|
- "github.com/beego/beego/v2/core/logs"
|
|
|
|
"Cold_Api/models/Account"
|
|
"Cold_Api/models/Account"
|
|
"Cold_Api/models/Device"
|
|
"Cold_Api/models/Device"
|
|
"Cold_Api/models/System"
|
|
"Cold_Api/models/System"
|
|
"encoding/xml"
|
|
"encoding/xml"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/astaxie/beego/cache"
|
|
"github.com/astaxie/beego/cache"
|
|
|
|
+ "github.com/beego/beego/v2/core/logs"
|
|
"github.com/nats-io/nats.go"
|
|
"github.com/nats-io/nats.go"
|
|
"github.com/vmihailenco/msgpack/v5"
|
|
"github.com/vmihailenco/msgpack/v5"
|
|
"strconv"
|
|
"strconv"
|
|
@@ -458,4 +458,40 @@ func NatsInit() {
|
|
b, _ := msgpack.Marshal(&t_R)
|
|
b, _ := msgpack.Marshal(&t_R)
|
|
_ = lib.Nats.Publish(m.Reply, b)
|
|
_ = lib.Nats.Publish(m.Reply, b)
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ // 请求-响应 根据时间获取设备数据(单条)
|
|
|
|
+ _, _ = lib.Nats.Subscribe("Cold_ReadDeviceDataBy_T_snid_T_time", func(m *nats.Msg) {
|
|
|
|
+ fmt.Printf("Cold_ReadDeviceDataBy_T_snid_T_time message: %s\n", string(m.Data))
|
|
|
|
+ type T_Req struct {
|
|
|
|
+ T_sn string `xml:"T_sn"`
|
|
|
|
+ T_id int `xml:"T_id"`
|
|
|
|
+ Time string `xml:"Time"`
|
|
|
|
+ }
|
|
|
|
+ type T_R struct {
|
|
|
|
+ Code int16 `xml:"Code"`
|
|
|
|
+ Msg string `xml:"Msg"`
|
|
|
|
+ Data Device.DeviceData_ `xml:"Data"` // 泛型
|
|
|
|
+ }
|
|
|
|
+ var t_Req T_Req
|
|
|
|
+ var t_R T_R
|
|
|
|
+
|
|
|
|
+ err := msgpack.Unmarshal(m.Data, &t_Req)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t_R.Code = 202
|
|
|
|
+ t_R.Msg = "Unmarshal error"
|
|
|
|
+ b, _ := msgpack.Marshal(&t_R)
|
|
|
|
+ _ = lib.Nats.Publish(m.Reply, b)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ deviceData := Device.Read_DeviceData_By_Time(t_Req.T_sn, t_Req.T_id, t_Req.Time)
|
|
|
|
+
|
|
|
|
+ t_R.Code = 200
|
|
|
|
+ t_R.Msg = "ok"
|
|
|
|
+ t_R.Data = deviceData
|
|
|
|
+
|
|
|
|
+ b, _ := msgpack.Marshal(&t_R)
|
|
|
|
+ _ = lib.Nats.Publish(m.Reply, b)
|
|
|
|
+ })
|
|
|
|
+
|
|
}
|
|
}
|