|
@@ -2571,60 +2571,91 @@ func (c *DataController) Docking_Note_Data() {
|
|
|
}
|
|
|
|
|
|
// 保温箱实时轨迹
|
|
|
-//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)
|
|
|
-//}
|
|
|
-//}
|
|
|
+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)
|
|
|
+
|
|
|
+ conn := true
|
|
|
+ // 监听客户端断开连接
|
|
|
+ notify := c.Ctx.ResponseWriter.CloseNotify()
|
|
|
+
|
|
|
+ type Response struct {
|
|
|
+ RequestId string `protobuf:"bytes,1,opt,name=requestId,proto3" json:"requestId,omitempty"`
|
|
|
+ Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
|
|
|
+ Msg string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
|
|
|
+ SN string `protobuf:"bytes,3,opt,name=sn,proto3" json:"sn,omitempty"`
|
|
|
+ CoolerName string `protobuf:"bytes,4,opt,name=CoolerName,proto3" json:"CoolerName,omitempty"`
|
|
|
+ Data []Device.DeviceData_R2 `json:"data"`
|
|
|
+ }
|
|
|
+ var response Response
|
|
|
+ list := make([]Device.DeviceData_, 0)
|
|
|
+ device, err := Device.Read_Device_ByT_sn(sn)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), "设备不存在: %v", err)
|
|
|
+ response.Code = 500
|
|
|
+ response.Msg = "设备不存在"
|
|
|
+ response.Data = nil
|
|
|
+ response.SN = sn
|
|
|
+ response.CoolerName = ""
|
|
|
+ res, _ := json.Marshal(&response)
|
|
|
+ fmt.Fprintf(c.Ctx.ResponseWriter, "data: %s\n\n", string(res))
|
|
|
+ c.Ctx.ResponseWriter.Flush()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for conn {
|
|
|
+ select {
|
|
|
+ case <-notify:
|
|
|
+ fmt.Println("断开连接")
|
|
|
+ conn = false
|
|
|
+ return
|
|
|
+ default:
|
|
|
+ err := Device.GetNewLocus(sn, tid, &list)
|
|
|
+ if err != nil {
|
|
|
+ response.Code = 500
|
|
|
+ response.Msg = err.Error()
|
|
|
+ response.Data = nil
|
|
|
+ response.SN = sn
|
|
|
+ response.CoolerName = device.T_devName
|
|
|
+ res, _ := json.Marshal(&response)
|
|
|
+ fmt.Fprintf(c.Ctx.ResponseWriter, "data: %s\n\n", string(res))
|
|
|
+ c.Ctx.ResponseWriter.Flush()
|
|
|
+ time.Sleep(20 * time.Second)
|
|
|
+ logs.Error(lib.FuncName(), "获取轨迹失败: %v", err)
|
|
|
+ } else {
|
|
|
+ updatedLists := make([]Device.DeviceData_R2, 0)
|
|
|
+ for i := range list {
|
|
|
+ updatedLists = append(updatedLists, Device.DeviceData_R2{
|
|
|
+ DeviceData_: Device.DeviceData_{
|
|
|
+ T_id: list[i].T_id,
|
|
|
+ T_rh: list[i].T_rh,
|
|
|
+ T_site: list[i].T_site,
|
|
|
+ T_sp: list[i].T_sp,
|
|
|
+ T_time: list[i].T_time,
|
|
|
+ T_t: list[i].T_t,
|
|
|
+ },
|
|
|
+ Sn: sn,
|
|
|
+ T_name: device.T_devName,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ response.Code = 200
|
|
|
+ response.Msg = "查询成功"
|
|
|
+ response.Data = updatedLists
|
|
|
+ response.SN = sn
|
|
|
+ response.CoolerName = device.T_devName
|
|
|
+ res, _ := json.Marshal(&response)
|
|
|
+ fmt.Fprintf(c.Ctx.ResponseWriter, "data: %s\n\n", string(res))
|
|
|
+ c.Ctx.ResponseWriter.Flush()
|
|
|
+ time.Sleep(10 * time.Second)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
var upgrader = websocket.Upgrader{
|
|
|
ReadBufferSize: 1024,
|