|
@@ -2,9 +2,12 @@ package initialize
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- "server/task"
|
|
|
|
|
-
|
|
|
|
|
"github.com/robfig/cron/v3"
|
|
"github.com/robfig/cron/v3"
|
|
|
|
|
+ "server/dao"
|
|
|
|
|
+ "server/service/devices"
|
|
|
|
|
+ "server/task"
|
|
|
|
|
+ "server/utils/protocol"
|
|
|
|
|
+ "time"
|
|
|
|
|
|
|
|
"server/global"
|
|
"server/global"
|
|
|
)
|
|
)
|
|
@@ -34,4 +37,31 @@ func Timer() {
|
|
|
// fmt.Println("add timer error:", err)
|
|
// fmt.Println("add timer error:", err)
|
|
|
//}
|
|
//}
|
|
|
}()
|
|
}()
|
|
|
|
|
+
|
|
|
|
|
+ go IsOnline() //监测在线状态
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func IsOnline() {
|
|
|
|
|
+ t := time.NewTicker(1 * time.Minute) //每分钟
|
|
|
|
|
+ for {
|
|
|
|
|
+ select {
|
|
|
|
|
+ case <-t.C:
|
|
|
|
|
+ for sn, device := range devices.DeviceOnlineTimes {
|
|
|
|
|
+ fmt.Printf("定时 %v", device)
|
|
|
|
|
+ fmt.Println("判断:", time.Now().Add(-2*time.Minute).After(*device))
|
|
|
|
|
+ //符合条件
|
|
|
|
|
+ if time.Now().Add(-2 * time.Minute).After(*device) {
|
|
|
|
|
+ err := dao.UpdateScreensStatusBySn(sn, 0)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ global.GVA_LOG.Error(fmt.Sprintf("修改屏幕状态失败:%s", err.Error()))
|
|
|
|
|
+ }
|
|
|
|
|
+ topic := devices.MqttService.GetTopic(sn, protocol.TopicOffline)
|
|
|
|
|
+ _ = devices.MqttService.Publish(topic, sn)
|
|
|
|
|
+ delete(devices.DeviceOnlineTimes, sn)
|
|
|
|
|
+ global.GVA_LOG.Info(fmt.Sprintf("设备【sn】%v 离线了", sn))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|