dev_screens.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package devices
  2. import (
  3. "gorm.io/gorm"
  4. "server/global"
  5. "server/model/common/request"
  6. "time"
  7. )
  8. type Screens struct {
  9. ID int `gorm:"primarykey" json:"ID"` //主键ID
  10. ScreensName string `gorm:"type:varchar(64)" json:"screensName"` //设备名称
  11. ScreensCode string `gorm:"type:varchar(64)" json:"screensCode"` //设备编码
  12. Sn string `gorm:"type:varchar(64)" json:"sn"` //设备sn
  13. Network int `gorm:"type:int" json:"network"` //组网方式 0代表网关 1代表4G模块
  14. GatewayId int `gorm:"type:int" json:"gatewayId"` //所属网关
  15. ScreensBrand string `gorm:"type:varchar(60)" json:"screensBrand"` //屏幕品牌
  16. ScreensModel string `gorm:"type:varchar(60)" json:"screensModel"` //屏幕型号
  17. IPAddress string `gorm:"type:varchar(40)" json:"ipAddress"` //IP地址
  18. InstallTime time.Time `gorm:"type:date" json:"installTime"` //安装时间
  19. Shunt int `gorm:"type:int" json:"shunt"` //所属分路 1主路,2支路
  20. ShuntDescribe string `gorm:"type:varchar(60)" json:"shuntDescribe"` //分路描述
  21. ResolutionId int `gorm:"type:int" json:"resolutionId"` //分辨率
  22. ScreensSizeId int `gorm:"type:int" json:"screensSizeId"` //信息屏尺寸
  23. IsDeleted gorm.DeletedAt `gorm:"default:null" json:"isDeleted"` //是否删除
  24. Status int `gorm:"type:int;default:0" json:"status"` //在线状态 0=离线,1=在线
  25. PlayStatus int `gorm:"type:int;default:0" json:"playStatus"` //播放状态
  26. DisplayStatus int `gorm:"type:int;default:0" json:"displayStatus"` //显示模板状态
  27. SourceStatus int `gorm:"type:int;default:0" json:"sourceStatus"` //素材状态
  28. DayBright int `gorm:"type:int;default:100" json:"dayBright"` //白天亮度
  29. NightBright int `gorm:"type:int;default:30" json:"nightBright"` //晚上亮度
  30. GateWay GateWay `gorm:"foreignkey:GatewayId"`
  31. Resolution Resolution `gorm:"foreignkey:ResolutionId"`
  32. ScreensSize ScreensSize `gorm:"foreignkey:ScreensSizeId"`
  33. }
  34. func (Screens) TableName() string {
  35. return "dev_screens"
  36. }
  37. func (s Screens) DelScreens(id int) error {
  38. err := global.GVA_DB.Model(&s).Where("id = ?", id).Delete(&s).Error
  39. return err
  40. }
  41. func (s Screens) IsExistedByCode() error {
  42. err := global.GVA_DB.Model(&Screens{}).Where("screens_code = ?", s.ScreensCode).First(&s).Error
  43. return err
  44. }
  45. func (s Screens) AddScreens() error {
  46. err := global.GVA_DB.Model(&Screens{}).Create(&s).Error
  47. return err
  48. }
  49. func (s Screens) UpdateScreens() error {
  50. err := global.GVA_DB.Model(&s).
  51. Select("screens_name", "screens_code", "sn", "network", "gateway_id", "screens_brand", "screens_model", "ip_address", "install_time", "shunt", "shunt_describe", "resolution_id", "screens_size_id").
  52. Where("id=?", s.ID).
  53. Updates(map[string]interface{}{
  54. "screens_name": s.ScreensName,
  55. "screens_code": s.ScreensCode,
  56. "sn": s.Sn,
  57. "network": s.Network,
  58. "gateway_id": s.GatewayId,
  59. "screens_brand": s.ScreensBrand,
  60. "screens_model": s.ScreensModel,
  61. "ip_address": s.IPAddress,
  62. "install_time": s.InstallTime,
  63. "shunt": s.Shunt,
  64. "shunt_describe": s.ShuntDescribe,
  65. "resolution_id": s.ResolutionId,
  66. "screens_size_id": s.ScreensSizeId,
  67. }).Error
  68. return err
  69. }
  70. func QueryScreensInfoList(limit, offset int, keyword, shunt string) (screensList []Screens, total int64, err error) {
  71. db := global.GVA_DB.Model(&Screens{})
  72. if keyword != "" {
  73. db.Where("screens_name like ? or screens_code like ?", "%"+keyword+"%", "%"+keyword+"%")
  74. }
  75. if shunt != "" {
  76. db.Where("shunt = ?", shunt)
  77. }
  78. err = db.Count(&total).Error
  79. if err != nil {
  80. return
  81. }
  82. err = db.Limit(limit).Offset(offset).Preload("GateWay").Preload("Resolution").Preload("ScreensSize").Find(&screensList).Error
  83. return
  84. }
  85. func QueryScreensToDetail(id int) (screensList []Screens, err error) {
  86. db := global.GVA_DB.Model(&Screens{})
  87. err = db.Where("gateway_id = ?", id).Find(&screensList).Error
  88. return
  89. }
  90. func UpdateScreensStatusByGatewayId(id, status int) error {
  91. var screens Screens
  92. err := global.GVA_DB.Model(&screens).
  93. Select("status", "play_status", "display_status", "source_status").
  94. Where("gateway_id = ?", id).
  95. Updates(map[string]interface{}{
  96. "status": status,
  97. "play_status": status,
  98. "display_status": status,
  99. "source_status": status,
  100. }).Error
  101. return err
  102. }
  103. func UpdateScreensStatus(code string, sta request.DeviceStatus) error {
  104. var screens Screens
  105. return global.GVA_DB.Model(&screens).Select("status", "play_status", "display_status", "source_status").
  106. Where("screens_code = ?", code).Updates(map[string]interface{}{
  107. "status": sta.Status,
  108. "play_status": sta.PlayStatus,
  109. "display_status": sta.DisplayStatus,
  110. "source_status": sta.SourceStatus,
  111. }).Error
  112. }
  113. // 根据sn查询设备是否存在
  114. func QueryScreenBySn(sn string) (screens Screens, err error) {
  115. err = global.GVA_DB.Model(&screens).Where("sn = ?", sn).First(&screens).Error
  116. if err != nil {
  117. return Screens{}, err
  118. }
  119. return screens, nil
  120. }
  121. // 根据sn更新白天晚上亮度
  122. func (s Screens) UpdateBrightnessBySn(sn string, dayBright, nightBright int) error {
  123. err := global.GVA_DB.Model(&s).
  124. Select("day_bright", "night_bright").
  125. Where("sn = ?", sn).
  126. Updates(map[string]interface{}{
  127. "day_bright": dayBright,
  128. "night_bright": nightBright,
  129. }).Error
  130. return err
  131. }
  132. // 获取在线的led屏幕
  133. func (s Screens) QueryOnlineScreens() (screensList []Screens, err error) {
  134. err = global.GVA_DB.Model(&Screens{}).Where("status =?", 1).Find(&screensList).Error
  135. return
  136. }