dev_screens.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. GatewayId int `gorm:"type:int" json:"gatewayId"` //所属网关
  13. ScreensBrand string `gorm:"type:varchar(60)" json:"screensBrand"` //屏幕品牌
  14. ScreensModel string `gorm:"type:varchar(60)" json:"screensModel"` //屏幕型号
  15. IPAddress string `gorm:"type:varchar(40)" json:"ipAddress"` //IP地址
  16. InstallTime time.Time `gorm:"type:date" json:"installTime"` //安装时间
  17. Shunt int `gorm:"type:int" json:"shunt"` //所属分路 1主路,2支路
  18. ShuntDescribe string `gorm:"type:varchar(60)" json:"shuntDescribe"` //分路描述
  19. ResolutionId int `gorm:"type:int" json:"resolutionId"` //分辨率
  20. ScreensSizeId int `gorm:"type:int" json:"screensSizeId"` //信息屏尺寸
  21. IsDeleted gorm.DeletedAt `gorm:"default:null" json:"isDeleted"` //是否删除
  22. Status int `gorm:"type:int;default:0" json:"status"` //在线状态 0=离线,1=在线
  23. PlayStatus int `gorm:"type:int;default:0" json:"playStatus"` //播放状态
  24. DisplayStatus int `gorm:"type:int;default:0" json:"displayStatus"` //显示模板状态
  25. SourceStatus int `gorm:"type:int;default:0" json:"sourceStatus"` //素材状态
  26. GateWay GateWay `gorm:"foreignkey:GatewayId"`
  27. Resolution Resolution `gorm:"foreignkey:ResolutionId"`
  28. ScreensSize ScreensSize `gorm:"foreignkey:ScreensSizeId"`
  29. }
  30. func (Screens) TableName() string {
  31. return "dev_screens"
  32. }
  33. func (s Screens) DelScreens(id int) error {
  34. err := global.GVA_DB.Model(&s).Where("id = ?", id).Delete(&s).Error
  35. return err
  36. }
  37. func (s Screens) IsExistedByCode() error {
  38. err := global.GVA_DB.Model(&Screens{}).Where("screens_code = ?", s.ScreensCode).First(&s).Error
  39. return err
  40. }
  41. func (s Screens) AddScreens() error {
  42. err := global.GVA_DB.Model(&Screens{}).Create(&s).Error
  43. return err
  44. }
  45. func (s Screens) UpdateScreens() error {
  46. err := global.GVA_DB.Model(&s).
  47. Select("screens_name", "screens_code", "gateway_id", "screens_brand", "screens_model", "ip_address", "install_time", "shunt", "shunt_describe", "resolution_id", "screens_size_id").
  48. Where("id=?", s.ID).
  49. Updates(map[string]interface{}{
  50. "screens_name": s.ScreensName,
  51. "screens_code": s.ScreensCode,
  52. "gateway_id": s.GatewayId,
  53. "screens_brand": s.ScreensBrand,
  54. "screens_model": s.ScreensModel,
  55. "ip_address": s.IPAddress,
  56. "install_time": s.InstallTime,
  57. "shunt": s.Shunt,
  58. "shunt_describe": s.ShuntDescribe,
  59. "resolution_id": s.ResolutionId,
  60. "screens_size_id": s.ScreensSizeId,
  61. }).Error
  62. return err
  63. }
  64. func QueryScreensInfoList(limit, offset int, keyword, shunt string) (screensList []Screens, total int64, err error) {
  65. db := global.GVA_DB.Model(&Screens{})
  66. if keyword != "" {
  67. db.Where("screens_name like ? or screens_code like ?", "%"+keyword+"%", "%"+keyword+"%")
  68. }
  69. if shunt != "" {
  70. db.Where("shunt = ?", shunt)
  71. }
  72. err = db.Count(&total).Error
  73. if err != nil {
  74. return
  75. }
  76. err = db.Limit(limit).Offset(offset).Preload("GateWay").Preload("Resolution").Preload("ScreensSize").Find(&screensList).Error
  77. return
  78. }
  79. func QueryScreensToDetail(id int) (screensList []Screens, err error) {
  80. db := global.GVA_DB.Model(&Screens{})
  81. err = db.Where("gateway_id = ?", id).Find(&screensList).Error
  82. return
  83. }
  84. func UpdateScreensStatusByGatewayId(id, status int) error {
  85. var screens Screens
  86. err := global.GVA_DB.Model(&screens).
  87. Select("status", "play_status", "display_status", "source_status").
  88. Where("gateway_id = ?", id).
  89. Updates(map[string]interface{}{
  90. "status": status,
  91. "play_status": status,
  92. "display_status": status,
  93. "source_status": status,
  94. }).Error
  95. return err
  96. }
  97. func UpdateScreensStatus(code string, sta request.DeviceStatus) error {
  98. var screens Screens
  99. //err := global.GVA_DB.Model(&screens).
  100. // Select("status").
  101. // Where("screens_code = ?", code).
  102. // Updates(map[string]interface{}{
  103. // "status": status,
  104. // }).Error
  105. //return err
  106. return global.GVA_DB.Model(&screens).Where("screens_code = ?", code).Updates(Screens{
  107. Status: sta.Status,
  108. PlayStatus: sta.PlayStatus,
  109. DisplayStatus: sta.DisplayStatus,
  110. SourceStatus: sta.SourceStatus,
  111. }).Error
  112. }
  113. func QueryAllScreens() (screensList []Screens) {
  114. _ = global.GVA_DB.Model(&Screens{}).Find(&screensList)
  115. return screensList
  116. }