File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,27 @@ func (s *ServerHandler) ReportSystemState(c context.Context, r *pb.State) (*pb.R
176176 // 更新服务器状态
177177 stateCopy := state // 创建一个副本
178178 singleton .ServerList [clientID ].State = & stateCopy
179+
180+ // 保存最后状态,用于离线后显示
181+ lastState := model.HostState {}
182+ copier .Copy (& lastState , & state )
183+ singleton .ServerList [clientID ].LastStateBeforeOffline = & lastState
184+
185+ // 也将当前状态保存到数据库中的LastStateJSON字段,用于面板重启后恢复离线机器状态
186+ lastStateJSON , err := utils .Json .Marshal (lastState )
187+ if err == nil {
188+ singleton .ServerList [clientID ].LastStateJSON = string (lastStateJSON )
189+ singleton .ServerList [clientID ].LastOnline = singleton .ServerList [clientID ].LastActive
190+
191+ // 立即更新到数据库
192+ singleton .DB .Model (singleton .ServerList [clientID ]).Updates (map [string ]interface {}{
193+ "last_state_json" : singleton .ServerList [clientID ].LastStateJSON ,
194+ "last_online" : singleton .ServerList [clientID ].LastOnline ,
195+ })
196+ } else {
197+ log .Printf ("序列化服务器 %s 的最后状态失败: %v" , singleton .ServerList [clientID ].Name , err )
198+ }
199+
179200 singleton .UpdateServer (singleton .ServerList [clientID ])
180201
181202 log .Printf ("[状态上报] 服务器 %d 状态更新完成: 入站=%d, 出站=%d" ,
You can’t perform that action at this time.
0 commit comments