bluetooth.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package dao
  2. import (
  3. "server/global"
  4. "time"
  5. )
  6. type Bluetooth struct {
  7. global.GVA_MODEL
  8. GatewayID uint `json:"gatewayId" gorm:"column:gateway_id;comment:所属网关ID"`
  9. AreaID uint `json:"areaId" gorm:"column:area_id;comment:所属分区ID"`
  10. ClusterID uint `json:"clusterId" gorm:"column:cluster_id;comment:所属群组ID"`
  11. UUID string `json:"uuid" gorm:"column:uuid;uniqueIndex;comment:设备唯一UUID(协议核心)"`
  12. AreaNo string `json:"areaNo" gorm:"column:area_no;comment:区号"`
  13. Number string `json:"number" gorm:"column:number;comment:灯号/设备号"`
  14. ClusterNo string `json:"clusterNo" gorm:"column:cluster_no;comment:组号"`
  15. Name string `json:"name" gorm:"column:name;comment:设备名称"`
  16. DeviceType string `json:"deviceType" gorm:"column:device_type;comment:设备类型 lamp=灯具 ac=空调 meter=电表 sensor=传感器"`
  17. Online int `json:"online" gorm:"column:online;comment:在线状态"`
  18. OnlineTime *time.Time `json:"onlineTime" gorm:"column:online_time;comment:最后在线时间"`
  19. // -------- 灯具运行参数 --------
  20. LightMode string `json:"lightMode" gorm:"column:light_mode;comment:亮灯模式"`
  21. HighBright int `json:"highBright" gorm:"column:high_bright;comment:有人亮度"`
  22. StandbyBright int `json:"standbyBright" gorm:"column:standby_bright;comment:无人亮度"`
  23. CctBright int `json:"cctBright" gorm:"column:cct_bright;comment:色温"`
  24. DelayTime int `json:"delayTime" gorm:"column:delay_time;comment:延时"`
  25. DelayTime2 int `json:"delayTime2" gorm:"column:delay_time2;comment:二级延时"`
  26. DelayMode string `json:"delay_mode"` // 感应模式
  27. AlsControlMode string `json:"alscontrol_mode"` // 恒照度模式
  28. }
  29. func (Bluetooth) TableName() string {
  30. return "bluetooth"
  31. }
  32. func QueryAllBluetooths() (bluetooths []Bluetooth, err error) {
  33. err = global.GVA_DB.Model(&Bluetooth{}).Find(&bluetooths).Error
  34. return
  35. }
  36. func QueryBluetoothsByGatewayID(gatewayID int) (bluetooths []Bluetooth, err error) {
  37. err = global.GVA_DB.Model(&Bluetooth{}).Where("gateway_id = ?", gatewayID).Find(&bluetooths).Error
  38. return
  39. }
  40. func QueryBluetoothList(gatewayId, limit, offset int) (bluetooths []Bluetooth, total int64, err error) {
  41. db := global.GVA_DB.Model(&Bluetooth{})
  42. if gatewayId != 0 {
  43. db = db.Where("gateway_id = ?", gatewayId)
  44. }
  45. err = db.Count(&total).Error
  46. if err != nil {
  47. return nil, 0, err
  48. }
  49. err = db.Order("name asc").Limit(limit).Offset(offset).Find(&bluetooths).Error
  50. return bluetooths, total, err
  51. }
  52. func (b Bluetooth) CreateBluetooth() error {
  53. return global.GVA_DB.Create(&b).Error
  54. }
  55. func (b Bluetooth) UpdateBluetooth() error {
  56. return global.GVA_DB.Save(&b).Error
  57. }
  58. func DeleteBluetooth(id int) error {
  59. return global.GVA_DB.Unscoped().Delete(&Bluetooth{}, id).Error
  60. }