package models

type DeviceCmdRecord struct {
	ID      uint64 `gorm:"type:bigint;primary_key"`
	GID     string `gorm:"type:varchar(32)"`
	DID     string `gorm:"type:varchar(32)"`
	Topic   string `gorm:"type:varchar(64)"`
	Message string `gorm:"type:text"`
	State   uint   `gorm:"type:int"` //状态，默认0
	Resp    string `gorm:"type:text"`
	LcModel
}

func (DeviceCmdRecord) TableName() string {
	return "device_cmd_record"
}

func (o DeviceCmdRecord) Update() error {
	return G_db.Model(&DeviceCmdRecord{}).Where("id = ?",
		o.ID).Updates(DeviceCmdRecord{State: o.State, Resp: o.Resp}).Error
}

//查询待发指令
func (o DeviceCmdRecord) QueryCmdRecordByDID(DID string) ([]DeviceCmdRecord, error) {
	var result []DeviceCmdRecord
	err := G_db.Model(&DeviceCmdRecord{}).Where("d_id = ? and state = 0", DID).Find(&result).Error
	return result, err
}
