1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package dao
- import (
- "github.com/jinzhu/gorm"
- "time"
- )
- type IpBroadcast struct {
- ID int `gorm:"primary_key" json:"id"`
- CastName string `gorm:"type:varchar(64)" json:"castName"`
- CastSN string `gorm:"type:varchar(60)" json:"castSN"`
- LampPoleId int `gorm:"type:int" json:"LampPoleId"`
- LampPoleSN string `gorm:"type: varchar(64)" json:"lampPoleSN"`
- GroupId int `gorm:"type:int" json:"groupId"`
- GatewayID int `gorm:"type: int" json:"gatewayID"`
- GatewaySN string `gorm:"type:varchar(64)" json:"gatewaySN"`
- BrandID int `gorm:"type:int" json:"brandID"`
- ModelID int `gorm:"type:int" json:"modelID"`
- RatedPower float32 `gorm:"type:float(8, 2); default 0.00" json:"ratedPower"`
- IPAddress string `gorm:"type:varchar(50)" json:"ipAddress"`
- ServiceIPAddress string `gorm:"type:varchar(50)" json:"serviceIPAddress"`
- ServerPort int `gorm:"type: int" json:"serverPort"`
- SoundVolume int `gorm:"type: int" json:"soundVolume"`
- InstallTime *time.Time `gorm:"type:date" json:"installTime"`
- CreateTime time.Time `gorm:"type:datetime" json:"createTime"`
- CreateUser string `gorm:"type:varchar(60)" json:"createUser"`
- UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"`
- UpdateUser string `gorm:"type:varchar(60)" json:"updateUser"`
- IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"`
- TenantID string `gorm:"type:varchar(12)" json:"tenantID"`
- }
- func (IpBroadcast) TableName() string {
- return "t_dev_ip_broadcast"
- }
- func (c IpBroadcast) Delete() error {
- return GDb.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 IpBroadcast) IsExistedBySN() bool {
- var count = 0
- _ = GDb.Model(&c).Where(" cast_sn = ? and is_deleted = ?",
- c.CastSN, c.IsDeleted).Count(&count).Error
- return count > 0
- }
- func (c IpBroadcast) IsExistedByNameAndCode() bool {
- var devices []IpBroadcast
- err := GDb.Model(&c).Where(" cast_sn = ? and is_deleted = ?",
- c.CastSN, 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 *IpBroadcast) Create() error {
- return GDb.Model(&c).Save(&c).Error
- }
- func (c *IpBroadcast) Update() error {
- return GDb.Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
- }
- func (c *IpBroadcast) GetDevice() error {
- err := GDb.Model(&c).Where(" id = ? ", c.ID).Scan(&c).Error
- return err
- }
- func (c IpBroadcast) GetDevices(offset, limit int) ([]IpBroadcast, error) {
- var devices []IpBroadcast
- err := GDb.Model(&c).Where(" cast_name like ? ", "%"+c.CastName+"%").Offset(offset).Limit(limit).Find(&devices).Error
- return devices, err
- }
- func (c IpBroadcast) GetAllDevices() ([]*IpBroadcast, error) {
- var devices []*IpBroadcast
- err := GDb.Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantID, c.IsDeleted).Scan(&devices).Error
- return devices, err
- }
|