package devices import ( "errors" "gorm.io/gorm" "server/dao/devices" promodel "server/model/common/devices" "server/model/common/request" model "server/model/devices" "server/service/tcp" "server/utils/logger" ) type ScreensService struct{} func (screensService *ScreensService) GetScreensInfoList(info request.PageInfo) (list interface{}, total int64, err error) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) keyword := info.Keyword shunt := info.Shunt gatewayList, total, err := devices.QueryScreensInfoList(limit, offset, keyword, shunt) return gatewayList, total, err } func (screensService *ScreensService) QueryScreensParms() (list interface{}, err error) { resolution := devices.Resolution{} getResolution, err := resolution.GetResolution() screensSize := devices.ScreensSize{} getScreensSize, err := screensSize.GetScreensSize() way := devices.GateWay{} gatewayList, err := way.PublicGateway() params := model.RspParams{Resolution: getResolution, ScreensSize: getScreensSize, PubGateway: gatewayList} return params, err } func (screensService *ScreensService) DelScreens(id int) error { s := devices.Screens{} err := s.DelScreens(id) return err } func (screensService *ScreensService) AddScreens(screens devices.Screens) error { err := screens.IsExistedByCode() if !errors.Is(err, gorm.ErrRecordNotFound) { logger.Logger.Errorf("Create IsExistedByCode \n") return errors.New("设备编码已存在!") } err = screens.AddScreens() return err } func (screensService *ScreensService) UpdateScreens(screens devices.Screens) error { err := screens.UpdateScreens() return err } /** 以下是关于设备操作的一些业务方法 */ // 开关屏 func (screensService *ScreensService) SwitchScreens(swatch promodel.SwitchScreens) error { //判断组网方式 0代表网关 1代表4G模块 if swatch.Network == 1 { err := tcp.SwitchScreen(swatch.Sn, swatch.Flag) if err != nil { logger.Logger.Errorf("SwitchScreens faild \n") return errors.New("开关屏幕失败!") } } else { // TODO 通过mqtt发送指令开关屏 return nil } return nil } // 发送内码文字 func (screensService *ScreensService) SendInternalCode(sn string, content []promodel.InternalCodeContent) error { err := tcp.SendInternalCode(sn, content) if err != nil { logger.Logger.Errorf("SendInternalCode faild \n") return errors.New("发送内码文字失败!") } return nil } // 远程喊话 func (screensService *ScreensService) VoiceBroad(sn string, content string) error { err := tcp.VoiceBroad(sn, content) if err != nil { logger.Logger.Errorf("SendInternalCode faild \n") return errors.New("远程喊话失败!") } return nil }