package message

import (
	logger "eta/eta_mini_ht_api/common/component/log"
	userService "eta/eta_mini_ht_api/domian/user"
	"eta/eta_mini_ht_api/task/base"
	"sync"
)

var (
	taskName base.TaskType = "NoticeTask"
	cron                   = "0/5 * * * * *"
)

// Execute Task ETA取研报的数据
func (au *NoticeTask) Execute(taskDetail *base.TaskDetail) (err error) {
	//logger.Info(contants.TaskFormat, "监听更新通知开始")
	metaInfoList := userService.GetInitMetaInfos()
	var wg sync.WaitGroup
	wg.Add(len(metaInfoList))
	for _, metaInfo := range metaInfoList {
		go func(metaInfo userService.MetaInfoDTO) {
			defer wg.Done()
			if !userService.PendingMetaInfo(metaInfo.Id) {
				return
			}
			msgErr := userService.CreateMessage(metaInfo)
			if msgErr != nil {
				logger.Error("生成消息失败:%v", err)
			}
		}(metaInfo)
	}
	//报告和媒体
	return
}

type NoticeTask struct {
}

func init() {
	reportTask := base.NewTask(taskName, cron, new(NoticeTask), base.DEV)
	base.RegisterTask(&reportTask)
}
