package report import ( "encoding/json" logger "eta/eta_mini_ht_api/common/component/log" "eta/eta_mini_ht_api/common/contants" "eta/eta_mini_ht_api/domian/report" "eta/eta_mini_ht_api/models/eta" "eta/eta_mini_ht_api/models/ht" "eta/eta_mini_ht_api/task/base" "sync" ) var ( taskName base.TaskType = "ETAReportSyncTask" cron = "0/10 * * * * *" ) // Execute Task ETA取研报的数据 func (re *ReportTask) Execute(taskDetail *base.TaskDetail) error { logger.Info(contants.TaskFormat, "同步ETA研报库开始") var wg sync.WaitGroup wg.Add(2) //ETA报告 go func() { defer wg.Done() id, err := report.GetETALatestReportId() var etaReportList []eta.ETAReport etaReportList, err = eta.GetETAReports(id) if err != nil { logger.Error("获取ETA研报列表失败:%v", err) } if len(etaReportList) > 0 { var list []byte list, err = json.Marshal(etaReportList) if err == nil { taskDetail.Content = string(list) } err = report.SyncETAReportList(etaReportList) if err != nil { logger.Error("同步ETA研报列表失败:%v", err) } } logger.Info(contants.TaskFormat, "同步ETA研报库结束") }() //HT报告 go func() { defer wg.Done() id, err := report.GetHTLatestReportId() var htReportList []ht.HTReport htReportList, err = ht.GetHTReports(id) if err != nil { logger.Error("获取ETA研报列表失败:%v", err) } if len(htReportList) > 0 { var list []byte list, err = json.Marshal(htReportList) if err == nil { taskDetail.Content = string(list) } err = report.SyncHTReportList(htReportList) if err != nil { logger.Error("同步ETA研报列表失败:%v", err) } } logger.Info(contants.TaskFormat, "同步ETA研报库结束") }() wg.Wait() return nil } type ReportTask struct { } func init() { reportTask := base.NewTask(taskName, cron, new(ReportTask), base.FORBIDDEN) base.RegisterTask(&reportTask) }