english_report.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package services
  2. import (
  3. "context"
  4. "eta/eta_task/models"
  5. "eta/eta_task/services/alarm_msg"
  6. "eta/eta_task/utils"
  7. "fmt"
  8. "html"
  9. "strconv"
  10. "time"
  11. )
  12. // PublishEnglishReport 定时发布英文研报-每分钟
  13. func PublishEnglishReport(cont context.Context) (err error) {
  14. defer func() {
  15. if err != nil {
  16. go alarm_msg.SendAlarmMsg("PublishEnglishReport-定时发布英文研报失败, ErrMsg:\n"+err.Error(), 3)
  17. }
  18. }()
  19. // 获取所有未发布的语音播报
  20. now := time.Now().Format(utils.FormatDateTimeMinute)
  21. startTime := now + ":00"
  22. endTime := now + ":59"
  23. afterDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate) //限制一下,只查询最近一个月的
  24. list, err := models.GetPrePublishedEnglishReports(startTime, endTime, afterDate)
  25. if err != nil {
  26. return
  27. }
  28. listLen := len(list)
  29. if listLen == 0 {
  30. return
  31. }
  32. // 比对时间(分钟),时间相等则发布并推送
  33. for i := 0; i < listLen; i++ {
  34. item := list[i]
  35. publishTime := time.Now().Format(utils.FormatDateTime)
  36. if item.PublishTime != "" {
  37. // 发布时间固定为首次发布时间
  38. publishTime = item.PublishTime
  39. }
  40. if err = models.PublishEnglishReportById(item.Id, publishTime); err != nil {
  41. return
  42. }
  43. go func() {
  44. _ = UpdateEnglishReportEs(item.Id, 2)
  45. }()
  46. }
  47. return
  48. }
  49. // UpdateEnglishReportEs 更新英文报告/章节Es
  50. func UpdateEnglishReportEs(reportId int, publishState int) (err error) {
  51. if reportId <= 0 {
  52. return
  53. }
  54. reportInfo, err := models.GetEnglishReportById(reportId)
  55. if err != nil {
  56. return
  57. }
  58. // 新增报告ES
  59. esReport := &models.ElasticEnglishReportDetail{
  60. Id: strconv.Itoa(reportInfo.Id),
  61. ReportId: reportInfo.Id,
  62. Title: reportInfo.Title,
  63. Abstract: reportInfo.Abstract,
  64. BodyContent: utils.TrimHtml(html.UnescapeString(reportInfo.Content)),
  65. PublishTime: reportInfo.PublishTime,
  66. CreateTime: reportInfo.CreateTime,
  67. ReportCode: reportInfo.ReportCode,
  68. PublishState: publishState,
  69. Author: reportInfo.Author,
  70. Frequency: reportInfo.Frequency,
  71. ClassifyIdFirst: reportInfo.ClassifyIdFirst,
  72. ClassifyNameFirst: reportInfo.ClassifyNameFirst,
  73. ClassifyIdSecond: reportInfo.ClassifyIdSecond,
  74. ClassifyNameSecond: reportInfo.ClassifyNameSecond,
  75. StageStr: strconv.Itoa(reportInfo.Stage),
  76. Overview: utils.TrimHtml(html.UnescapeString(reportInfo.Overview)),
  77. ContentSub: utils.TrimHtml(html.UnescapeString(reportInfo.ContentSub)),
  78. }
  79. docId := fmt.Sprintf("%d", reportInfo.Id)
  80. if err = EsAddOrEditEnglishReport(utils.EsEnglishReportIndexName, docId, esReport); err != nil {
  81. return
  82. }
  83. return
  84. }