|
@@ -7,13 +7,17 @@ import (
|
|
|
"Cold_Api/models/Account"
|
|
|
"Cold_Api/models/Device"
|
|
|
"encoding/base64"
|
|
|
+ "encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"github.com/beego/beego/v2/core/logs"
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
|
+ "github.com/gorilla/websocket"
|
|
|
"github.com/signintech/gopdf"
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
+ "log"
|
|
|
"math"
|
|
|
+ "net/http"
|
|
|
"os"
|
|
|
"strconv"
|
|
|
"strings"
|
|
@@ -2291,3 +2295,121 @@ func (c *DataController) Docking_Note_Data() {
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// 保温箱实时轨迹
|
|
|
+//func (c *DataController) GetNewLocus() {
|
|
|
+// // 设置响应头
|
|
|
+// c.Ctx.ResponseWriter.Header().Set("Content-Type", "text/event-stream")
|
|
|
+// c.Ctx.ResponseWriter.Header().Set("Cache-Control", "no-cache")
|
|
|
+// c.Ctx.ResponseWriter.Header().Set("Connection", "keep-alive")
|
|
|
+
|
|
|
+//sn := c.GetString("sn")
|
|
|
+//t_id := c.GetString("t_id")
|
|
|
+//tid, _ := strconv.Atoi(t_id)
|
|
|
+//
|
|
|
+//var list []Device.DeviceData_
|
|
|
+//type Response struct {
|
|
|
+// Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
|
|
|
+// Msg string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
|
|
|
+// Data []Device.DeviceData_ `json:"data"`
|
|
|
+//}
|
|
|
+//fmt.Println("日志输出:====================================================================")
|
|
|
+//for {
|
|
|
+// err := Device.GetNewLocus(sn, tid, &list)
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "获取轨迹失败s: %v, sn: %s, tid: %d", err, sn, tid)
|
|
|
+// response := Response{
|
|
|
+// Code: 500,
|
|
|
+// Msg: "获取轨迹失败",
|
|
|
+// Data: nil,
|
|
|
+// }
|
|
|
+// data, _ := json.Marshal(response)
|
|
|
+// _, err := c.Ctx.ResponseWriter.Write(data)
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "写入响应出错: %v", err)
|
|
|
+// }
|
|
|
+// break
|
|
|
+// }
|
|
|
+//
|
|
|
+// response := Response{
|
|
|
+// Code: 200,
|
|
|
+// Msg: "ok!",
|
|
|
+// Data: list,
|
|
|
+// }
|
|
|
+// data, _ := json.Marshal(response)
|
|
|
+// _, err = c.Ctx.ResponseWriter.Write(data)
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "写入响应出错: %v", err)
|
|
|
+// break
|
|
|
+// }
|
|
|
+// _, err := c.Ctx.ResponseWriter.Write(append(append([]byte("data: "), []byte("hello world")...), []byte("\n\n")...))
|
|
|
+// if err != nil {
|
|
|
+// logs.Error(lib.FuncName(), "写入响应出错: %v", err)
|
|
|
+// break
|
|
|
+// }
|
|
|
+//c.Ctx.ResponseWriter.Flush()
|
|
|
+//time.Sleep(10 * time.Second)
|
|
|
+//}
|
|
|
+//}
|
|
|
+
|
|
|
+var upgrader = websocket.Upgrader{
|
|
|
+ ReadBufferSize: 1024,
|
|
|
+ WriteBufferSize: 1024,
|
|
|
+ CheckOrigin: func(r *http.Request) bool {
|
|
|
+ return true
|
|
|
+ },
|
|
|
+}
|
|
|
+
|
|
|
+func (c *DataController) GetNewLocus_() {
|
|
|
+ ws, err := upgrader.Upgrade(c.Ctx.ResponseWriter, c.Ctx.Request, nil)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("Failed to set websocket upgrade:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer ws.Close()
|
|
|
+ type Responses struct {
|
|
|
+ Sn string `json:"sn"`
|
|
|
+ Tid int `json:"tid"`
|
|
|
+ }
|
|
|
+ var list []Device.DeviceData_
|
|
|
+ type Response struct {
|
|
|
+ Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
|
|
|
+ Msg string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
|
|
|
+ Data []Device.DeviceData_ `json:"data"`
|
|
|
+ }
|
|
|
+ _, message, err := ws.ReadMessage()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), "读取参数失败: %v", err)
|
|
|
+ }
|
|
|
+ log.Printf("Received: %s", message)
|
|
|
+ var r Responses
|
|
|
+ //var rs Response
|
|
|
+ err = json.Unmarshal(message, &r)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), "解析参数失败: %v", err)
|
|
|
+ ws.WriteMessage(websocket.TextMessage, []byte("参数解析失败"))
|
|
|
+ }
|
|
|
+ for {
|
|
|
+ err = Device.GetNewLocus(r.Sn, r.Tid, &list)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), "获取轨迹失败s: %v, sn: %s, tid: %d", err, r.Sn, r.Tid)
|
|
|
+ response := Response{
|
|
|
+ Code: 500,
|
|
|
+ Msg: "获取轨迹失败",
|
|
|
+ Data: nil,
|
|
|
+ }
|
|
|
+ data, _ := json.Marshal(response)
|
|
|
+ ws.WriteMessage(websocket.TextMessage, data)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ response := Response{
|
|
|
+ Code: 200,
|
|
|
+ Msg: "ok!",
|
|
|
+ Data: list,
|
|
|
+ }
|
|
|
+ data, _ := json.Marshal(response)
|
|
|
+ ws.WriteMessage(websocket.TextMessage, data)
|
|
|
+ // 回复消息
|
|
|
+ time.Sleep(10 * time.Second)
|
|
|
+ }
|
|
|
+}
|