english_report_email_pv.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package models
  2. import (
  3. "time"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  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. type EnglishReportEmailUvPageListResp struct {
  29. List []*EnglishReportEmailUvResp
  30. Paging *paging.PagingItem `description:"分页数据"`
  31. }
  32. // EnglishReportEmailPvResp 邮箱响应体
  33. type EnglishReportEmailPvResp struct {
  34. Name string `description:"客户名称"`
  35. Email string `description:"邮箱地址"`
  36. ClickNum int `description:"点击量"`
  37. RecentClickTime string `description:"最近一次点击时间"`
  38. }
  39. type EnglishReportEmailUvResp struct {
  40. Name string `description:"客户名称"`
  41. Email string `description:"邮箱地址"`
  42. RecentClickTime string `description:"最近一次点击时间"`
  43. }
  44. // GetEnglishReportEmailPageList 获取邮箱pv列表-分页
  45. func GetEnglishReportEmailPvPageList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*EnglishReportEmailPvResp, err error) {
  46. o := orm.NewOrmUsingDB("rddp")
  47. sql := `SELECT
  48. b.name,
  49. b.email,
  50. COUNT(a.id) AS click_num,
  51. MAX(a.create_time) AS recent_click_time
  52. FROM
  53. english_report_email_pv AS a
  54. JOIN english_report_email AS b ON a.email_id = b.id
  55. WHERE 1 = 1 `
  56. if condition != `` {
  57. sql += condition
  58. }
  59. sql += ` GROUP BY a.email_id `
  60. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  61. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  62. return
  63. }
  64. sql += ` ORDER BY recent_click_time DESC LIMIT ?,?`
  65. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  66. return
  67. }
  68. // GetEnglishReportEmailUvPageList 获取邮箱uv列表-分页
  69. func GetEnglishReportEmailUvPageList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*EnglishReportEmailUvResp, err error) {
  70. o := orm.NewOrmUsingDB("rddp")
  71. sql := `SELECT
  72. b.name,
  73. b.email,
  74. MAX(a.create_time) AS recent_click_time
  75. FROM
  76. english_report_email_pv AS a
  77. JOIN english_report_email AS b ON a.email_id = b.id
  78. WHERE 1 = 1 `
  79. if condition != `` {
  80. sql += condition
  81. }
  82. sql += ` GROUP BY a.email_id `
  83. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  84. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  85. return
  86. }
  87. sql += ` ORDER BY recent_click_time DESC LIMIT ?,?`
  88. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  89. return
  90. }
  91. // EnglishEmailViewPageListResp 邮箱/联系人阅读分页列表响应体
  92. type EnglishEmailViewPageListResp struct {
  93. List []*EnglishEmailViewResp
  94. Paging *paging.PagingItem `description:"分页数据"`
  95. }
  96. // EnglishEmailViewResp 邮箱/联系人阅读数据响应体
  97. type EnglishEmailViewResp struct {
  98. ReportId int `description:"英文研报ID"`
  99. ClickType int `description:"类型:0英文研报,1英文线上路演"`
  100. ReportTitle string `description:"报告标题"`
  101. ReportType string `description:"报告类型"`
  102. ViewTotal int `description:"点击量"`
  103. LastViewTime string `description:"最近一次点击时间"`
  104. }
  105. // todo GetEnglishEmailPageList 获取英文邮箱/联系人阅读列表-分页
  106. func GetEnglishEmailViewPageList(condition string, pars []interface{}, orderRule string, startSize, pageSize int) (total int, list []*EnglishEmailViewResp, err error) {
  107. o := orm.NewOrmUsingDB("rddp")
  108. sql := `SELECT
  109. report_id,
  110. report_type as click_type,
  111. COUNT(1) AS view_total,
  112. MAX(create_time) AS last_view_time
  113. FROM
  114. english_report_email_pv
  115. WHERE
  116. 1 = 1 `
  117. if condition != `` {
  118. sql += condition
  119. }
  120. sql += ` GROUP BY report_id, report_type`
  121. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  122. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  123. return
  124. }
  125. if orderRule != `` {
  126. sql += orderRule
  127. }
  128. sql += ` LIMIT ?,?`
  129. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  130. return
  131. }