12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package dao
- import (
- "github.com/jinzhu/gorm"
- "time"
- )
- type OnDemandGroup struct {
- ID int `gorm:"primary_key" json:"id"`
- PoleGroupName string `gorm:"type:varchar(64)" json:"poleGroupName"`
- SN string `gorm:"type:varchar(60)" json:"sn"`
- LampPoleCount int `gorm:"type:int" json:"lampPoleCount"`
- LightingNum int `gorm:"type:int" json:"lightingNum"`
- BeforeLightingNum int `gorm:"type:int" json:"beforeLightingNum"`
- OutTimes int `gorm:"type:int" json:"outTimes"`
- 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"`
- }
- func (OnDemandGroup) TableName() string {
- return "t_dev_on_demand_group"
- }
- func (c *OnDemandGroup) 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 OnDemandGroup) 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 OnDemandGroup) IsExistedByNameAndCode() bool {
- var devices []Gateway
- err := Db.Debug().Model(&c).Where("gateway_sn = ? and is_deleted = ?",
- c.TenantId, 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 *OnDemandGroup) Create() error {
- return Db.Debug().Model(&c).Save(&c).Error
- }
- func (c *OnDemandGroup) Update() error {
- return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
- }
- func (c *OnDemandGroup) GetDevice() error {
- err := Db.Debug().Model(&c).Where(" id = ? ", c.ID).First(&c).Error
- return err
- }
- func (c OnDemandGroup) GetDevices(offset, limit int) ([]OnDemandGroup, error) {
- var devices []OnDemandGroup
- err := Db.Debug().Model(&c).Where("(pole_group_name like ? or sn like ?) and is_deleted = 0", "%"+c.PoleGroupName+"%", "%"+c.PoleGroupName+"%").Offset(offset).Limit(limit).Find(&devices).Error
- return devices, err
- }
- func (c OnDemandGroup) GetAllDevices() ([]*OnDemandGroup, error) {
- var devices []*OnDemandGroup
- err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
- return devices, err
- }
|