english_report_email_log.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  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 `gorm:"column:id;primaryKey;auto_increment:true" description:"邮箱日志ID"`
  18. ReportId int `gorm:"column:report_id" description:"报告ID或者线上路演ID"`
  19. ReportType int `gorm:"column:report_type" description:"类型:0英文研报,1英文线上路演"`
  20. EmailId int `gorm:"column:email_id" description:"邮箱ID"`
  21. Email string `gorm:"column:email" description:"邮箱地址"`
  22. SendData string `gorm:"column:send_data" description:"请求信息"`
  23. Result string `gorm:"column:result" description:"响应信息"`
  24. SendStatus int `gorm:"column:send_status" description:"发送状态:-1-已发送(一个中间状态,重新推送时可能会产生这种状态);0-发送失败;1-发送成功"`
  25. CreateTime time.Time `gorm:"column:create_time" description:"请求时间"`
  26. Source int `gorm:"column:source" description:"服务商:1-阿里云;2-腾讯云"`
  27. IsDeleted int `gorm:"column:is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
  28. CallbackData string `gorm:"column:callback_data" description:"回调信息"`
  29. ErrMsg string `gorm:"column:err_msg" description:"错误信息"`
  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. //id, e := o.Insert(item)
  37. //if e != nil {
  38. // err = e
  39. // return
  40. //}
  41. //item.Id = int(id)
  42. err = global.DmSQL["rddp"].Create(item).Error
  43. return
  44. }
  45. func (item *EnglishReportEmailLog) Update(cols []string) (err error) {
  46. //o := orm.NewOrmUsingDB("rddp")
  47. //_, err = o.Update(item, cols...)
  48. err = global.DmSQL["rddp"].Select(cols).Updates(item).Error
  49. return
  50. }
  51. func (item *EnglishReportEmailLog) InsertMulti(items []*EnglishReportEmailLog) (err error) {
  52. //o := orm.NewOrmUsingDB("rddp")
  53. //_, err = o.InsertMulti(len(items), items)
  54. err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
  55. return
  56. }
  57. // GetEnglishReportEmailLogList 获取日志列表
  58. func GetEnglishReportEmailLogList(condition string, pars []interface{}) (list []*EnglishReportEmailLog, err error) {
  59. //o := orm.NewOrmUsingDB("rddp")
  60. sql := `SELECT * FROM english_report_email_log WHERE is_deleted = 0 `
  61. if condition != `` {
  62. sql += condition
  63. }
  64. //_, err = o.Raw(sql, pars).QueryRows(&list)
  65. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&list).Error
  66. return
  67. }
  68. // EnglishReportEmailLogPageListResp 英文研报-邮件推送记录分页列表响应体
  69. type EnglishReportEmailLogPageListResp struct {
  70. List []*EnglishReportEmailLogPageList `description:"列表数据"`
  71. Paging *paging.PagingItem `description:"分页数据"`
  72. }
  73. // EnglishReportEmailLogPageList 英文研报-邮件推送记录分页列表
  74. type EnglishReportEmailLogPageList struct {
  75. SendId int `description:"推送ID"`
  76. ReportId int `description:"报告ID"`
  77. EmailId int `description:"邮箱ID"`
  78. Email string `description:"邮箱地址"`
  79. ResultMsg string `description:"结果详情"`
  80. SendStatus int `description:"发送状态:-1-已发送;0-发送失败;1-发送成功"`
  81. Source int `description:"服务商:1-阿里云;2-腾讯云"`
  82. CreateTime string `description:"创建时间"`
  83. }
  84. // GetEnglishReportEmailLogPageList 获取日志列表-分页
  85. func GetEnglishReportEmailLogPageList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*EnglishReportEmailLog, err error) {
  86. //o := orm.NewOrmUsingDB("rddp")
  87. sql := `SELECT * FROM english_report_email_log WHERE is_deleted = 0 `
  88. sql += condition
  89. if order != "" {
  90. sql += order
  91. } else {
  92. sql += ` ORDER BY send_status ASC, create_time DESC`
  93. }
  94. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  95. //if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  96. if err = global.DmSQL["rddp"].Raw(totalSQl, pars...).Scan(&total).Error; err != nil {
  97. return
  98. }
  99. sql += ` LIMIT ?,?`
  100. //_, err = o.Raw(sql, pars...).QueryRows(&list)
  101. pars = append(pars, startSize)
  102. pars = append(pars, pageSize)
  103. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&list).Error
  104. return
  105. }
  106. // GetEnglishReportEmailLogById 主键获取日志
  107. func GetEnglishReportEmailLogById(id int) (item *EnglishReportEmailLog, err error) {
  108. //o := orm.NewOrmUsingDB("rddp")
  109. sql := `SELECT * FROM english_report_email_log WHERE is_deleted = 0 AND id = ? LIMIT 1`
  110. //err = o.Raw(sql, id).QueryRow(&item)
  111. err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
  112. return
  113. }
  114. // DeleteEnglishReportEmailLogByIds IDs删除日志
  115. func DeleteEnglishReportEmailLogByIds(logIds []int) (err error) {
  116. if len(logIds) == 0 {
  117. return
  118. }
  119. //o := orm.NewOrmUsingDB("rddp")
  120. sql := `DELETE FROM english_report_email_log WHERE id IN (` + utils.GetOrmInReplace(len(logIds)) + `)`
  121. //sql := `UPDATE english_report_email_log SET is_deleted = 1 WHERE id IN (` + utils.GetOrmInReplace(len(logIds)) + `)`
  122. //_, err = o.Raw(sql, logIds).Exec()
  123. err = global.DmSQL["rddp"].Raw(sql, logIds).Exec(sql, logIds).Error
  124. return
  125. }
  126. // EnglishReportEmailLogFail 群发消息日志失败列表
  127. type EnglishReportEmailLogFail struct {
  128. HasFail int `description:"是否有失败记录: 0-无; 1-有"`
  129. ReportId int `description:"报告ID"`
  130. }
  131. // GetEnglishReportEmailLogFailList 获取群发消息日志失败列表
  132. func GetEnglishReportEmailLogFailList(reportType int) (list []*EnglishReportEmailLogFail, err error) {
  133. //o := orm.NewOrmUsingDB("rddp")
  134. 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`
  135. //_, err = o.Raw(sql, reportType).QueryRows(&list)
  136. err = global.DmSQL["rddp"].Raw(sql, reportType).Find(&list).Error
  137. return
  138. }
  139. // GetEnglishReportEmailLog 获取邮件推送日志
  140. func GetEnglishReportEmailLog(condition string, pars []interface{}) (item *EnglishReportEmailLog, err error) {
  141. //o := orm.NewOrmUsingDB("rddp")
  142. sql := `SELECT * FROM english_report_email_log WHERE 1 = 1 `
  143. sql += condition
  144. sql += ` ORDER BY id DESC LIMIT 1`
  145. //err = o.Raw(sql, pars).QueryRow(&item)
  146. err = global.DmSQL["rddp"].Raw(sql, pars...).First(&item).Error
  147. return
  148. }
  149. func (item *EnglishReportEmailLog) MultiUpdateResult(items []*EnglishReportEmailLog) (err error) {
  150. //o := orm.NewOrmUsingDB("rddp")
  151. //p, err := o.Raw("UPDATE english_report_email_log SET send_data = ?, result = ?, send_status = ?, err_msg = ? WHERE id = ?").Prepare()
  152. //if err != nil {
  153. // return
  154. //}
  155. //defer func() {
  156. // _ = p.Close()
  157. //}()
  158. //for _, v := range items {
  159. // _, err = p.Exec(v.SendData, v.Result, v.SendStatus, v.ErrMsg, v.Id)
  160. // if err != nil {
  161. // return
  162. // }
  163. //}
  164. tx := global.DmSQL["rddp"].Begin()
  165. for _, v := range items {
  166. err = tx.Exec("UPDATE english_report_email_log SET send_data = ?, result = ?, send_status = ?, err_msg = ? WHERE id = ?", v.SendData, v.Result, v.SendStatus, v.ErrMsg, v.Id).Error
  167. if err != nil {
  168. tx.Rollback()
  169. return
  170. }
  171. }
  172. tx.Commit()
  173. return
  174. }