zhangzengfei
2024-05-18 3771d5551480964ab17f4c23a152df2482bf6470
models/cascade.go
@@ -1,19 +1,35 @@
package models
import "time"
type Cascade struct {
   Id         string   `gorm:"column:id;primary_key;" json:"id"`
   Name       string   `gorm:"column:name" json:"name"`
   Username   string   `gorm:"column:username" json:"username"`
   Password   string   `gorm:"column:password" json:"password"`
   IP         string   `gorm:"column:ip" json:"ip"`
   Port       int      `gorm:"column:port" json:"port"`
   Enabled    bool     `gorm:"column:enabled" json:"enabled"`
   DeviceIDs  []string `gorm:"column:device_ids;type:text[];default '{}'" json:"device_ids"`
   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:"-"`
   Id            string   `gorm:"column:id;primary_key;" json:"id"`
   Name          string   `gorm:"column:name" json:"name"`
   Username      string   `gorm:"column:username" json:"username"`
   Password      string   `gorm:"column:password" json:"password"`
   IP            string   `gorm:"column:ip" json:"ip"`
   Port          int      `gorm:"column:port" json:"port"`
   Enabled       bool     `gorm:"column:enabled" json:"enabled"`
   DeviceIDs     []string `gorm:"column:device_ids;type:text[];default '{}'" json:"device_ids"`
   HeartbeatTime string   `gorm:"column:heartbeat_time;" json:"heartbeat_time"`
   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 (c *Cascade) TableName() string {
   return "cascades"
}
func (c *Cascade) FindAll() ([]Cascade, error) {
   var list []Cascade
   if err := db.Table(c.TableName()).Find(&list).Error; err != nil {
      return nil, err
   }
   return list, nil
}
func (c *Cascade) Keepalive(id string) error {
   return db.Table(c.TableName()).Where("id = ?", id).Update("heartbeat_time", time.Now().Format("2006-01-02 15:04:05")).Error
}