english_report_email_log.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package models
  2. import (
  3. sql2 "database/sql"
  4. "eta/eta_api/global"
  5. "eta/eta_api/utils"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "time"
  8. )
  9. const (
  10. EnglishReportEmailLogSourceAli = 1 // 来源-阿里云
  11. EnglishReportEmailLogSourceTencent = 2 // 来源-腾讯云
  12. EnglishReportEmailLogStatusIng = -1 // 推送状态-已发送
  13. EnglishReportEmailLogStatusFail = 0 // 推送状态-发送失败
  14. EnglishReportEmailLogStatusSuccess = 1 // 推送状态-发送成功
  15. )
  16. // EnglishReportEmailLog 英文研报-邮件推送记录
  17. type EnglishReportEmailLog struct {
  18. Id int `gorm:"column:id;primaryKey" description:"邮箱ID"`
  19. ReportId int `description:"报告ID或者线上路演ID"`
  20. ReportType int `description:"类型:0英文研报,1英文线上路演"`
  21. EmailId int `description:"邮箱ID"`
  22. Email string `description:"邮箱地址"`
  23. SendData string `description:"请求信息"`
  24. Result string `description:"响应信息"`
  25. SendStatus int `description:"发送状态:-1-已发送(一个中间状态,重新推送时可能会产生这种状态);0-发送失败;1-发送成功"`
  26. CreateTime time.Time `description:"请求时间"`
  27. Source int `description:"服务商:1-阿里云;2-腾讯云"`
  28. IsDeleted int `description:"是否已删除: 0-正常; 1-已删除"`
  29. CallbackData string `description:"回调信息"`
  30. ErrMsg string `description:"错误信息"`
  31. }
  32. func (item *EnglishReportEmailLog) TableName() string {
  33. return "english_report_email_log"
  34. }
  35. func (item *EnglishReportEmailLog) Create() (err error) {
  36. err = global.DbMap[utils.DbNameReport].Create(item).Error
  37. return
  38. }
  39. func (item *EnglishReportEmailLog) Update(cols []string) (err error) {
  40. err = global.DbMap[utils.DbNameReport].Select(cols).Updates(item).Error
  41. return
  42. }
  43. func (item *EnglishReportEmailLog) InsertMulti(items []*EnglishReportEmailLog) (err error) {
  44. o := global.DbMap[utils.DbNameReport]
  45. err = o.CreateInBatches(items, utils.MultiAddNum).Error
  46. return
  47. }
  48. // GetEnglishReportEmailLogList 获取日志列表
  49. func GetEnglishReportEmailLogList(condition string, pars []interface{}) (list []*EnglishReportEmailLog, err error) {
  50. o := global.DbMap[utils.DbNameReport]
  51. sql := `SELECT * FROM english_report_email_log WHERE is_deleted = 0 `
  52. if condition != `` {
  53. sql += condition
  54. }
  55. err = o.Raw(sql, pars...).Find(&list).Error
  56. return
  57. }
  58. // EnglishReportEmailLogPageListResp 英文研报-邮件推送记录分页列表响应体
  59. type EnglishReportEmailLogPageListResp struct {
  60. List []*EnglishReportEmailLogPageList `description:"列表数据"`
  61. Paging *paging.PagingItem `description:"分页数据"`
  62. }
  63. // EnglishReportEmailLogPageList 英文研报-邮件推送记录分页列表
  64. type EnglishReportEmailLogPageList struct {
  65. SendId int `description:"推送ID"`
  66. ReportId int `description:"报告ID"`
  67. EmailId int `description:"邮箱ID"`
  68. Email string `description:"邮箱地址"`
  69. ResultMsg string `description:"结果详情"`
  70. SendStatus int `description:"发送状态:-1-已发送;0-发送失败;1-发送成功"`
  71. Source int `description:"服务商:1-阿里云;2-腾讯云"`
  72. CreateTime string `description:"创建时间"`
  73. }
  74. // GetEnglishReportEmailLogPageList 获取日志列表-分页
  75. func GetEnglishReportEmailLogPageList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*EnglishReportEmailLog, err error) {
  76. o := global.DbMap[utils.DbNameReport]
  77. sql := `SELECT * FROM english_report_email_log WHERE is_deleted = 0 `
  78. sql += condition
  79. if order != "" {
  80. sql += order
  81. } else {
  82. sql += ` ORDER BY send_status ASC, create_time DESC`
  83. }
  84. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  85. var totalNull sql2.NullInt64
  86. err = global.DbMap[utils.DbNameReport].Raw(totalSql, pars...).Scan(&totalNull).Error
  87. if err != nil {
  88. return
  89. }
  90. if totalNull.Valid {
  91. total = int(totalNull.Int64)
  92. }
  93. sql += ` LIMIT ?,?`
  94. pars = append(pars, startSize, pageSize)
  95. err = o.Raw(sql, pars...).Find(&list).Error
  96. return
  97. }
  98. // GetEnglishReportEmailLogById 主键获取日志
  99. func GetEnglishReportEmailLogById(id int) (item *EnglishReportEmailLog, err error) {
  100. o := global.DbMap[utils.DbNameReport]
  101. sql := `SELECT * FROM english_report_email_log WHERE is_deleted = 0 AND id = ? LIMIT 1`
  102. err = o.Raw(sql, id).First(&item).Error
  103. return
  104. }
  105. // DeleteEnglishReportEmailLogByIds IDs删除日志
  106. func DeleteEnglishReportEmailLogByIds(logIds []int) (err error) {
  107. if len(logIds) == 0 {
  108. return
  109. }
  110. o := global.DbMap[utils.DbNameReport]
  111. sql := `DELETE FROM english_report_email_log WHERE id IN (` + utils.GetOrmInReplace(len(logIds)) + `)`
  112. //sql := `UPDATE english_report_email_log SET is_deleted = 1 WHERE id IN (` + utils.GetOrmInReplace(len(logIds)) + `)`
  113. err = o.Exec(sql, logIds).Error
  114. return
  115. }
  116. // EnglishReportEmailLogFail 群发消息日志失败列表
  117. type EnglishReportEmailLogFail struct {
  118. HasFail int `description:"是否有失败记录: 0-无; 1-有"`
  119. ReportId int `description:"报告ID"`
  120. }
  121. // GetEnglishReportEmailLogFailList 获取群发消息日志失败列表
  122. func GetEnglishReportEmailLogFailList(reportType int) (list []*EnglishReportEmailLogFail, err error) {
  123. o := global.DbMap[utils.DbNameReport]
  124. 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`
  125. err = o.Raw(sql, reportType).Find(&list).Error
  126. return
  127. }
  128. // GetEnglishReportEmailLog 获取邮件推送日志
  129. func GetEnglishReportEmailLog(condition string, pars []interface{}) (item *EnglishReportEmailLog, err error) {
  130. o := global.DbMap[utils.DbNameReport]
  131. sql := `SELECT * FROM english_report_email_log WHERE 1 = 1 `
  132. sql += condition
  133. sql += ` ORDER BY id DESC LIMIT 1`
  134. err = o.Raw(sql, pars...).First(&item).Error
  135. return
  136. }
  137. func (item *EnglishReportEmailLog) MultiUpdateResult(items []*EnglishReportEmailLog) (err error) {
  138. o := global.DbMap[utils.DbNameReport]
  139. sql := "UPDATE english_report_email_log SET send_data = ?, result = ?, send_status = ?, err_msg = ? WHERE id = ?"
  140. for _, v := range items {
  141. err = o.Exec(sql, v.SendData, v.Result, v.SendStatus, v.ErrMsg, v.Id).Error
  142. if err != nil {
  143. return
  144. }
  145. }
  146. return
  147. }