zhangzengfei
2024-03-29 d6831b733a4a97f2271c544c92ce33701634a97b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package models
 
type Positions struct {
    Id         uint   `gorm:"column:id;primary_key;auto_increment;unique;not null;"`
    DeviceId   string `gorm:"column:device_id;" json:"device_id"`
    Pos        string `gorm:"column:pos" json:"pos"`
    CreateTime int64  `gorm:"column:create_time;autoCreateTime;"`
}
 
func (d *Positions) TableName() string {
    return "positions"
}
 
func (d *Positions) FindDevicePosition(devId string, timestamp int64) error {
    return db.Table(d.TableName()).Where(&d, "device_id = ? AND create_time < ?", devId, timestamp).Order("create_time desc").First(&d).Error
}