package worker import ( "film/config" "film/model" "film/worker/haha" "film/worker/nowcar" "github.com/go-co-op/gocron" log "github.com/sirupsen/logrus" "gitlab.com/jiangyong27/gobase/wxapi" "strings" "time" ) type Worker struct { qyClient *wxapi.WxQiye qyImpClient *wxapi.WxQiye hahaProcessor *haha.Processor } func (w *Worker) initQyWeixin() { cfg := config.GetConfig() w.qyClient = wxapi.NewQiye(&wxapi.QiyeConfig{ Corpid: cfg.Weixin.QiyeAppid, Secret: cfg.Weixin.Qiyesecret, Sender: cfg.Weixin.QiyeAgent, }) w.qyImpClient = wxapi.NewQiye(&wxapi.QiyeConfig{ Corpid: "ww288920bd3e8c92b2", Secret: "-RtxFJMwM0j_4QJbHrstHuLSIzMU1Q_euJSeWmhtOTM", Sender: "1000002", }) } func (w *Worker) Run() { timezone, _ := time.LoadLocation("Asia/Shanghai") cron := gocron.NewScheduler(timezone) w.initQyWeixin() newOrderChan := make(chan *model.Order, 100000) updateOrderChan := make(chan *model.Order, 100000) hahaSyncer := haha.NewSyncOrder(&haha.SyncOrderConfig{ Token: config.GetHahaConfig().Token, NewOrder: newOrderChan, UpdateOrder: updateOrderChan, }) cron.Every(config.GetHahaConfig().SyncInterval).Seconds().Do(func() { hahaSyncer.Sync() }) cron.Every(10).Seconds().Do(func() { nowcar.Sync() }) cron.StartAsync() for { select { case order := <-newOrderChan: if !strings.Contains(order.CinemaName, "大地影院") { continue } case updateOrder := <-updateOrderChan: log.Tracef("%s update", updateOrder.String()) } } }