dev_screens.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package devices
  2. import (
  3. "errors"
  4. "gorm.io/gorm"
  5. "server/dao/devices"
  6. promodel "server/model/common/devices"
  7. "server/model/common/request"
  8. model "server/model/devices"
  9. "server/service/tcp"
  10. "server/utils/logger"
  11. "time"
  12. )
  13. type ScreensService struct{}
  14. func (screensService *ScreensService) GetScreensInfoList(info request.PageInfo) (list interface{}, total int64, err error) {
  15. limit := info.PageSize
  16. offset := info.PageSize * (info.Page - 1)
  17. keyword := info.Keyword
  18. shunt := info.Shunt
  19. gatewayList, total, err := devices.QueryScreensInfoList(limit, offset, keyword, shunt)
  20. return gatewayList, total, err
  21. }
  22. func (screensService *ScreensService) QueryScreensParms() (list interface{}, err error) {
  23. resolution := devices.Resolution{}
  24. getResolution, err := resolution.GetResolution()
  25. screensSize := devices.ScreensSize{}
  26. getScreensSize, err := screensSize.GetScreensSize()
  27. way := devices.GateWay{}
  28. gatewayList, err := way.PublicGateway()
  29. params := model.RspParams{Resolution: getResolution, ScreensSize: getScreensSize, PubGateway: gatewayList}
  30. return params, err
  31. }
  32. func (screensService *ScreensService) DelScreens(id int) error {
  33. s := devices.Screens{}
  34. err := s.DelScreens(id)
  35. return err
  36. }
  37. func (screensService *ScreensService) AddScreens(screens devices.Screens) error {
  38. err := screens.IsExistedByCode()
  39. if !errors.Is(err, gorm.ErrRecordNotFound) {
  40. logger.Logger.Errorf("Create IsExistedByCode \n")
  41. return errors.New("设备编码已存在!")
  42. }
  43. err = screens.AddScreens()
  44. return err
  45. }
  46. func (screensService *ScreensService) UpdateScreens(screens devices.Screens) error {
  47. err := screens.UpdateScreens()
  48. return err
  49. }
  50. /**
  51. 以下是关于设备操作的一些业务方法
  52. */
  53. // 开关屏
  54. func (screensService *ScreensService) SwitchScreens(swatch promodel.SwitchScreens) error {
  55. //判断组网方式 0代表网关 1代表4G模块
  56. if swatch.Network == 1 {
  57. err := tcp.SwitchScreen(swatch.Sn, swatch.Flag)
  58. if err != nil {
  59. logger.Logger.Errorf("SwitchScreens faild \n")
  60. return errors.New("开关屏幕失败!")
  61. }
  62. } else {
  63. // TODO 通过mqtt发送指令开关屏
  64. return nil
  65. }
  66. return nil
  67. }
  68. // 发送内码文字
  69. func (screensService *ScreensService) SendInternalCode(sn string, content []promodel.InternalCodeContent) error {
  70. err := tcp.SendInternalCode(sn, content)
  71. if err != nil {
  72. logger.Logger.Errorf("SendInternalCode faild \n")
  73. return errors.New("发送内码文字失败!")
  74. }
  75. return nil
  76. }
  77. // 远程喊话
  78. func (screensService *ScreensService) VoiceBroad(sn string, content string) error {
  79. err := tcp.VoiceBroad(sn, content)
  80. if err != nil {
  81. logger.Logger.Errorf("SendInternalCode faild \n")
  82. return errors.New("远程喊话失败!")
  83. }
  84. return nil
  85. }
  86. func (screensService *ScreensService) SetBright(sb model.ReqBrightness) error {
  87. //先将白天、晚上亮度更新到数据库
  88. screens := devices.Screens{}
  89. err := screens.UpdateBrightnessBySn(sb.Sn, sb.DayBright, sb.NightBright)
  90. if err != nil {
  91. logger.Logger.Errorf("SetBright faild \n")
  92. return errors.New("亮度更新数据库失败!")
  93. }
  94. //判断当前时间是白天还是晚上(立马去更改当前所处时间的亮度)
  95. currentTime := time.Now()
  96. // 获取当前小时和分钟
  97. hour := currentTime.Hour()
  98. minute := currentTime.Minute()
  99. // 判断当前时间是否在 8:00 到 18:00 之间
  100. if (hour > 8 || (hour == 8 && minute >= 0)) && (hour < 18) {
  101. //白天
  102. err = tcp.SetBrightness(sb.Sn, sb.DayBright)
  103. if err != nil {
  104. logger.Logger.Errorf("SetBright[白天] faild \n")
  105. return errors.New("设置白天亮度失败!")
  106. }
  107. } else {
  108. //晚上
  109. err = tcp.SetBrightness(sb.Sn, sb.NightBright)
  110. if err != nil {
  111. logger.Logger.Errorf("SetBright[晚上] faild \n")
  112. return errors.New("设置晚上亮度失败!")
  113. }
  114. }
  115. return nil
  116. }