dust_data_info.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package model
  2. import (
  3. "github.com/jinzhu/gorm"
  4. "time"
  5. )
  6. type DustMonitorInfo 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. SaveTime time.Time `gorm:"column:SaveTime"`
  13. Pm10Value float64 `gorm:"column:Pm10Value"`
  14. Pm25Value float64 `gorm:"column:Pm25Value"`
  15. Voice float64 `gorm:"column:Voice"`
  16. Temperature float64 `gorm:"column:Temperature"`
  17. Humidity float64 `gorm:"column:Humidity"`
  18. WindSpeed float64 `gorm:"column:WindSpeed"`
  19. WindDirection float64 `gorm:"column:WindDirection"`
  20. Atmospheric float64 `gorm:"column:Atmospheric"`
  21. Type int64 `gorm:"column:Type"`
  22. Pm25Monitor float64 `gorm:"column:Pm25Monitor"`
  23. Pm10Monitor float64 `gorm:"column:Pm10Monitor"`
  24. SprayStatus int64 `gorm:"column:SprayStatus"`
  25. ProjectId int64 `gorm:"column:ProjectId"`
  26. SN string `gorm:"column:SN"`
  27. }
  28. func (DustMonitorInfo) TableName() string {
  29. return "DustMonitorInfo"
  30. }
  31. func (p *DustMonitorInfo) Insert(db *gorm.DB) error {
  32. return db.Table(p.TableName()).Create(p).Error
  33. }
  34. func (p *DustMonitorInfo) Find(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) error {
  35. cond, val, err := whereBuildAndOr(where, or)
  36. if err != nil {
  37. return err
  38. }
  39. return db.Table(p.TableName()).Where(cond, val...).First(p).Error
  40. }
  41. func (p *DustMonitorInfo) All(db *gorm.DB, where map[string]interface{}) (list []DustMonitorInfo, err error) {
  42. if len(where) > 0 {
  43. cond, val, err := whereBuild(where)
  44. if err != nil {
  45. return nil, err
  46. }
  47. result := db.Table(p.TableName()).Where(cond, val).Find(&list)
  48. return list, result.Error
  49. }
  50. result := db.Table(p.TableName()).Find(&list)
  51. return list, result.Error
  52. }
  53. func (p *DustMonitorInfo) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
  54. if len(where) > 0 {
  55. cond, val, err := whereBuild(where)
  56. if err != nil {
  57. return 0, err
  58. }
  59. ret := int64(0)
  60. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  61. return ret, err
  62. }
  63. ret := int64(0)
  64. err := db.Table(p.TableName()).Count(&ret).Error
  65. return ret, err
  66. }
  67. func (p *DustMonitorInfo) Del(db *gorm.DB, where map[string]interface{}) error {
  68. cond, val, err := whereBuild(where)
  69. if err != nil {
  70. return err
  71. }
  72. return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
  73. }