zhangzengfei
2024-10-20 5ddd4f4ba6aaf1fe52f93c0966315d0424bd2a5f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package models
 
import (
    "gat1400Exchange/vo"
    "time"
)
 
type Ape struct {
    Id            string `gorm:"column:id;primary_key;" json:"id"`
    Name          string `gorm:"column:name" json:"name"`
    FromId        string `gorm:"column:from_id" json:"from_id"`
    HeartbeatTime string `gorm:"column:heartbeat_time" json:"heartbeat_time"`
    Ext           vo.Ape `gorm:"column:ext;type:json;not null;default '{}'" json:"ext"`
    CreateTime    int64  `gorm:"column:create_time;autoCreateTime;" json:"create_time"`
    UpdateTime    int64  `gorm:"column:update_time;autoUpdateTime" json:"-"`
    DeleteTime    int64  `gorm:"column:delete_time" json:"-"`
}
 
func (a *Ape) TableName() string {
    return "apes"
}
 
func (a *Ape) FindById(id string) error {
    return db.Table(a.TableName()).First(&a, "id = ?", id).Error
}
 
func (a *Ape) Save() error {
    return db.Table(a.TableName()).Save(a).Error
}
 
func (a *Ape) Keepalive(id string) error {
    return db.Table(a.TableName()).Where("id = ?", id).Update("heartbeat_time", time.Now().Format("2006-01-02 15:04:05")).Error
}
 
func (a *Ape) FindAll() ([]Ape, error) {
    var devices []Ape
    if err := db.Table(a.TableName()).Find(&devices).Error; err != nil {
        return nil, err
    }
 
    return devices, nil
}