add last online ip #24

This commit is contained in:
ljw
2024-10-28 20:24:34 +08:00
parent 1191ade8af
commit 991fc86fa6
3 changed files with 5 additions and 5 deletions

View File

@@ -101,7 +101,7 @@ func main() {
} }
func DatabaseAutoUpdate() { func DatabaseAutoUpdate() {
version := 240 version := 241
db := global.DB db := global.DB

View File

@@ -54,10 +54,9 @@ func (i *Index) Heartbeat(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{}) c.JSON(http.StatusOK, gin.H{})
return return
} }
//如果在一分钟以内则不更新 //如果在40s以内则不更新
if time.Now().Unix()-peer.LastOnlineTime > 60 { if time.Now().Unix()-peer.LastOnlineTime > 40 {
peer.LastOnlineTime = time.Now().Unix() upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: time.Now().Unix(), LastOnlineIp: c.ClientIP()}
upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: peer.LastOnlineTime}
service.AllService.PeerService.Update(upp) service.AllService.PeerService.Update(upp)
} }
c.JSON(http.StatusOK, gin.H{}) c.JSON(http.StatusOK, gin.H{})

View File

@@ -13,6 +13,7 @@ type Peer struct {
UserId uint `json:"user_id" gorm:"default:0;not null;index"` UserId uint `json:"user_id" gorm:"default:0;not null;index"`
User *User `json:"user,omitempty"` User *User `json:"user,omitempty"`
LastOnlineTime int64 `json:"last_online_time" gorm:"default:0;not null;"` LastOnlineTime int64 `json:"last_online_time" gorm:"default:0;not null;"`
LastOnlineIp string `json:"last_online_ip" gorm:"default:'';not null;"`
TimeModel TimeModel
} }