2023-04-09 02:11:58 +08:00
|
|
|
package worker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"film/config"
|
|
|
|
"film/model"
|
|
|
|
"film/worker/haha"
|
2024-04-27 23:12:44 +08:00
|
|
|
"film/worker/nowcar"
|
|
|
|
"github.com/go-co-op/gocron"
|
2023-04-09 02:11:58 +08:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"gitlab.com/jiangyong27/gobase/wxapi"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Worker struct {
|
2023-04-09 11:38:19 +08:00
|
|
|
qyClient *wxapi.WxQiye
|
2023-04-09 17:47:46 +08:00
|
|
|
qyImpClient *wxapi.WxQiye
|
2023-04-09 11:38:19 +08:00
|
|
|
hahaProcessor *haha.Processor
|
2023-04-09 02:11:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
})
|
2023-04-09 17:47:46 +08:00
|
|
|
w.qyImpClient = wxapi.NewQiye(&wxapi.QiyeConfig{
|
|
|
|
Corpid: "ww288920bd3e8c92b2",
|
|
|
|
Secret: "-RtxFJMwM0j_4QJbHrstHuLSIzMU1Q_euJSeWmhtOTM",
|
|
|
|
Sender: "1000002",
|
|
|
|
})
|
2023-04-09 02:11:58 +08:00
|
|
|
}
|
2023-04-09 11:38:19 +08:00
|
|
|
|
2023-04-09 02:11:58 +08:00
|
|
|
func (w *Worker) Run() {
|
2024-04-27 23:12:44 +08:00
|
|
|
timezone, _ := time.LoadLocation("Asia/Shanghai")
|
|
|
|
cron := gocron.NewScheduler(timezone)
|
|
|
|
|
2023-04-09 02:11:58 +08:00
|
|
|
w.initQyWeixin()
|
|
|
|
newOrderChan := make(chan *model.Order, 100000)
|
|
|
|
updateOrderChan := make(chan *model.Order, 100000)
|
|
|
|
hahaSyncer := haha.NewSyncOrder(&haha.SyncOrderConfig{
|
2024-04-27 23:12:44 +08:00
|
|
|
Token: config.GetHahaConfig().Token,
|
|
|
|
NewOrder: newOrderChan,
|
|
|
|
UpdateOrder: updateOrderChan,
|
2023-04-09 02:11:58 +08:00
|
|
|
})
|
|
|
|
|
2024-04-27 23:12:44 +08:00
|
|
|
cron.Every(config.GetHahaConfig().SyncInterval).Seconds().Do(func() {
|
|
|
|
hahaSyncer.Sync()
|
|
|
|
})
|
2023-04-09 02:11:58 +08:00
|
|
|
|
2024-05-08 18:58:51 +08:00
|
|
|
var nc nowcar.Nowcar
|
|
|
|
var ddf nowcar.Ddf
|
2024-04-27 23:13:32 +08:00
|
|
|
cron.Every(10).Seconds().Do(func() {
|
2024-05-08 18:58:51 +08:00
|
|
|
nc.Sync()
|
|
|
|
})
|
|
|
|
cron.Every(10).Seconds().Do(func() {
|
|
|
|
ddf.Sync()
|
2024-04-27 23:12:44 +08:00
|
|
|
})
|
2023-04-09 13:01:04 +08:00
|
|
|
|
2024-04-27 23:12:44 +08:00
|
|
|
cron.StartAsync()
|
2023-04-09 17:47:46 +08:00
|
|
|
|
2023-04-09 02:11:58 +08:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case order := <-newOrderChan:
|
|
|
|
if !strings.Contains(order.CinemaName, "大地影院") {
|
|
|
|
continue
|
|
|
|
}
|
2023-04-09 12:16:09 +08:00
|
|
|
|
2023-04-09 02:11:58 +08:00
|
|
|
case updateOrder := <-updateOrderChan:
|
2023-04-09 12:16:09 +08:00
|
|
|
log.Tracef("%s update", updateOrder.String())
|
2023-04-09 15:59:56 +08:00
|
|
|
|
2023-04-09 02:11:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|