1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package model
- import (
- "github.com/jinzhu/gorm"
- "time"
- )
- type DustMonitorInfo struct {
- ID int64 `gorm:"column:ID"`
- Code string `gorm:"column:Code"`
- Name string `gorm:"column:Name"`
- DeviceID string `gorm:"column:DeviceID"`
- MonitoringTime time.Time `gorm:"column:MonitoringTime"`
- SaveTime time.Time `gorm:"column:SaveTime"`
- Pm10Value float64 `gorm:"column:Pm10Value"`
- Pm25Value float64 `gorm:"column:Pm25Value"`
- Voice float64 `gorm:"column:Voice"`
- Temperature float64 `gorm:"column:Temperature"`
- Humidity float64 `gorm:"column:Humidity"`
- WindSpeed float64 `gorm:"column:WindSpeed"`
- WindDirection float64 `gorm:"column:WindDirection"`
- Atmospheric float64 `gorm:"column:Atmospheric"`
- Type int64 `gorm:"column:Type"`
- Pm25Monitor float64 `gorm:"column:Pm25Monitor"`
- Pm10Monitor float64 `gorm:"column:Pm10Monitor"`
- SprayStatus int64 `gorm:"column:SprayStatus"`
- ProjectId int64 `gorm:"column:ProjectId"`
- SN string `gorm:"column:SN"`
- }
- func (DustMonitorInfo) TableName() string {
- return "DustMonitorInfo"
- }
- func (p *DustMonitorInfo) Insert(db *gorm.DB) error {
- return db.Table(p.TableName()).Create(p).Error
- }
- func (p *DustMonitorInfo) Find(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) error {
- cond, val, err := whereBuildAndOr(where, or)
- if err != nil {
- return err
- }
- return db.Table(p.TableName()).Where(cond, val...).First(p).Error
- }
- func (p *DustMonitorInfo) All(db *gorm.DB, where map[string]interface{}) (list []DustMonitorInfo, err error) {
- if len(where) > 0 {
- cond, val, err := whereBuild(where)
- if err != nil {
- return nil, err
- }
- result := db.Table(p.TableName()).Where(cond, val).Find(&list)
- return list, result.Error
- }
- result := db.Table(p.TableName()).Find(&list)
- return list, result.Error
- }
- func (p *DustMonitorInfo) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
- if len(where) > 0 {
- cond, val, err := whereBuild(where)
- if err != nil {
- return 0, err
- }
- ret := int64(0)
- err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
- return ret, err
- }
- ret := int64(0)
- err := db.Table(p.TableName()).Count(&ret).Error
- return ret, err
- }
- func (p *DustMonitorInfo) Del(db *gorm.DB, where map[string]interface{}) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- return err
- }
- return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
- }
|