package handler

import (
	"fengkuangGameServerJob/service"
	"log"
	"time"
)

// StationRobotJob 跑商机器人定时任务的脚本
type StationRobotJob struct {
	running bool
}

func NewStationRobotJob() *StationRobotJob {
	return &StationRobotJob{
		running: false,
	}
}

func (s *StationRobotJob) Specs() []string {
	return []string{EveryMorningAt5}
}

func (s *StationRobotJob) Enable() bool {
	return true
}

func (s *StationRobotJob) Run() {
	defer catchJobPanic()
	if s.running == true {
		return
	}
	s.running = true
	defer func() {
		s.running = false
	}()
	handlerJobRun(s)
}

func (s *StationRobotJob) jobContent() {
	stationService := service.NewStationService()
	//1 获取区服列表
	tcpIds := stationService.GetTcpList()
	for _, tcpId := range tcpIds {
		// 操作单服的机器人
		err := stationService.DoSingleTcpStation(tcpId, true)
		if err != nil {
			log.Println("跑商发生异常:" + err.Error())
			return
		}
		time.Sleep(time.Second)
	}
}
