english_report_email_log.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_yb_en_api/utils"
  6. "time"
  7. )
  8. const (
  9. EnglishReportEmailLogSourceAli = 1 // 来源-阿里云
  10. EnglishReportEmailLogSourceTencent = 2 // 来源-腾讯云
  11. EnglishReportEmailLogStatusIng = -1 // 推送状态-已发送
  12. EnglishReportEmailLogStatusFail = 0 // 推送状态-发送失败
  13. EnglishReportEmailLogStatusSuccess = 1 // 推送状态-发送成功
  14. )
  15. // EnglishReportEmailLog 英文研报-邮件推送记录
  16. type EnglishReportEmailLog struct {
  17. Id int `orm:"column(id);pk;auto" description:"邮箱ID"`
  18. ReportId int `description:"报告ID或者线上路演ID"`
  19. ReportType int `description:"类型:0英文研报,1英文线上路演"`
  20. EmailId int `description:"邮箱ID"`
  21. Email string `description:"邮箱地址"`
  22. SendData string `description:"请求信息"`
  23. Result string `description:"响应信息"`
  24. SendStatus int `description:"发送状态:-1-已发送(一个中间状态,重新推送时可能会产生这种状态);0-发送失败;1-发送成功"`
  25. CreateTime time.Time `description:"请求时间"`
  26. Source int `description:"服务商:1-阿里云;2-腾讯云"`
  27. IsDeleted int `description:"是否已删除: 0-正常; 1-已删除"`
  28. CallbackData string `description:"回调信息"`
  29. ErrMsg string `description:"错误信息(Result/CallbackData里面的取起来麻烦=_=!)"`
  30. }
  31. func (item *EnglishReportEmailLog) TableName() string {
  32. return "english_report_email_log"
  33. }
  34. func (item *EnglishReportEmailLog) Create() (err error) {
  35. o := orm.NewOrmUsingDB("rddp")
  36. _, err = o.Insert(item)
  37. return
  38. }
  39. func (item *EnglishReportEmailLog) Update(cols []string) (err error) {
  40. o := orm.NewOrmUsingDB("rddp")
  41. _, err = o.Update(item, cols...)
  42. return
  43. }
  44. func (item *EnglishReportEmailLog) InsertMulti(items []*EnglishReportEmailLog) (err error) {
  45. o := orm.NewOrmUsingDB("rddp")
  46. _, err = o.InsertMulti(len(items), items)
  47. return
  48. }
  49. // EnglishReportEmailLogPageListResp 英文研报-邮件推送记录分页列表响应体
  50. type EnglishReportEmailLogPageListResp struct {
  51. List []*EnglishReportEmailLogPageList `description:"列表数据"`
  52. Paging *paging.PagingItem `description:"分页数据"`
  53. }
  54. // EnglishReportEmailLogPageList 英文研报-邮件推送记录分页列表
  55. type EnglishReportEmailLogPageList struct {
  56. SendId int `description:"推送ID"`
  57. ReportId int `description:"报告ID"`
  58. EmailId int `description:"邮箱ID"`
  59. Email string `description:"邮箱地址"`
  60. ResultMsg string `description:"结果详情"`
  61. SendStatus int `description:"发送状态:-1-已发送;0-发送失败;1-发送成功"`
  62. Source int `description:"服务商:1-阿里云;2-腾讯云"`
  63. CreateTime string `description:"创建时间"`
  64. }
  65. // GetEnglishReportEmailLogPageList 获取日志列表-分页
  66. func GetEnglishReportEmailLogPageList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*EnglishReportEmailLog, err error) {
  67. o := orm.NewOrmUsingDB("rddp")
  68. sql := `SELECT * FROM english_report_email_log WHERE is_deleted = 0 `
  69. sql += condition
  70. if order != "" {
  71. sql += order
  72. } else {
  73. sql += ` ORDER BY send_status ASC, create_time DESC`
  74. }
  75. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  76. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  77. return
  78. }
  79. sql += ` LIMIT ?,?`
  80. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  81. return
  82. }
  83. // GetEnglishReportEmailLogById 主键获取日志
  84. func GetEnglishReportEmailLogById(id int) (item *EnglishReportEmailLog, err error) {
  85. o := orm.NewOrmUsingDB("rddp")
  86. sql := `SELECT * FROM english_report_email_log WHERE is_deleted = 0 AND id = ? LIMIT 1`
  87. err = o.Raw(sql, id).QueryRow(&item)
  88. return
  89. }
  90. // EnglishReportEmailLogFail 群发消息日志失败列表
  91. type EnglishReportEmailLogFail struct {
  92. HasFail int `description:"是否有失败记录: 0-无; 1-有"`
  93. ReportId int `description:"报告ID"`
  94. }
  95. // GetEnglishReportEmailLogFailList 获取群发消息日志失败列表
  96. func GetEnglishReportEmailLogFailList(reportType int) (list []*EnglishReportEmailLogFail, err error) {
  97. o := orm.NewOrmUsingDB("rddp")
  98. sql := `SELECT 1 AS has_fail, report_id FROM english_report_email_log WHERE report_type=? and is_deleted = 0 AND send_status = 0 GROUP BY report_id`
  99. _, err = o.Raw(sql, reportType).QueryRows(&list)
  100. return
  101. }
  102. // GetEnglishReportEmailLog 获取邮件推送日志
  103. func GetEnglishReportEmailLog(condition string, pars []interface{}) (item *EnglishReportEmailLog, err error) {
  104. o := orm.NewOrmUsingDB("rddp")
  105. sql := `SELECT * FROM english_report_email_log WHERE 1 = 1 `
  106. sql += condition
  107. sql += ` ORDER BY id DESC LIMIT 1`
  108. err = o.Raw(sql, pars).QueryRow(&item)
  109. return
  110. }
  111. // GetHasFailEmailLogReportIds 获取存在邮件推送失败记录的英文报告IDs
  112. func GetHasFailEmailLogReportIds() (reportIds []int, err error) {
  113. o := orm.NewOrmUsingDB("rddp")
  114. sql := `SELECT DISTINCT report_id FROM english_report_email_log WHERE is_deleted = 0 AND send_status = 0`
  115. _, err = o.Raw(sql).QueryRows(&reportIds)
  116. return
  117. }
  118. // GetSuccessEmailLogReportIds 获取邮件推送记录均为成功的英文报告IDs
  119. func GetSuccessEmailLogReportIds() (reportIds []int, err error) {
  120. o := orm.NewOrmUsingDB("rddp")
  121. sql := `SELECT DISTINCT report_id FROM english_report_email_log WHERE is_deleted = 0 AND (send_status != 0 AND send_status != -1)`
  122. _, err = o.Raw(sql).QueryRows(&reportIds)
  123. return
  124. }