123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package dao
- import (
- "github.com/jinzhu/gorm"
- "time"
- )
- type OptoSensor struct {
- ID int `gorm:"primary_key" json:"id"`
- Name string `gorm:"type:varchar(64)" json:"name"`
- SN string `gorm:"type:varchar(60)" json:"sn"`
- LampPoleId int `gorm:"type:int" json:"lampPoleId"`
- LampPoleName string `gorm:"type:varchar(64)" json:"lampPoleName"`
- LampPoleSN string `gorm:"type:varchar(64)" json:"lampPoleSN"`
- LampPoleLocation string `gorm:"type:varchar(255)" json:"lampPoleLocation"`
- LampLng float64 `gorm:"type:double(17, 14) " json:"poleLng"`
- LampLat float64 `gorm:"type:double(17, 14) " json:"poleLat"`
- BrandID int `gorm:"type:int" json:"brandID"`
- ModelID int `gorm:"type:int" json:"modelID"`
- GatewayId int `gorm:"type:int" json:"gatewayId"`
- InstallTime *time.Time `gorm:"type:date" json:"installTime"`
- IPAddress string `gorm:"type:varchar(64)" json:"ipAddress"`
- IsDefault int `gorm:"type:int;default 0" json:"isDefault"`
- TenantId int `gorm:"type:int" json:"tenantId"`
- CreateTime time.Time `gorm:"type:datetime" json:"createTime"`
- CreateUser int64 `gorm:"type:bigint" json:"createUser"`
- UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"`
- UpdateUser int64 `gorm:"type:bigint" json:"updateUser"`
- IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"`
- Status int `gorm:"type:int" json:"status"`
- Tag string `gorm:"type:varchar(255)" json:"tag"`
- }
- func (OptoSensor) TableName() string {
- return "t_dev_opto_sensor"
- }
- func (c OptoSensor) Delete() error {
- return Db.Debug().Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
- "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
- }
- func (c OptoSensor) IsExistedBySN() bool {
- var count = 0
- _ = Db.Debug().Model(&c).Where(" sn = ? and is_deleted = ?",
- c.SN, c.IsDeleted).Count(&count).Error
- return count > 0
- }
- func (c OptoSensor) IsExistedByNameAndCode() bool {
- var devices []Zigbee
- err := Db.Debug().Model(&c).Where(" sn = ? and is_deleted = ?",
- c.SN, c.IsDeleted).Find(&devices).Error
-
- if gorm.IsRecordNotFoundError(err) {
- return false
- }
- for _, d := range devices {
- if d.ID != c.ID {
- return true
- }
- }
- return false
- }
- func (c *OptoSensor) Create() error {
- return Db.Debug().Model(&c).Save(&c).Error
- }
- func (c *OptoSensor) Update() error {
- return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
- }
- func (c *OptoSensor) GetDevice() error {
- err := Db.Debug().Model(&c).Where(" id = ? ", c.ID).Scan(&c).Error
- return err
- }
- func (c OptoSensor) GetDevices(offset, limit int) ([]OptoSensor, error) {
- var devices []OptoSensor
- err := Db.Debug().Model(&c).Where(" name like ? ", "%"+c.Name+"%").Offset(offset).Limit(limit).Find(&devices).Error
- return devices, err
- }
- func (c OptoSensor) GetAllDevices() ([]*OptoSensor, error) {
- var devices []*OptoSensor
- err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
- return devices, err
- }
|