1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package dao
- import (
- "github.com/jinzhu/gorm"
- "time"
- )
- //Zigbee集控器
- type Zigbee struct {
- ID int `gorm:"primary_key" json:"id"` //编号
- Name string `gorm:"type:varchar(64)" json:"name"` //名称
- SN string `gorm:"type:varchar(60)" json:"sn"` //唯一编码
- GroupId int `gorm:"type:int" json:"groupId"` //所属灯杆分组
- LampPoleName string `gorm:"type: varchar(64)" json:"lampPoleName"` //灯杆名称
- LampPoleSN string `gorm:"type: varchar(64)" json:"lampPoleSN"` //灯杆编码
- LampPoleLocation string `gorm:"type:varchar(255)" json:"lampPoleLocation"` //灯杆安装位置
- PoleLng float64 `gorm:"type:double(17, 14) " json:"poleLng"` //经度
- PoleLat float64 `gorm:"type:double(17, 14) " json:"poleLat"` //纬度
- BrandID int `gorm:"type:int" json:"brandID"` //设备名称
- ModelID int `gorm:"type:int" json:"modelID"` //设备型号
- GatewayId string `gorm:"type:varchar(32)" json:"gatewayId"` //所属网关id
- GatewayName string `gorm:"type:varchar(64)" json:"gatewayName"` //所属网关名称
- GatewaySN string `gorm:"type:varchar(60)" json:"gatewaySN"` //所属网关编码
- ChanelNum int `gorm:"type:int" json:"chanelNum"` //通道号
- NetworkNum int `gorm:"type:int" json:"networkNum"` //网络号
- InstallTime *time.Time `gorm:"type:date" json:"installTime"` //安装时间
- TenantId string `gorm:"type:varchar(12)" json:"tenantId"` //租户id
- CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
- CreateUser string `gorm:"type:varchar(60)" json:"createUser"` //新增记录操作用户ID
- 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"` //是否删除 0=未删除,1=删除
- Tag string `gorm:"type:varchar(255)" json:"tag"` //标签,保留字段(逗号区分)
- IPAddress string `gorm:"type:varchar(64)" json:"ipAddress"` //IP地址-备用
- }
- func (Zigbee) TableName() string {
- return "t_dev_zigbee"
- }
- func (c Zigbee) 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 Zigbee) 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 Zigbee) 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 *Zigbee) Create() error {
- return Db.Debug().Model(&c).Save(&c).Error
- }
- func (c *Zigbee) Update() error {
- return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
- }
- func (c *Zigbee) GetDevice() error {
- err := Db.Debug().Model(&c).Where(" id = ? ", c.ID).Scan(&c).Error
- return err
- }
- func (c Zigbee) GetDevices(offset, limit int) ([]Zigbee, error) {
- var devices []Zigbee
- err := Db.Debug().Model(&c).Where(" name like ? ", "%"+c.Name+"%").Offset(offset).Limit(limit).Find(&devices).Error
- return devices, err
- }
- func (c Zigbee) GetAllDevices() ([]*Zigbee, error) {
- var devices []*Zigbee
- err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
- return devices, err
- }
|