package main

import (
	"github.com/astaxie/beego"
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/notification/service"
	_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
	_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
	"time"
)

func main() {
	go func() {
		notificationService := service.NewNotificationService(nil)
		for {
			now := time.Now()
			next := now.Add(time.Hour * 24)
			nextZero := time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
			dispatchTicker := time.NewTimer(nextZero.Sub(now))
			<-dispatchTicker.C
			if _, err := notificationService.SystemNotificationNearThePlannedCompletionTimeTaskReceiver(); err != nil {
				println(err.Error())
			}
		}
	}()
	go func() {
		notificationService := service.NewNotificationService(nil)
		for {
			now := time.Now()
			next := now.Add(time.Hour * 24)
			nextZero := time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
			dispatchTicker := time.NewTimer(nextZero.Sub(now))
			<-dispatchTicker.C
			if _, err := notificationService.SystemNotificationNearBidEndTimeTaskSponsor(); err != nil {
				println(err.Error())
			}
		}
	}()

	// excel文件路径映射
	beego.SetStaticPath("/public", "public")

	beego.Run()
}