Browse Source

延时报警

huangyan 4 days ago
parent
commit
e7215889b9

+ 112 - 0
Nats/Nats.go

@@ -636,4 +636,116 @@ func NatsInit() {
 		return
 
 	})
+	//通过sn获取设备最新开始监控时间以及结束时间
+	_, _ = lib.Nats.QueueSubscribe("Read_DeviceTask_List_By_Condition", "Read_DeviceTask_List_By_Condition", func(m *nats.Msg) {
+		logs.Debug(fmt.Sprintf("Read_DeviceTask_List_By_Condition message: %s\n", string(m.Data)))
+		type T_R struct {
+			Code int16             `xml:"Code"`
+			Msg  string            `xml:"Msg"`
+			Data Device.DeviceTask `xml:"Data"`
+		}
+		type T_Req struct {
+			T_sn string `xml:"T_sn"`
+		}
+		var t_R T_R
+		var t_Req T_Req
+		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
+		}
+		l, err := Device.Read_DeviceTask_List_By_Condition(t_Req.T_sn)
+		if err == nil && l.Id != 0 {
+			t_R.Code = 200
+			t_R.Msg = "ok"
+			t_R.Data = l
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+		t_R.Code = 202
+		t_R.Msg = "查询失败当前数据为空"
+		b, _ := msgpack.Marshal(&t_R)
+		_ = lib.Nats.Publish(m.Reply, b)
+		return
+	})
+	// 发布-订阅 通过sn_id 查询最新设备数据
+	_, _ = lib.Nats.QueueSubscribe("Read_New_DeviceData", "Read_New_DeviceData", func(m *nats.Msg) {
+		logs.Debug(fmt.Sprintf("Read_New_DeviceData message: %s\n", string(m.Data)))
+		type T_R struct {
+			Code int16              `xml:"Code"`
+			Msg  string             `xml:"Msg"`
+			Data Device.DeviceData_ `xml:"Data"`
+		}
+		type T_Req struct {
+			T_sn string `xml:"T_sn"`
+			T_id int    `xml:"T_id"`
+		}
+		var t_R T_R
+		var t_Req T_Req
+		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
+		}
+		r := Device.Read_DeviceData(t_Req.T_sn, t_Req.T_id)
+		if r.T_id != 0 {
+			t_R.Code = 200
+			t_R.Msg = "ok"
+			t_R.Data = r
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+		t_R.Code = 202
+		t_R.Msg = "查询失败当前数据为空"
+		b, _ := msgpack.Marshal(&t_R)
+		_ = lib.Nats.Publish(m.Reply, b)
+		return
+	})
+	// 查询大于开始时间的所有数据
+	_, _ = lib.Nats.QueueSubscribe("Read_Start_Time_DeviceData", "Read_Start_Time_DeviceData", func(m *nats.Msg) {
+		logs.Debug(fmt.Sprintf("Read_Start_Time_DeviceData message: %s\n", string(m.Data)))
+		type T_R struct {
+			Code int16                `xml:"Code"`
+			Msg  string               `xml:"Msg"`
+			Data []Device.DeviceData_ `xml:"Data"`
+		}
+		type T_Req struct {
+			T_sn      string `xml:"T_sn"`
+			T_id      int    `xml:"T_id"`
+			StartTime string `xml:"StartTime"`
+			EndTime   string `xml:"EndTime"`
+		}
+		var t_R T_R
+		var t_Req T_Req
+		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
+		}
+		t, count := Device.Read_DeviceData_Start_Time(t_Req.T_sn, t_Req.T_id, t_Req.StartTime, t_Req.EndTime)
+		if count > 0 {
+			t_R.Code = 200
+			t_R.Msg = "ok"
+			t_R.Data = t
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+		t_R.Code = 202
+		t_R.Msg = "查询失败当前数据为空"
+		b, _ := msgpack.Marshal(&t_R)
+		_ = lib.Nats.Publish(m.Reply, b)
+		return
+	})
 }

+ 4 - 3
conf/app.conf

@@ -8,6 +8,7 @@ Version = "/v3"
 
 # # Nats
 NatsServer_Url = "203.34.49.130:4222"
