|
@@ -2,6 +2,7 @@ package controllers
|
|
|
|
|
|
import (
|
|
|
"Cold_Api/Nats/NatsServer"
|
|
|
+ "Cold_Api/conf"
|
|
|
"Cold_Api/controllers/lib"
|
|
|
"Cold_Api/logs"
|
|
|
"Cold_Api/models/Device"
|
|
@@ -59,36 +60,62 @@ func DeviceRealTime() {
|
|
|
time.Sleep(time.Second * 3)
|
|
|
for true {
|
|
|
// 如果能拿到key,10s等待时间还没结束,则不继续往下执行
|
|
|
- if Device.Redis_DeviceRealWait_IsExist("DeviceRealWait10Second") {
|
|
|
+ if Device.Redis_DeviceRealWait_IsExist("DeviceRealWait10Second"+conf.MqttServer_id) {
|
|
|
+ fmt.Println("-----------------------",time.Now())
|
|
|
time.Sleep(time.Second * 1)
|
|
|
continue
|
|
|
}
|
|
|
+
|
|
|
lib.DeviceRealSnMap.Range(func(k, v interface{}) bool {
|
|
|
+
|
|
|
+ logs.Println("=================", k)
|
|
|
sn := strings.Split(k.(string), "|")[0]
|
|
|
mqttid := strings.Split(k.(string), "|")[1]
|
|
|
- num, is := Device.Redis_DeviceReal_Get(sn)
|
|
|
- if !is {
|
|
|
- Device.Redis_DeviceReal_Set(sn, 1)
|
|
|
- } else {
|
|
|
- Device.Redis_DeviceReal_Set(sn, num+1)
|
|
|
- }
|
|
|
- // 每次拿到Map的key后,删除该key,否则会造成死循环
|
|
|
- lib.DeviceRealSnMap.Delete(k)
|
|
|
- // 实时数据请求次数达到180次(30分钟*6次/分钟=180)
|
|
|
- // 更新实时请求为2分钟每次(2分钟*6次/分钟=12)
|
|
|
- if num > 180 && (num-180)%12 != 0 {
|
|
|
- fmt.Println("num:", num)
|
|
|
- return true
|
|
|
- }
|
|
|
|
|
|
- logs.Debug("DeviceRealSnMap:", sn, " num:", num)
|
|
|
- NatsServer.Get_Device_Realtime(sn, mqttid)
|
|
|
+ //num, is := Device.Redis_DeviceReal_Get(sn)
|
|
|
+ //if num >= 3 {
|
|
|
+ // lib.DeviceRealSnMap.Delete(k)
|
|
|
+ // Device.Redis_DeviceReal_DelK(sn)
|
|
|
+ // return true
|
|
|
+ //}
|
|
|
+ //if !is {
|
|
|
+ // Device.Redis_DeviceReal_Set(sn, 1)
|
|
|
+ //} else {
|
|
|
+ // Device.Redis_DeviceReal_Set(sn, num+1)
|
|
|
+ //}
|
|
|
|
|
|
+ NatsServer.Get_Device_Realtime(sn, mqttid)
|
|
|
+ lib.DeviceRealSnMap.Delete(k)
|
|
|
time.Sleep(time.Millisecond * 100)
|
|
|
return true
|
|
|
})
|
|
|
|
|
|
- Device.Redis_DeviceRealWait_Set("DeviceRealWait10Second")
|
|
|
+ //lib.DeviceRealSnMap.Range(func(k, v interface{}) bool {
|
|
|
+ // sn := strings.Split(k.(string), "|")[0]
|
|
|
+ // mqttid := strings.Split(k.(string), "|")[1]
|
|
|
+ // num, is := Device.Redis_DeviceReal_Get(sn)
|
|
|
+ // if !is {
|
|
|
+ // Device.Redis_DeviceReal_Set(sn, 1)
|
|
|
+ // } else {
|
|
|
+ // Device.Redis_DeviceReal_Set(sn, num+1)
|
|
|
+ // }
|
|
|
+ // // 每次拿到Map的key后,删除该key,否则会造成死循环
|
|
|
+ // lib.DeviceRealSnMap.Delete(k)
|
|
|
+ // // 实时数据请求次数达到180次(30分钟*6次/分钟=180)
|
|
|
+ // // 更新实时请求为2分钟每次(2分钟*6次/分钟=12)
|
|
|
+ // if num > 180 && (num-180)%12 != 0 {
|
|
|
+ // fmt.Println("num:", num)
|
|
|
+ // return true
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // logs.Debug("DeviceRealSnMap:", sn, " num:", num)
|
|
|
+ // NatsServer.Get_Device_Realtime(sn, mqttid)
|
|
|
+ //
|
|
|
+ // time.Sleep(time.Millisecond * 100)
|
|
|
+ // return true
|
|
|
+ //})
|
|
|
+
|
|
|
+ Device.Redis_DeviceRealWait_Set("DeviceRealWait10Second"+conf.MqttServer_id)
|
|
|
time.Sleep(time.Second * 10)
|
|
|
}
|
|
|
}
|