dust_excessive_info.go 1.9 KB

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