dust_excessive_img.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package model
  2. import "github.com/jinzhu/gorm"
  3. type DustExcessiveImg struct {
  4. Ecode string `gorm:"column:Ecode"`
  5. ImageText string `gorm:"column:ImageText"`
  6. ID int64 `gorm:"column:ID"`
  7. ProjectId int64 `gorm:"column:ProjectId"`
  8. SN string `gorm:"column:SN"`
  9. DeviceID string `gorm:"column:DeviceID"`
  10. }
  11. func (DustExcessiveImg) TableName() string {
  12. return "DustExcessiveImg"
  13. }
  14. func (p *DustExcessiveImg) Insert(db *gorm.DB) error {
  15. return db.Table(p.TableName()).Create(p).Error
  16. }
  17. func (p *DustExcessiveImg) Find(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) error {
  18. cond, val, err := whereBuildAndOr(where, or)
  19. if err != nil {
  20. return err
  21. }
  22. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  23. }
  24. func (p *DustExcessiveImg) All(db *gorm.DB, where map[string]interface{}) (list []DustExcessiveImg, err error) {
  25. if len(where) > 0 {
  26. cond, val, err := whereBuild(where)
  27. if err != nil {
  28. return nil, err
  29. }
  30. result := db.Table(p.TableName()).Where(cond, val).Find(&list)
  31. return list, result.Error
  32. }
  33. result := db.Table(p.TableName()).Find(&list)
  34. return list, result.Error
  35. }
  36. func (p *DustExcessiveImg) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
  37. if len(where) > 0 {
  38. cond, val, err := whereBuild(where)
  39. if err != nil {
  40. return 0, err
  41. }
  42. ret := int64(0)
  43. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  44. return ret, err
  45. }
  46. ret := int64(0)
  47. err := db.Table(p.TableName()).Count(&ret).Error
  48. return ret, err
  49. }
  50. func (p *DustExcessiveImg) Del(db *gorm.DB, where map[string]interface{}) error {
  51. cond, val, err := whereBuild(where)
  52. if err != nil {
  53. return err
  54. }
  55. return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  56. }