Browse Source

优化代码

chengqian 4 months ago
parent
commit
693117e986
2 changed files with 7 additions and 20 deletions
  1. 2 15
      server/dao/devices/dev_screens.go
  2. 5 5
      server/service/tcp/deviceMgr.go

+ 2 - 15
server/dao/devices/dev_screens.go

@@ -113,7 +113,7 @@ func UpdateScreensStatusByGatewayId(id, status int) error {
 	return err
 }
 
-func UpdateScreensStatusAndOnline(code string, sta request.DeviceStatus) error {
+func UpdateScreensStatusIsLogin(code string, sta request.DeviceStatus, isLogin int) error {
 	var screens Screens
 	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{}{
@@ -122,20 +122,7 @@ func UpdateScreensStatusAndOnline(code string, sta request.DeviceStatus) error {
 		"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", "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,
+		"is_login":         isLogin,
 	}).Error
 }
 

+ 5 - 5
server/service/tcp/deviceMgr.go

@@ -63,12 +63,12 @@ func (s *Device) Process() {
 				break
 			}
 
-			err = Dev.UpdateScreensStatusAndOnline(screens.ScreensCode, request.DeviceStatus{
+			err = Dev.UpdateScreensStatusIsLogin(screens.ScreensCode, request.DeviceStatus{
 				Status:        1,
 				PlayStatus:    1,
 				DisplayStatus: 1,
 				SourceStatus:  1,
-			})
+			}, 1)
 			if err != nil {
 				logger.Logger.Error("[Handle] UpdateScreensStatus err", zap.Error(err))
 				continue
@@ -92,12 +92,12 @@ func (s *Device) Process() {
 
 				//如果是未登录状态,则登录并更新在线时间
 				if screens.IsLogin == 0 {
-					_ = Dev.UpdateScreensStatusAndOnline(screens.ScreensCode, request.DeviceStatus{
+					_ = Dev.UpdateScreensStatusIsLogin(screens.ScreensCode, request.DeviceStatus{
 						Status:        s.info.Status,
 						PlayStatus:    s.info.PlayStatus,
 						DisplayStatus: s.info.DisplayStatus,
 						SourceStatus:  s.info.SourceStatus,
-					})
+					}, 1)
 				}
 			}
 			if data[34:50] != s.info.Sn {
@@ -127,7 +127,7 @@ func (s *Device) Handle() {
 			if time.Now().Add(-2*time.Minute).After(s.lastTime) || s.lastTime.IsZero() {
 				//离线
 				state.Status = 0
-				err := Dev.UpdateScreensStatusAndOffline(s.info.ScreensCode, state)
+				err := Dev.UpdateScreensStatusIsLogin(s.info.ScreensCode, state, 0)
 				if err != nil {
 					logger.Logger.Error("[Handle] UpdateScreensStatus err", zap.Error(err))
 					continue