lampPoleGroupDto.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "time"
  4. )
  5. //LampPoleGroup 灯杆分组
  6. type LampPoleGroup struct {
  7. ID int `gorm:"type:int;primary_key"` //编号
  8. PoleGroupName string `gorm:"type:varchar(64)"` //分组名称
  9. TenantId string `gorm:"type:varchar(12)"` //租户ID
  10. CreateTime time.Time `gorm:"type:datetime"` //新增时间
  11. CreateUser string `gorm:"type:varchar(60)"` //新增记录操作用户ID
  12. UpdateTime time.Time `gorm:"type:datetime"` //修改时间
  13. UpdateUser string `gorm:"type:varchar(60)"` //修改用户
  14. IsDeleted int `gorm:"type:int;default 0"` //是否删除 0=未删除,1=删除
  15. Tag string `gorm:"type:varchar(255)"` //标签,(备用,逗号区分)
  16. Remark string `gorm:"type:varchar(255)"` //备注
  17. }
  18. func (LampPoleGroup) TableName() string {
  19. return "t_dev_lamp_pole_group"
  20. }
  21. func (c LampPoleGroup) Delete() error {
  22. return GDb.Model(&c).Updates(map[string]interface{}{"state": 0}).Error
  23. }
  24. func (c LampPoleGroup) IsExistedByCode() (bool, error) {
  25. var count = 0
  26. err := GDb.Model(&c).Where(" id = ? ", c.ID).Count(&count).Error
  27. return count > 0, err
  28. }
  29. func (c LampPoleGroup) GetDeviceID() (int, error) {
  30. err := GDb.Model(&c).Where(" pole_group_name = ? and tenant_id = ? and is_deleted = ?", c.PoleGroupName, c.TenantId, c.IsDeleted).First(&c).Error
  31. return c.ID, err
  32. }
  33. func (c LampPoleGroup) Create() error {
  34. return GDb.Create(&c).Error
  35. }
  36. func (c LampPoleGroup) Update() error {
  37. return GDb.Model(&c).Updates(map[string]interface{}{"pole_group_name": c.PoleGroupName,
  38. "tenant_id": c.TenantId, "update_time": time.Now(), "update_user": "TODO", "is_deleted": 0}).Error
  39. }
  40. func (c LampPoleGroup) GetDevice() error {
  41. err := GDb.Model(&c).Where(" id = ? ", c.ID).Scan(&c).Error
  42. return err
  43. }
  44. func (c LampPoleGroup) GetDevices(offset, limit int) ([]LampPoleGroup, error) {
  45. var devices []LampPoleGroup
  46. err := GDb.Model(&c).Where(" id like '%?%'", c.PoleGroupName).Offset(offset).Limit(limit).Scan(&devices).Error
  47. return devices, err
  48. }