+; NatsServer_Url = "127.0.0.1:4222"
 
 # Mysql
 MysqlServer_UrlPort = "203.34.49.130:3306"
@@ -21,7 +22,7 @@ MysqlServer_Debug = true
 
 # Redis
 Redis_address = "203.34.49.130:6379"
-Redis_password = "redis_GGRi8f"
+Redis_password = "redis_JJ56d5"
 Redis_dbNum = "1"
 
 
@@ -35,9 +36,9 @@ Qiniu_Url = "https://coldoss.coldbaozhida.com/"
 Panel_url = "http://127.0.0.1:6204/Cold_Panel"
 
 # 不验证登录的接口
-FilterExcludeURL = /Login_verification,/Data/List,/WxPay/Notify,/Data/Company_key_Device_Sensor_List,/docking/Real_Data,/docking/Note_Data,/Company/Transport/List,/DeviceSensor/List_BySN
+FilterExcludeURL = /Login_verification,/Data/List,/WxPay/Notify,/Data/Company_key_Device_Sensor_List,/docking/Real_Data,/docking/Note_Data,/Company/Transport/List,/DeviceSensor/List_BySN,/Data/GetNewLocus
 # 只验证登录不验证权限的接口
-FilterOnlyLoginCheckURL = /Menu/List,/User/Info,/User/Home,/User/Post,/UpFileToken,/User/WxQRCode,/Company/Get,/DataSource,/Company/Bill_Excel,/WarningSend/List,/WxPay/Get_QRCode,/WxPay/GetOrderState,/WarningHandle/List,/DeviceWarning/List_Count
+FilterOnlyLoginCheckURL = /Menu/List,/User/Info,/User/Home,/User/Post,/UpFileToken,/User/WxQRCode,/Company/Get,/DataSource,/Company/Bill_Excel,/WarningSend/List,/WxPay/Get_QRCode,/WxPay/GetOrderState,/WarningHandle/List,/DeviceWarning/List_Count,/Bulletin/GetBulletinById,/Bulletin/IsReadBulletin,/Bulletin/GetBulletinList
 
 
 MqttIds = tmqttjxit

+ 122 - 0
controllers/Data.go

@@ -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)
+	}
+}

+ 3 - 0
controllers/Device.go

