Browse Source

优化累计时间出现负数的问题

chengqian 4 months ago
parent
commit
18b9878c84

BIN
server/build/smart_intersection


+ 1 - 1
server/config.yaml

@@ -134,7 +134,7 @@ mysql:
     singular: false
     log-zap: false
 mqtt:
-    server: "tcp://118.253.180.18:1883"
+    server: "tcp://106.52.134.22:1883"
     id: "smart_intersection_admin"
     user: "admin"
     password: "admin"

+ 6 - 3
server/dao/devices/dev_screens.go

@@ -28,9 +28,10 @@ type Screens struct {
 	DisplayStatus   int            `gorm:"type:int;default:0" json:"displayStatus"`           //显示模板状态
 	SourceStatus    int            `gorm:"type:int;default:0" json:"sourceStatus"`            //素材状态
 	DayBright       int            `gorm:"type:int;default:100" json:"dayBright"`             //白天亮度
-	NightBright     int            `gorm:"type:int;default:30" json:"nightBright"`            //晚上亮度
+	NightBright     int            `gorm:"type:int;default:10" json:"nightBright"`            //晚上亮度
 	LastOnlineTime  time.Time      `gorm:"type:datetime;default:NULL" json:"lastOnlineTime"`  //最近在线时间
 	LastOfflineTime time.Time      `gorm:"type:datetime;default:NULL" json:"lastOfflineTime"` //最近离线时间
+	IsLogin         int            `gorm:"type:int;default:0" json:"isLogin"`                 //是否登录 0=未登录,1=登录
 
 	GateWay     GateWay     `gorm:"foreignkey:GatewayId"`
 	Resolution  Resolution  `gorm:"foreignkey:ResolutionId"`
@@ -114,25 +115,27 @@ func UpdateScreensStatusByGatewayId(id, status int) error {
 
 func UpdateScreensStatusAndOnline(code string, sta request.DeviceStatus) error {
 	var screens Screens
-	return global.GVA_DB.Model(&screens).Select("status", "play_status", "display_status", "source_status", "last_online_time").
+	return global.GVA_DB.Model(&screens).Select("status", "play_status", "display_status", "source_status", "last_online_time", "is_login").
 		Where("screens_code = ?", code).Updates(map[string]interface{}{
 		"status":           sta.Status,
 		"play_status":      sta.PlayStatus,
 		"display_status":   sta.DisplayStatus,
 		"source_status":    sta.SourceStatus,
 		"last_online_time": time.Now(),
+		"is_login":         1,
 	}).Error
 }
 
 func UpdateScreensStatusAndOffline(code string, sta request.DeviceStatus) error {
 	var screens Screens
-	return global.GVA_DB.Model(&screens).Select("status", "play_status", "display_status", "source_status", "last_offline_time").
+	return global.GVA_DB.Model(&screens).Select("status", "play_status", "display_status", "source_status", "last_offline_time", "is_login").
 		Where("screens_code = ?", code).Updates(map[string]interface{}{
 		"status":            sta.Status,
 		"play_status":       sta.PlayStatus,
 		"display_status":    sta.DisplayStatus,
 		"source_status":     sta.SourceStatus,
 		"last_offline_time": time.Now(),
+		"is_login":          0,
 	}).Error
 }
 

+ 10 - 0
server/service/tcp/deviceMgr.go

@@ -89,6 +89,16 @@ func (s *Device) Process() {
 				}
 				s.info = screens
 				devices[s.info.Sn] = *s
+
+				//如果是未登录状态,则登录并更新在线时间
+				if screens.IsLogin == 0 {
+					_ = Dev.UpdateScreensStatusAndOnline(screens.ScreensCode, request.DeviceStatus{
+						Status:        s.info.Status,
+						PlayStatus:    s.info.PlayStatus,
+						DisplayStatus: s.info.DisplayStatus,
+						SourceStatus:  s.info.SourceStatus,
+					})
+				}
 			}
 			if data[34:50] != s.info.Sn {
 				continue