english_report_email_pv.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. // EnglishReportEmailPV 英文研报-邮箱pv
  8. type EnglishReportEmailPV struct {
  9. Id int `orm:"column(id);pk;auto"`
  10. ReportId int `description:"英文报告ID"`
  11. EmailId int `description:"邮箱ID"`
  12. ReportType int `description:"类型:0英文研报,1英文线上路演"`
  13. CreateTime time.Time `description:"创建时间"`
  14. }
  15. func (item *EnglishReportEmailPV) TableName() string {
  16. return "english_report_email_pv"
  17. }
  18. func (item *EnglishReportEmailPV) Create() (err error) {
  19. o := orm.NewOrmUsingDB("rddp")
  20. _, err = o.Insert(item)
  21. return
  22. }
  23. // EnglishReportEmailPvPageListResp 分页列表响应体
  24. type EnglishReportEmailPvPageListResp struct {
  25. List []*EnglishReportEmailPvResp
  26. Paging *paging.PagingItem `description:"分页数据"`
  27. }
  28. // EnglishReportEmailPvResp 邮箱响应体
  29. type EnglishReportEmailPvResp struct {
  30. Name string `description:"客户名称"`
  31. Email string `description:"邮箱地址"`
  32. ClickNum int `description:"点击量"`
  33. RecentClickTime string `description:"最近一次点击时间"`
  34. }
  35. // GetEnglishReportEmailPageList 获取邮箱pv列表-分页
  36. func GetEnglishReportEmailPvPageList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*EnglishReportEmailPvResp, err error) {
  37. o := orm.NewOrmUsingDB("rddp")
  38. sql := `SELECT
  39. b.name,
  40. b.email,
  41. COUNT(a.id) AS click_num,
  42. MAX(a.create_time) AS recent_click_time
  43. FROM
  44. english_report_email_pv AS a
  45. JOIN english_report_email AS b ON a.email_id = b.id
  46. WHERE 1 = 1 `
  47. if condition != `` {
  48. sql += condition
  49. }
  50. sql += ` GROUP BY a.email_id `
  51. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  52. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  53. return
  54. }
  55. sql += ` ORDER BY recent_click_time DESC LIMIT ?,?`
  56. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  57. return
  58. }
  59. // EnglishEmailViewPageListResp 邮箱/联系人阅读分页列表响应体
  60. type EnglishEmailViewPageListResp struct {
  61. List []*EnglishEmailViewResp
  62. Paging *paging.PagingItem `description:"分页数据"`
  63. }
  64. // EnglishEmailViewResp 邮箱/联系人阅读数据响应体
  65. type EnglishEmailViewResp struct {
  66. ReportId int `description:"英文研报ID"`
  67. ClickType int `description:"类型:0英文研报,1英文线上路演"`
  68. ReportTitle string `description:"报告标题"`
  69. ReportType string `description:"报告类型"`
  70. ViewTotal int `description:"点击量"`
  71. LastViewTime string `description:"最近一次点击时间"`
  72. }
  73. // todo GetEnglishEmailPageList 获取英文邮箱/联系人阅读列表-分页
  74. func GetEnglishEmailViewPageList(condition string, pars []interface{}, orderRule string, startSize, pageSize int) (total int, list []*EnglishEmailViewResp, err error) {
  75. o := orm.NewOrmUsingDB("rddp")
  76. sql := `SELECT
  77. report_id,
  78. report_type as click_type,
  79. COUNT(1) AS view_total,
  80. MAX(create_time) AS last_view_time
  81. FROM
  82. english_report_email_pv
  83. WHERE
  84. 1 = 1 `
  85. if condition != `` {
  86. sql += condition
  87. }
  88. sql += ` GROUP BY report_id, report_type`
  89. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  90. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  91. return
  92. }
  93. if orderRule != `` {
  94. sql += orderRule
  95. }
  96. sql += ` LIMIT ?,?`
  97. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  98. return
  99. }