package services import ( "context" "eta/eta_task/models" "eta/eta_task/services/alarm_msg" "eta/eta_task/utils" "fmt" "html" "strconv" "time" ) // PublishEnglishReport 定时发布英文研报-每分钟 func PublishEnglishReport(cont context.Context) (err error) { defer func() { if err != nil { go alarm_msg.SendAlarmMsg("PublishEnglishReport-定时发布英文研报失败, ErrMsg:\n"+err.Error(), 3) } }() // 获取所有未发布的语音播报 now := time.Now().Format(utils.FormatDateTimeMinute) startTime := now + ":00" endTime := now + ":59" afterDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate) //限制一下,只查询最近一个月的 list, err := models.GetPrePublishedEnglishReports(startTime, endTime, afterDate) if err != nil { return } listLen := len(list) if listLen == 0 { return } // 比对时间(分钟),时间相等则发布并推送 for i := 0; i < listLen; i++ { item := list[i] publishTime := time.Now().Format(utils.FormatDateTime) if item.PublishTime != "" { // 发布时间固定为首次发布时间 publishTime = item.PublishTime } if err = models.PublishEnglishReportById(item.Id, publishTime); err != nil { return } go func() { _ = UpdateEnglishReportEs(item.Id, 2) }() } return } // UpdateEnglishReportEs 更新英文报告/章节Es func UpdateEnglishReportEs(reportId int, publishState int) (err error) { if reportId <= 0 { return } reportInfo, err := models.GetEnglishReportById(reportId) if err != nil { return } // 新增报告ES esReport := &models.ElasticEnglishReportDetail{ Id: strconv.Itoa(reportInfo.Id), ReportId: reportInfo.Id, Title: reportInfo.Title, Abstract: reportInfo.Abstract, BodyContent: utils.TrimHtml(html.UnescapeString(reportInfo.Content)), PublishTime: reportInfo.PublishTime, CreateTime: reportInfo.CreateTime, ReportCode: reportInfo.ReportCode, PublishState: publishState, Author: reportInfo.Author, Frequency: reportInfo.Frequency, ClassifyIdFirst: reportInfo.ClassifyIdFirst, ClassifyNameFirst: reportInfo.ClassifyNameFirst, ClassifyIdSecond: reportInfo.ClassifyIdSecond, ClassifyNameSecond: reportInfo.ClassifyNameSecond, StageStr: strconv.Itoa(reportInfo.Stage), Overview: utils.TrimHtml(html.UnescapeString(reportInfo.Overview)), ContentSub: utils.TrimHtml(html.UnescapeString(reportInfo.ContentSub)), } docId := fmt.Sprintf("%d", reportInfo.Id) if err = EsAddOrEditEnglishReport(utils.EsEnglishReportIndexName, docId, esReport); err != nil { return } return }