dev_screens.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. )
  12. type ScreensService struct{}
  13. func (screensService *ScreensService) GetScreensInfoList(info request.PageInfo) (list interface{}, total int64, err error) {
  14. limit := info.PageSize
  15. offset := info.PageSize * (info.Page - 1)
  16. keyword := info.Keyword
  17. shunt := info.Shunt
  18. gatewayList, total, err := devices.QueryScreensInfoList(limit, offset, keyword, shunt)
  19. return gatewayList, total, err
  20. }
  21. func (screensService *ScreensService) QueryScreensParms() (list interface{}, err error) {
  22. resolution := devices.Resolution{}
  23. getResolution, err := resolution.GetResolution()
  24. screensSize := devices.ScreensSize{}
  25. getScreensSize, err := screensSize.GetScreensSize()
  26. way := devices.GateWay{}
  27. gatewayList, err := way.PublicGateway()
  28. params := model.RspParams{Resolution: getResolution, ScreensSize: getScreensSize, PubGateway: gatewayList}
  29. return params, err
  30. }
  31. func (screensService *ScreensService) DelScreens(id int) error {
  32. s := devices.Screens{}
  33. err := s.DelScreens(id)
  34. return err
  35. }
  36. func (screensService *ScreensService) AddScreens(screens devices.Screens) error {
  37. err := screens.IsExistedByCode()
  38. if !errors.Is(err, gorm.ErrRecordNotFound) {
  39. logger.Logger.Errorf("Create IsExistedByCode \n")
  40. return errors.New("设备编码已存在!")
  41. }
  42. err = screens.AddScreens()
  43. return err
  44. }
  45. func (screensService *ScreensService) UpdateScreens(screens devices.Screens) error {
  46. err := screens.UpdateScreens()
  47. return err
  48. }
  49. /**
  50. 以下是关于设备操作的一些业务方法
  51. */
  52. // 开关屏
  53. func (screensService *ScreensService) SwitchScreens(swatch promodel.SwitchScreens) error {
  54. //判断组网方式 0代表网关 1代表4G模块
  55. if swatch.Network == 1 {
  56. err := tcp.SwitchScreen(swatch.Sn, swatch.Flag)
  57. if err != nil {
  58. logger.Logger.Errorf("SwitchScreens faild \n")
  59. return errors.New("开关屏幕失败!")
  60. }
  61. } else {
  62. // TODO 通过mqtt发送指令开关屏
  63. return nil
  64. }
  65. return nil
  66. }
  67. // 发送内码文字
  68. func (screensService *ScreensService) SendInternalCode(sn string, content []promodel.InternalCodeContent) error {
  69. err := tcp.SendInternalCode(sn, content)
  70. if err != nil {
  71. logger.Logger.Errorf("SendInternalCode faild \n")
  72. return errors.New("发送内码文字失败!")
  73. }
  74. return nil
  75. }
  76. // 远程喊话
  77. func (screensService *ScreensService) VoiceBroad(sn string, content string) error {
  78. err := tcp.VoiceBroad(sn, content)
  79. if err != nil {
  80. logger.Logger.Errorf("SendInternalCode faild \n")
  81. return errors.New("远程喊话失败!")
  82. }
  83. return nil
  84. }