package models
|
|
//设备添加申请记录
|
type DeviceApply struct {
|
Id string `gorm:"column:id;primary_key;type:varchar(50);unique;not null;" json:"id"`
|
DevId string `gorm:"column:devId;unique;not null;" json:"devId"`
|
DevName string `gorm:"column:devName" json:"devName"`
|
ApplyKey string `gorm:"column:applyKey" json:"applyKey"`
|
Ip string `gorm:"column:ip" json:"ip"`
|
CreateTime string `gorm:"column:createTime" json:"createTime"`
|
Status int `gorm:"column:status;default:0;" json:"status"` //状态 0:已添加,待发送给对方 1:已成功发送请求到对方,等待反馈。 2:对方已同意 -2:对方已拒绝
|
}
|
|
const (
|
ApplyStatus_KeyErr = -2 //密钥错误
|
ApplyStatus_Reject = -1 //已拒绝
|
ApplyStatus_Sending = 0 //等待发送给对方
|
ApplyStatus_Waiting = 1 //等待响应
|
ApplyStatus_Agreed = 2 //已同意
|
ApplyStatus_Managed = 3 //已处于管理状态
|
)
|
|
func (DeviceApply) TableName() string {
|
return "t_device_apply"
|
}
|
|
func (da *DeviceApply) Insert() bool {
|
result := db.Table(da.TableName()).Create(&da)
|
if result.Error == nil && result.RowsAffected > 0 {
|
return true
|
}
|
return false
|
}
|
|
func (da *DeviceApply) FindByDevId(devId string) (int64,error) {
|
result := db.Table(da.TableName()).Where("devId=?", devId).First(&da)
|
if result.Error != nil || result.RowsAffected == 0 {
|
return 0, result.Error
|
}
|
return result.RowsAffected, nil
|
}
|
|
func (da *DeviceApply) Update() bool {
|
result := db.Table(da.TableName()).Where("id=?", da.Id).Update(&da)
|
if result.Error ==nil && result.RowsAffected > 0 {
|
return true
|
}
|
return false
|
}
|
|
func (da *DeviceApply) DeleteById(id string) bool {
|
result := db.Exec("delete from "+da.TableName()+" where id='"+id+"'")
|
if result.Error == nil && result.RowsAffected > 0 {
|
return true
|
}
|
return false
|
}
|
|
func (da *DeviceApply) FindByStatus(status int) (list []DeviceApply) {
|
err := db.Table(da.TableName()).Where("status=?", status).Find(&list).Error
|
if err != nil {
|
return nil
|
}
|
return list
|
}
|
|
func (da *DeviceApply) UpdateStatus(status int, id string) bool {
|
return db.Exec("update "+da.TableName()+" set status=? where id=?", status, id).RowsAffected >0
|
}
|