123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- 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"
- "time"
- )
- 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
- }
- func (screensService *ScreensService) SetBright(sb model.ReqBrightness) error {
- //先将白天、晚上亮度更新到数据库
- screens := devices.Screens{}
- err := screens.UpdateBrightnessBySn(sb.Sn, sb.DayBright, sb.NightBright)
- if err != nil {
- logger.Logger.Errorf("SetBright faild \n")
- return errors.New("亮度更新数据库失败!")
- }
- //判断当前时间是白天还是晚上(立马去更改当前所处时间的亮度)
- currentTime := time.Now()
- // 获取当前小时和分钟
- hour := currentTime.Hour()
- minute := currentTime.Minute()
- // 判断当前时间是否在 8:00 到 18:00 之间
- if (hour > 8 || (hour == 8 && minute >= 0)) && (hour < 18) {
- //白天
- err = tcp.SetBrightness(sb.Sn, sb.DayBright)
- if err != nil {
- logger.Logger.Errorf("SetBright[白天] faild \n")
- return errors.New("设置白天亮度失败!")
- }
- } else {
- //晚上
- err = tcp.SetBrightness(sb.Sn, sb.NightBright)
- if err != nil {
- logger.Logger.Errorf("SetBright[晚上] faild \n")
- return errors.New("设置晚上亮度失败!")
- }
- }
- return nil
- }
|