report_push.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package services
  2. import (
  3. "fmt"
  4. "hongze/hz_eta_api/models"
  5. "hongze/hz_eta_api/services/alarm_msg"
  6. "hongze/hz_eta_api/utils"
  7. "strconv"
  8. "time"
  9. )
  10. //func init() {
  11. // report, _ := models.GetReportById(572)
  12. // SendReportToThs(report)
  13. //}
  14. // SendReportToEmail 发送报告邮件
  15. func SendReportToEmail(report *models.ReportDetail) (err error) {
  16. if utils.SystemType == "custom" {
  17. // 客户不做报告邮件推送
  18. return
  19. }
  20. fmt.Println("SendReportToEmail")
  21. defer func() {
  22. if err != nil {
  23. //fmt.Println(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送消息至同花顺失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  24. go alarm_msg.SendAlarmMsg("发送报告至邮件失败,SendReportToEmail ErrMsg:"+err.Error(), 3)
  25. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "SendReportToEmail ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  26. }
  27. }()
  28. toUser := ``
  29. jumpUrl := ``
  30. if utils.RunMode == "debug" {
  31. //toUser = `glji@hzinsights.com`
  32. toUser = `317699326@qq.com`
  33. jumpUrl = "http://rddpweb.brilliantstart.cn/reportdtl?id=1578" + strconv.Itoa(report.Id)
  34. } else {
  35. toUser = "lijun011112@gtjas.com"
  36. jumpUrl = "https://ficc.hzinsights.com/reportdtl?id=" + strconv.Itoa(report.Id)
  37. }
  38. createDate, err := time.Parse(utils.FormatDateTime, report.CreateTime)
  39. createDateFrom := createDate.Format("060102")
  40. emailBody :=
  41. `<!DOCTYPE html>
  42. <html lang="en">
  43. <head>
  44. <meta charset="UTF-8">
  45. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  46. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  47. <title>Email</title>
  48. </head>
  49. <body>
  50. <div>
  51. <h2 style="font-size: 16px;">弘则研报:<span>` + report.Title + "_" + createDateFrom + `</span><span></span></h2>
  52. <div style="font-size: 14px;margin-left: 40px;">
  53. <p>你好,</p>
  54. <p>今日报告已推送。</p>
  55. <p><span>报告类型:</span><span>` + report.ClassifyNameFirst + `</span></p>
  56. <p><span>报告标题:</span><span>` + report.Title + `</span></p>
  57. <p><span>报告链接:</span><a href="` + jumpUrl + `">弘则研究</a></p>
  58. </div>
  59. </div>
  60. </body>
  61. </html>`
  62. fmt.Println("start SendReportToEmail")
  63. result, err := utils.SendEmailByHz("弘则研报报告", emailBody, toUser)
  64. fmt.Println("send result:", result, err)
  65. return
  66. }
  67. // SendReportMiniToThs 发送报告-研报小程序到同花顺
  68. func SendReportMiniToThs(report *models.ReportDetail) (err error) {
  69. defer func() {
  70. if err != nil {
  71. go alarm_msg.SendAlarmMsg("SendReportMiniToThs 发送报告-研报小程序到同花顺失败, ReportId:"+strconv.Itoa(report.Id)+", ErrMsg:"+err.Error(), 3)
  72. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "SendReportMiniToThs发送报告至同花顺失败, ReportId:" + strconv.Itoa(report.Id) + ", ErrMsg:" + err.Error(), utils.EmailSendToUsers)
  73. }
  74. }()
  75. if report.HasChapter == 0 {
  76. go SendReportToEmail(report)
  77. }
  78. return
  79. }