checkPointDao.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package dao
  2. import (
  3. "time"
  4. )
  5. //CheckPoint 卡口
  6. type CheckPoint struct {
  7. ID int `gorm:"primary_key" json:"id"` //编号
  8. PointName string `gorm:"type:varchar(64)" json:"pointName"` //卡口名称
  9. PointSN string `gorm:"type:varchar(60)" json:"pointSn"` //卡口编码
  10. PointLocation string `gorm:"type:varchar(150)" json:"pointLocation"` //卡口位置
  11. TenantId int `gorm:"type:int" json:"tenantId"` //租户ID
  12. CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
  13. CreateUser int64 `gorm:"type:bigint" json:"createUser"` //新增记录操作用户ID
  14. UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
  15. UpdateUser int64 `gorm:"type:bigint" json:"updateUser"` //修改用户
  16. IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
  17. }
  18. func (CheckPoint) TableName() string {
  19. return "t_dev_check_point"
  20. }
  21. func (c CheckPoint) IsExistedBySN() bool {
  22. var count = 0
  23. _ = Db.Debug().Model(&c).Where("point_sn = ? and is_deleted = ?",
  24. c.PointSN, c.IsDeleted).Count(&count).Error
  25. return count > 0
  26. }
  27. func (c *CheckPoint) Create() error {
  28. return Db.Debug().Model(&c).Save(&c).Error
  29. }
  30. func (c *CheckPoint) Update() error {
  31. return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
  32. }
  33. func (c *CheckPoint) GetDevice() error {
  34. err := Db.Debug().Model(&c).Where(" id = ? ", c.ID).First(&c).Error
  35. return err
  36. }
  37. func (c CheckPoint) GetDevices(offset, limit int) ([]CheckPoint, error) {
  38. var Points []CheckPoint
  39. db := Db.Debug().Model(&c)
  40. if c.PointSN != "" {
  41. db = db.Where("point_name like ? or point_sn like ?", "%"+c.PointSN+"%", "%"+c.PointSN+"%")
  42. }
  43. err := db.Where("is_deleted = 0").Offset(offset).Limit(limit).Find(&Points).Error
  44. return Points, err
  45. }
  46. func (c *CheckPoint) Delete() error {
  47. return Db.Debug().Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
  48. "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
  49. }
  50. func (c CheckPoint) GetAllDevices() ([]*CheckPoint, error) {
  51. var Points []*CheckPoint
  52. err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&Points).Error
  53. return Points, err
  54. }