device_del_job.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package model
  4. import (
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. type DeviceDelJob struct {
  9. ID int64 `gorm:"column:ID" json:"id" form:"id"`
  10. CreatedAt time.Time `gorm:"column:CreatedAt" json:"created_at" form:"created_at"`
  11. Status int64 `gorm:"column:Status" json:"status" form:"status"`
  12. UpdatedAt time.Time `gorm:"column:UpdatedAt" json:"updated_at" form:"updated_at"`
  13. ProjectId int64 `gorm:"column:ProjectId" json:"project_id" form:"project_id"`
  14. Feedback string `gorm:"column:Feedback"`
  15. Reason string `gorm:"column:Reason"`
  16. ProviderId int64 `gorm:"column:ProviderId"`
  17. DeviceId int64 `gorm:"column:DeviceId"`
  18. DeviceCode uint32 `gorm:"column:DeviceCode"`
  19. Sn string `gorm:"column:SN"`
  20. DeviceName string `gorm:"column:DeviceName"`
  21. }
  22. func (DeviceDelJob) TableName() string {
  23. return "DeviceDelJob"
  24. }
  25. func (p *DeviceDelJob) Insert(db *gorm.DB) error {
  26. return db.Table(p.TableName()).Create(p).Error
  27. }
  28. func (p *DeviceDelJob) Del(db *gorm.DB, where map[string]interface{}) error {
  29. cond, val, err := whereBuild(where)
  30. if err != nil {
  31. return err
  32. }
  33. return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  34. }
  35. func (p *DeviceDelJob) Find(db *gorm.DB, where map[string]interface{}) error {
  36. cond, val, err := whereBuild(where)
  37. if err != nil {
  38. return err
  39. }
  40. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  41. }
  42. func (p *DeviceDelJob) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error {
  43. cond, val, err := whereBuild(where)
  44. if err != nil {
  45. return err
  46. }
  47. return db.Table(p.TableName()).Where(cond, val...).Updates(values).Error
  48. }
  49. func (p *DeviceDelJob) Save(db *gorm.DB) error {
  50. return db.Table(p.TableName()).Save(p).Error
  51. }
  52. func (p *DeviceDelJob) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
  53. if len(where) > 0 {
  54. cond, val, err := whereBuild(where)
  55. if err != nil {
  56. return 0, err
  57. }
  58. ret := int64(0)
  59. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  60. return ret, err
  61. }
  62. ret := int64(0)
  63. err := db.Table(p.TableName()).Count(&ret).Error
  64. return ret, err
  65. }
  66. func (p *DeviceDelJob) List(db *gorm.DB, where map[string]interface{}, page int) (list []DeviceDelJob, err error) {
  67. if len(where) > 0 {
  68. cond, val, err := whereBuild(where)
  69. if err != nil {
  70. return list, err
  71. }
  72. result := db.Table(p.TableName()).Where(cond, val...).Limit(PageSize).Offset(page).Find(&list)
  73. return list, result.Error
  74. }
  75. result := db.Table(p.TableName()).Limit(10).Offset(page).Find(&list)
  76. return list, result.Error
  77. }
  78. func (p *DeviceDelJob) All(db *gorm.DB) (list []DeviceDelJob, err error) {
  79. result := db.Table(p.TableName()).Find(&list)
  80. return list, result.Error
  81. }