package models

import "time"

//电缆防盗状态
type CableGuardianStatus struct {
	ID          uint      `gorm:"primary_key"`
	GID         string    `gorm:"type:varchar(32)"` //网关ID
	GatewayName string    `gorm:"type:varchar(32)"` //网关名称
	DID         string    `gorm:"type:varchar(32)"` //设备ID
	TerminalID  string    `gorm:"type:varchar(8)"`  //终端ID
	Status      int       `gorm:"type:int"`
	CreatedAt   time.Time `gorm:"type:datetime"`
	UpdateAt    time.Time `gorm:"type:datetime"`
}

func (CableGuardianStatus) TableName() string {
	return "t_cable_guardian_status"
}

func (o *CableGuardianStatus) Get() error {
	err := G_db.Model(&o).Where(" g_id = ? and d_id = ? and terminal_id = ?", o.GID, o.DID,
		o.TerminalID).Find(&o).Error
	return err
}

func (o *CableGuardianStatus) Save() error {
	return G_db.Model(&o).Save(&o).Error
}

func (o *CableGuardianStatus) Update() error {
	return G_db.Model(&o).Where(" id = ?", o.ID).Update(&o).Error
}
