package dao import ( "server/global" "time" ) type Bluetooth struct { global.GVA_MODEL GatewayID uint `json:"gatewayId" gorm:"column:gateway_id;comment:所属网关ID"` AreaID uint `json:"areaId" gorm:"column:area_id;comment:所属分区ID"` ClusterID uint `json:"clusterId" gorm:"column:cluster_id;comment:所属群组ID"` UUID string `json:"uuid" gorm:"column:uuid;uniqueIndex;comment:设备唯一UUID(协议核心)"` AreaNo string `json:"areaNo" gorm:"column:area_no;comment:区号"` Number string `json:"number" gorm:"column:number;comment:灯号/设备号"` ClusterNo string `json:"clusterNo" gorm:"column:cluster_no;comment:组号"` Name string `json:"name" gorm:"column:name;comment:设备名称"` DeviceType string `json:"deviceType" gorm:"column:device_type;comment:设备类型 lamp=灯具 ac=空调 meter=电表 sensor=传感器"` Online int `json:"online" gorm:"column:online;comment:在线状态"` OnlineTime *time.Time `json:"onlineTime" gorm:"column:online_time;comment:最后在线时间"` // -------- 灯具运行参数 -------- LightMode string `json:"lightMode" gorm:"column:light_mode;comment:亮灯模式"` HighBright int `json:"highBright" gorm:"column:high_bright;comment:有人亮度"` StandbyBright int `json:"standbyBright" gorm:"column:standby_bright;comment:无人亮度"` CctBright int `json:"cctBright" gorm:"column:cct_bright;comment:色温"` DelayTime int `json:"delayTime" gorm:"column:delay_time;comment:延时"` DelayTime2 int `json:"delayTime2" gorm:"column:delay_time2;comment:二级延时"` DelayMode string `json:"delay_mode"` // 感应模式 AlsControlMode string `json:"alscontrol_mode"` // 恒照度模式 } func (Bluetooth) TableName() string { return "bluetooth" } func QueryAllBluetooths() (bluetooths []Bluetooth, err error) { err = global.GVA_DB.Model(&Bluetooth{}).Find(&bluetooths).Error return } func QueryBluetoothsByGatewayID(gatewayID int) (bluetooths []Bluetooth, err error) { err = global.GVA_DB.Model(&Bluetooth{}).Where("gateway_id = ?", gatewayID).Find(&bluetooths).Error return } func QueryBluetoothList(gatewayId, limit, offset int) (bluetooths []Bluetooth, total int64, err error) { db := global.GVA_DB.Model(&Bluetooth{}) if gatewayId != 0 { db = db.Where("gateway_id = ?", gatewayId) } err = db.Count(&total).Error if err != nil { return nil, 0, err } err = db.Order("name asc").Limit(limit).Offset(offset).Find(&bluetooths).Error return bluetooths, total, err } func (b Bluetooth) CreateBluetooth() error { return global.GVA_DB.Create(&b).Error } func (b Bluetooth) UpdateBluetooth() error { return global.GVA_DB.Save(&b).Error } func DeleteBluetooth(id int) error { return global.GVA_DB.Unscoped().Delete(&Bluetooth{}, id).Error }