@@ -576,6 +576,9 @@ func (c *DeviceController) Device_Parameter_Pu() {
 	if v, err := c.GetInt("T_snum"); err == nil {
 		DeviceParameter.T_snum = v
 	}
+	if v, err := c.GetInt("T_alarm"); err == nil {
+		DeviceParameter.T_alarm = v
+	}
 	if v := c.GetString("T_btname"); len(v) > 0 {
 		DeviceParameter.T_btname = v
 	}

+ 3 - 1
controllers/Login.go

@@ -4,6 +4,7 @@ import (
 	"Cold_Api/controllers/lib"
 	"Cold_Api/models/Account"
 	"Cold_Api/models/System"
+	"fmt"
 	beego "github.com/beego/beego/v2/server/web"
 	"github.com/mssola/user_agent"
 	"time"
@@ -41,11 +42,12 @@ func (c *AdminController) Login_verification() {
 
 	println("Login_verification", Admin_user, Admin_pass)
 	err, admin_r := Account.Read_AdminLogin_verification(Admin_user, Admin_pass)
-
+	fmt.Println("Login_verification", err, admin_r)
 	if err != nil {
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "账号密码错误!"}
 	} else {
 		User_tokey := Account.Add_Tokey_Set(admin_r.T_uuid)
+		//fmt.Println("User_tokey:登录", User_tokey)
 		c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60)
 		c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey}
 

+ 49 - 0
controllers/lib/wgs84ToGcj02.go

@@ -0,0 +1,49 @@
+package lib
+
+import "math"
+
+const (
+	a  = 6378245.0          // 长半轴
+	ee = 0.0066934216229659 // 扁率
+)
+
+// 判断是否在中国范围外
+func outOfChina(lng, lat float64) bool {
+	return !(lng > 72.004 && lng < 137.8347 && lat > 0.8293 && lat < 55.8271)
+}
+
+// 计算纬度偏差
+func transformLat(x, y float64) float64 {
+	ret := -100.0 + 2.0*x + 3.0*y + 0.2*y*y + 0.1*x*y + 0.2*math.Sqrt(math.Abs(x))
+	ret += (20.0*math.Sin(6.0*x*(math.Pi)) + 20.0*math.Sin(2.0*x*(math.Pi))) * 2.0 / 3.0
+	ret += (20.0*math.Sin(y*(math.Pi)) + 40.0*math.Sin(y/3.0*(math.Pi))) * 2.0 / 3.0
+	ret += (160.0*math.Sin(y/12.0*(math.Pi)) + 320.0*math.Sin(y/30.0*(math.Pi))) * 2.0 / 3.0
+	return ret
+}
+
+// 计算经度偏差
+func transformLon(x, y float64) float64 {
+	ret := 300.0 + x + 2.0*y + 0.1*x*x + 0.1*x*y + 0.1*math.Sqrt(math.Abs(x))
+	ret += (20.0*math.Sin(6.0*x*(math.Pi)) + 20.0*math.Sin(2.0*x*(math.Pi))) * 2.0 / 3.0
+	ret += (20.0*math.Sin(x*(math.Pi)) + 40.0*math.Sin(x/3.0*(math.Pi))) * 2.0 / 3.0
+	ret += (150.0*math.Sin(x/12.0*(math.Pi)) + 300.0*math.Sin(x/30.0*(math.Pi))) * 2.0 / 3.0
+	return ret
+}
+
+// WGS-84 转 GCJ-02
+func Wgs84ToGcj02(lng, lat float64) (float64, float64) {
+	if outOfChina(lng, lat) {
+		return lng, lat
+	}
+	dLat := transformLat(lng-105.0, lat-35.0)
+	dLng := transformLon(lng-105.0, lat-35.0)
+	radLat := lat / 180.0 * math.Pi
+	magic := math.Sin(radLat)
+	magic = 1 - ee*magic*magic
+	sqrtMagic := math.Sqrt(magic)
+	dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * math.Pi)
+	dLng = (dLng * 180.0) / (a / sqrtMagic * math.Cos(radLat) * math.Pi)
+	mgLat := lat + dLat
+	mgLng := lng + dLng
+	return mgLng, mgLat
+}

+ 1 - 0
go.mod

