package task

import (
	"server/dao/devices"
	"time"
)

func GatewayRoutingInspection() {
	g := devices.GateWay{}
	gatewayList, _ := g.PublicGateway()
	for _, gateway := range gatewayList {
		currentTime := time.Now()
		status := 1
		if (gateway.RecentOnline == time.Time{} || currentTime.Sub(gateway.RecentOnline).Minutes() > 15) { //如果上次在线时间与当前时间对比超过十五分钟则离线
			//离线 && 修改网关下所有设备的状态为离线
			status = 0
			//_ = devices.UpdateCameraStatusByGatewayId(gateway.ID, status)
			//_ = devices.UpdateScreensStatusByGatewayId(gateway.ID, status)
			//_ = devices.UpdateRadarStatusByGatewayId(gateway.ID, status)
		}
		_ = devices.UpdateGatewayStatus(gateway.GatewayCode, status)
	}
}
