|
|
@@ -46,20 +46,20 @@ func (LightControl) TableName() string {
|
|
|
}
|
|
|
|
|
|
func (c *LightControl) Delete() error {
|
|
|
- return Db.Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
|
|
|
+ return Db.Debug().Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
|
|
|
"update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
|
|
|
}
|
|
|
|
|
|
func (c LightControl) IsExistedBySN() bool {
|
|
|
var count = 0
|
|
|
- _ = Db.Model(&c).Where("sn = ? and is_deleted = ?",
|
|
|
+ _ = Db.Debug().Model(&c).Where("sn = ? and is_deleted = ?",
|
|
|
c.SN, c.IsDeleted).Count(&count).Error
|
|
|
return count > 0
|
|
|
}
|
|
|
|
|
|
func (c LightControl) IsExistedByNameAndCode() bool {
|
|
|
var devices []LightControl
|
|
|
- err := Db.Model(&c).Where("pole_sn = ? and is_deleted = ?",
|
|
|
+ err := Db.Debug().Model(&c).Where("pole_sn = ? and is_deleted = ?",
|
|
|
c.TenantId, c.IsDeleted).Find(&devices).Error
|
|
|
if gorm.IsRecordNotFoundError(err) {
|
|
|
return false
|
|
|
@@ -73,32 +73,32 @@ func (c LightControl) IsExistedByNameAndCode() bool {
|
|
|
}
|
|
|
|
|
|
func (c *LightControl) Create() error {
|
|
|
- return Db.Model(&c).Save(&c).Error
|
|
|
+ return Db.Debug().Model(&c).Save(&c).Error
|
|
|
}
|
|
|
|
|
|
func (c *LightControl) Update() error {
|
|
|
- return Db.Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
|
|
|
+ return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
|
|
|
}
|
|
|
|
|
|
func (c *LightControl) UpdateEnable() error {
|
|
|
- return Db.Model(&c).Where(" id = ? ", c.ID).Updates(map[string]interface{}{"is_enable": c.IsEnable}).Error
|
|
|
+ return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Updates(map[string]interface{}{"is_enable": c.IsEnable}).Error
|
|
|
}
|
|
|
|
|
|
func (c *LightControl) GetDevice() error {
|
|
|
- err := Db.Model(&c).Where(" id = ? ", c.ID).First(&c).Error
|
|
|
+ err := Db.Debug().Model(&c).Where(" id = ? ", c.ID).First(&c).Error
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func (c *LightControl) GetDevicesByGroup() ([]LightControl, error) {
|
|
|
var devices []LightControl
|
|
|
- err := Db.Model(&c).Where(" group_id = ? and is_deleted = 0", c.GroupId).Find(&devices).Error
|
|
|
+ err := Db.Debug().Model(&c).Where(" group_id = ? and is_deleted = 0", c.GroupId).Find(&devices).Error
|
|
|
return devices, err
|
|
|
}
|
|
|
|
|
|
func (c LightControl) GetDevices(offset, limit int) ([]LightControl, error) {
|
|
|
var devices []LightControl
|
|
|
|
|
|
- db := Db.Model(&c)
|
|
|
+ db := Db.Debug().Model(&c)
|
|
|
if c.SN != "" {
|
|
|
db = db.Where("name like ? or sn like ?", "%"+c.SN+"%", "%"+c.SN+"%")
|
|
|
}
|
|
|
@@ -115,6 +115,6 @@ func (c LightControl) GetDevices(offset, limit int) ([]LightControl, error) {
|
|
|
|
|
|
func (c LightControl) GetAllDevices() ([]*LightControl, error) {
|
|
|
var devices []*LightControl
|
|
|
- err := Db.Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
|
|
|
+ err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
|
|
|
return devices, err
|
|
|
}
|