@@ -26,6 +26,7 @@ require (
 	github.com/beorn7/perks v1.0.1 // indirect
 	github.com/cespare/xxhash/v2 v2.1.2 // indirect
 	github.com/golang/protobuf v1.5.2 // indirect
+	github.com/gorilla/websocket v1.5.3 // indirect
 	github.com/hashicorp/golang-lru v0.5.4 // indirect
 	github.com/jinzhu/inflection v1.0.0 // indirect
 	github.com/jinzhu/now v1.1.5 // indirect

+ 2 - 0
go.sum

@@ -165,6 +165,8 @@ github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
 github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
 github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
+github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
+github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
 github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
 github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
 github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=

+ 1 - 0
models/Account/Tokey.go

@@ -107,6 +107,7 @@ func Redis_Tokey_T_pid_Get(Tokey string) (int, bool) {
 // 登录验证
 func Verification(GetCookie string, GetString string) (bool, Admin) {
 	// 自适应 参数
+	//log.Println("登录验证Verification", GetCookie, GetString)
 	User_tokey := GetCookie
 	if len(User_tokey) == 0 {
 		User_tokey = GetString

+ 77 - 1
models/Device/DeviceData.go

@@ -4,6 +4,7 @@ import (
 	"Cold_Api/conf"
 	"Cold_Api/controllers/lib"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"github.com/astaxie/beego/cache"
 	_ "github.com/astaxie/beego/cache/redis"
@@ -655,7 +656,6 @@ func Read_DeviceData(T_sn string, T_id int) (t DeviceData_) {
 	if t, is := RedisDeviceData_Get(key); is {
 		return t
 	}
-
 	o := orm.NewOrm()
 	var maps []DeviceData_
 	sql := "SELECT t_id,t_sp,t_t,t_rh,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time,t_time AS t_time1 FROM z_device_data_" + T_sn + " WHERE" + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time1 DESC LIMIT 0,1"
@@ -770,3 +770,79 @@ func Read_DeviceData_By_Time(T_sn string, T_id int, Time string) (t DeviceData_)
 
 	return maps
 }
+func Read_DeviceData_Start_Time(T_sn string, T_id int, StartTime, EndTime string) (t []DeviceData_, count int64) {
+	o := orm.NewOrm()
+	var maps []DeviceData_
+	var sql string
+	if len(StartTime) > 0 && len(EndTime) > 0 {
+		sql = "SELECT t_id,t_sp,t_t,t_rh,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time,t_time AS t_time1 FROM z_device_data_" + T_sn + " WHERE" + " t_id = " + strconv.Itoa(T_id) + " AND t_time >= '" + StartTime + "'" + " AND t_time <= '" + EndTime + "'" + " ORDER BY t_time1 DESC"
+	} else if len(StartTime) > 0 && len(EndTime) == 0 {
+		sql = "SELECT t_id,t_sp,t_t,t_rh,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time,t_time AS t_time1 FROM z_device_data_" + T_sn + " WHERE" + " t_id = " + strconv.Itoa(T_id) + " AND t_time >= '" + StartTime + "'" + " ORDER BY t_time1 DESC"
+	}
+	logs.Debug(sql)
+	count, err := o.Raw(sql).QueryRows(&maps)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return t, 0
+	}
+	return maps, count
+}
+
+// 获取最新轨迹信息
+func GetNewLocus(T_sn string, T_id int, list *[]DeviceData_) error {
+	task, err := Read_DeviceTask_List_By_Condition(T_sn)
+	if err != nil {
+		logs.Error(lib.FuncName(), err.Error())
+		return errors.New("设备未开启监控")
+	}
+	// 当最新设备状态为1时,证明设备正在启动中,查询大于开始时间的所有轨迹,设备状态为2时,查询开始时间到结束时间的轨迹
+	if task.T_State == 1 {
+		deviceData, count := Read_DeviceData_Start_Time(T_sn, T_id, task.T_Ut_start.Format("2006-01-02 15:04:05"), "")
+		if count >= 0 {
+			*list = appendUniqueDeviceData(*list, deviceData)
+		} else {
+			logs.Error(lib.FuncName(), err)
+			return errors.New("获取设备轨迹失败")
+		}
+
+	} else if task.T_State == 2 {
+		deviceData, count := Read_DeviceData_Start_Time(T_sn, T_id, task.T_Ut_start.Format("2006-01-02 15:04:05"), task.T_Ut_end.Format("2006-01-02 15:04:05"))
+		if count >= 0 {
+			*list = appendUniqueDeviceData(*list, deviceData)
+		} else {
+			logs.Error(lib.FuncName(), err)
+			return errors.New("获取设备轨迹失败")
+		}
+	}
+	return nil
+}
+
+// 去重并追加设备数据
+func appendUniqueDeviceData(list []DeviceData_, newData []DeviceData_) []DeviceData_ {
+	uniqueMap := make(map[time.Time]bool)
+	for _, d := range list {
+		uniqueMap[d.T_time] = true
+	}
+	for _, d := range newData {
+		if !uniqueMap[d.T_time] {
+			split := strings.Split(d.T_site, ",")
+			defer func() {
+				if r := recover(); r != nil {
+					fmt.Println("数组下标越界:", r)
+				}
+			}()
+			Lng := split[0]
+			Lat := split[1]
+			Lngs, _ := strconv.ParseFloat(Lng, 64)
+			Lats, _ := strconv.ParseFloat(Lat, 64)
+			mLng, mLat := lib.Wgs84ToGcj02(Lngs, Lats)
+			d.T_site = fmt.Sprintf("%v,%v", mLng, mLat)
+			list = append(list, d)
+		}
+	}
+	//排序
+	sort.Slice(list, func(i, j int) bool {
+		return list[i].T_time.After(list[j].T_time)
+	})
+	return list
+}

+ 1 - 0
models/Device/DeviceParameter.go

@@ -32,6 +32,7 @@ type DeviceParameter struct {
 	T_btname string `orm:"size(256);null"` //蓝牙打印机名称
 	T_btsid  int    `orm:"size(256);null"` //打印机服务号
 	T_btchar int    `orm:"size(256);null"` //蓝牙特征码
+	T_alarm  int    `orm:"size(256);null"` //内部
 
 	T_uuid      string `orm:"size(256);null"`      // 处理 人员
 	T_Msid      int64  `orm:"size(50);default(0)"` // 消息识别ID

+ 10 - 0
models/Device/DeviceTask.go

@@ -2,6 +2,7 @@ package Device
 
 import (
 	"Cold_Api/controllers/lib"
+	"fmt"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	"github.com/beego/beego/v2/core/logs"
@@ -130,3 +131,12 @@ func Read_DeviceTask_List(T_sn string, Time_start string, Time_end string, page
 
 	return
 }
+
+// Read_DeviceTask_List_By_Condition 通过sn获取最新的一条状态
+func Read_DeviceTask_List_By_Condition(T_sn string) (deviceTask DeviceTask, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf("select ID,t_sn,t__ut_start,t__ut_end,t__ut,t__state from device_task where t_sn='%s' order by id desc limit 1", T_sn)
+	err = o.Raw(sql).QueryRow(&deviceTask)
+	fmt.Println(deviceTask)
+	return deviceTask, err
+}

+ 4 - 0
routers/Data.go

@@ -10,6 +10,10 @@ func init() {
 	ns := beego.NewNamespace(conf.Version,
 		beego.NSNamespace("/Data",
 			beego.NSBefore(T_pidFilter),
+			//数据实时轨迹
+			//beego.NSRouter("/GetNewLocus", &controllers.DataController{}, "*:GetNewLocus"), // 获取实时轨迹
+			beego.NSRouter("/GetNewLocus", &controllers.DataController{}, "*:GetNewLocus_"),
+			// 获取实时轨迹
 			beego.NSRouter("/Device_Sensor", &controllers.DataController{}, "*:Device_Sensor_Get"),                                 // 获取传感器
 			beego.NSRouter("/Device_Sensor_Data_Real", &controllers.DataController{}, "*:Device_Sensor_Data_Real"),                 // 获取传感器
 			beego.NSRouter("/Device_Sensor_List", &controllers.DataController{}, "*:Device_Sensor_List"),                           // 传感器列表

+ 4 - 0
routers/filter.go

@@ -4,6 +4,7 @@ import (
 	"Cold_Api/conf"
 	"Cold_Api/controllers/lib"
 	"Cold_Api/models/Account"
+	"fmt"
 	"github.com/beego/beego/v2/core/logs"
 	"github.com/beego/beego/v2/server/web/context"
 	"strings"
@@ -32,6 +33,7 @@ func init() {
 			}
 		}
 	}
+	//fmt.Println("初始化map", filterExcludeURLMap)
 	checkLoginUrl := conf.FilterOnlyLoginCheckURL
 	if len(checkLoginUrl) > 0 {
 		checkLoginUrlSlice := strings.Split(checkLoginUrl, ",")
@@ -48,6 +50,7 @@ func RBACFilter(ctx *context.Context) {
 	if _, ok := filterExcludeURLMap[ctx.Request.URL.Path]; ok {
 		return
 	}
+	fmt.Println("进入拦截===========", ctx.Request.URL.Path)
 	b_, admin_r := Account.Verification(ctx.GetCookie("User_tokey"), ctx.Input.Query("User_tokey"))
 	if !b_ {
 		ctx.Output.JSON(lib.JSONS{Code: 201, Msg: "请重新登陆!"}, true, false)
@@ -106,6 +109,7 @@ func T_pidFilter(ctx *context.Context) {
 	}
 	T_pid := admin_r.T_pid
 	if T_pid == 0 {
+		logs.Debug("获取缓存pid为:", T_pid)
 		T_pid, _ = Account.Redis_Tokey_T_pid_Get(User_tokey)
 	}
 	// fixme 如果逻辑正常,不需要做pid验证