| | |
| | | package models |
| | | |
| | | import "time" |
| | | |
| | | type Positions struct { |
| | | Id uint `gorm:"column:id;primary_key;auto_increment;unique;not null;"` |
| | | DeviceId string `gorm:"column:device_id;" json:"device_id"` |
| | |
| | | func (d *Positions) FindPositionByTime(timestamp int64) error { |
| | | return db.Table(d.TableName()).Where("create_time <= ?", timestamp).Order("create_time desc").First(&d).Error |
| | | } |
| | | |
| | | func (d *Positions) Clean() error { |
| | | timestamp := time.Now().Unix() - 3600 |
| | | return db.Table(d.TableName()).Where("create_time <= ?", timestamp).Delete(&d).Error |
| | | } |