diff --git a/internal/routes/standby/pjlink.go b/internal/routes/standby/pjlink.go index 767c89d..71e9c6c 100644 --- a/internal/routes/standby/pjlink.go +++ b/internal/routes/standby/pjlink.go @@ -7,6 +7,7 @@ import ( "game-driver/internal/schema" "game-driver/pkg/pjlink" "go.uber.org/zap" + "time" ) func PJLink(_ schema.WaitItemModel) func(c context.Context) error { @@ -21,14 +22,27 @@ func PJLink(_ schema.WaitItemModel) func(c context.Context) error { } zap.S().Infoln("打开投影仪结果:", resp) - <-c.Done() - - zap.S().Infoln("关闭待机投影仪") - resp, err = pjc.PowerOffSync() - if err != nil { - return fmt.Errorf("关闭投影仪异常: %w", err) + run := true + for run { + select { + case <-c.Done(): + zap.S().Infoln("关闭待机投影仪") + resp, err = pjc.PowerOffSync() + if err != nil { + return fmt.Errorf("关闭投影仪异常: %w", err) + } + zap.S().Infoln("关闭投影仪结果:", resp) + run = false + break + case <-time.After(time.Minute * 30): + zap.S().Infoln("轮询待机投影仪") + resp, err = pjc.PowerOnSync() + if err != nil { + return fmt.Errorf("轮询投影仪异常: %w", err) + } + zap.S().Infoln("轮询投影仪结果:", resp) + } } - zap.S().Infoln("关闭投影仪结果:", resp) return nil }