123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package services
- import (
- "context"
- "eta_gn/eta_task/models"
- "eta_gn/eta_task/services/alarm_msg"
- "eta_gn/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
- }
|