english_report_email_pv.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package models
  2. import (
  3. sql2 "database/sql"
  4. "eta/eta_api/global"
  5. "eta/eta_api/utils"
  6. "time"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. )
  9. // EnglishReportEmailPV 英文研报-邮箱pv
  10. type EnglishReportEmailPV struct {
  11. Id int `gorm:"column:id;primaryKey;autoIncrement"`
  12. ReportId int `description:"英文报告ID"`
  13. EmailId int `description:"邮箱ID"`
  14. ReportType int `description:"类型:0英文研报,1英文线上路演"`
  15. CreateTime time.Time `description:"创建时间"`
  16. }
  17. func (item *EnglishReportEmailPV) TableName() string {
  18. return "english_report_email_pv"
  19. }
  20. func (item *EnglishReportEmailPV) Create() (err error) {
  21. err = global.DbMap[utils.DbNameReport].Create(item).Error
  22. return
  23. }
  24. // EnglishReportEmailPvPageListResp 分页列表响应体
  25. type EnglishReportEmailPvPageListResp struct {
  26. List []*EnglishReportEmailPvResp
  27. Paging *paging.PagingItem `description:"分页数据"`
  28. }
  29. type EnglishReportEmailUvPageListResp struct {
  30. List []*EnglishReportEmailUvResp
  31. Paging *paging.PagingItem `description:"分页数据"`
  32. }
  33. // EnglishReportEmailPvResp 邮箱响应体
  34. type EnglishReportEmailPvResp struct {
  35. Name string `description:"客户名称"`
  36. Email string `description:"邮箱地址"`
  37. ClickNum int `description:"点击量"`
  38. RecentClickTime string `description:"最近一次点击时间"`
  39. }
  40. type EnglishReportEmailUvResp struct {
  41. Name string `description:"客户名称"`
  42. Email string `description:"邮箱地址"`
  43. RecentClickTime string `description:"最近一次点击时间"`
  44. }
  45. // GetEnglishReportEmailPageList 获取邮箱pv列表-分页
  46. func GetEnglishReportEmailPvPageList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*EnglishReportEmailPvResp, err error) {
  47. o := global.DbMap[utils.DbNameReport]
  48. sql := `SELECT
  49. b.name,
  50. b.email,
  51. COUNT(a.id) AS click_num,
  52. MAX(a.create_time) AS recent_click_time
  53. FROM
  54. english_report_email_pv AS a
  55. JOIN english_report_email AS b ON a.email_id = b.id
  56. WHERE 1 = 1 `
  57. if condition != `` {
  58. sql += condition
  59. }
  60. sql += ` GROUP BY a.email_id `
  61. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  62. var totalNull sql2.NullInt64
  63. err = global.DbMap[utils.DbNameReport].Raw(totalSql, pars...).Scan(&totalNull).Error
  64. if err != nil {
  65. return
  66. }
  67. if totalNull.Valid {
  68. total = int(totalNull.Int64)
  69. }
  70. sql += ` ORDER BY recent_click_time DESC LIMIT ?,?`
  71. err = o.Raw(sql, pars, startSize, pageSize).Find(&list).Error
  72. return
  73. }
  74. // GetEnglishReportEmailUvPageList 获取邮箱uv列表-分页
  75. func GetEnglishReportEmailUvPageList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*EnglishReportEmailUvResp, err error) {
  76. o := global.DbMap[utils.DbNameReport]
  77. sql := `SELECT
  78. b.name,
  79. b.email,
  80. MAX(a.create_time) AS recent_click_time
  81. FROM
  82. english_report_email_pv AS a
  83. JOIN english_report_email AS b ON a.email_id = b.id
  84. WHERE 1 = 1 `
  85. if condition != `` {
  86. sql += condition
  87. }
  88. sql += ` GROUP BY a.email_id `
  89. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  90. var totalNull sql2.NullInt64
  91. err = global.DbMap[utils.DbNameReport].Raw(totalSql, pars...).Scan(&totalNull).Error
  92. if err != nil {
  93. return
  94. }
  95. if totalNull.Valid {
  96. total = int(totalNull.Int64)
  97. }
  98. sql += ` ORDER BY recent_click_time DESC LIMIT ?,?`
  99. err = o.Raw(sql, pars, startSize, pageSize).Find(&list).Error
  100. return
  101. }
  102. // EnglishEmailViewPageListResp 邮箱/联系人阅读分页列表响应体
  103. type EnglishEmailViewPageListResp struct {
  104. List []*EnglishEmailViewResp
  105. Paging *paging.PagingItem `description:"分页数据"`
  106. }
  107. // EnglishEmailViewResp 邮箱/联系人阅读数据响应体
  108. type EnglishEmailViewResp struct {
  109. ReportId int `description:"英文研报ID"`
  110. ClickType int `description:"类型:0英文研报,1英文线上路演"`
  111. ReportTitle string `description:"报告标题"`
  112. ReportType string `description:"报告类型"`
  113. ViewTotal int `description:"点击量"`
  114. LastViewTime string `description:"最近一次点击时间"`
  115. }
  116. // GetEnglishEmailViewPageList 获取英文邮箱/联系人阅读列表-分页
  117. func GetEnglishEmailViewPageList(condition string, pars []interface{}, orderRule string, startSize, pageSize int) (total int, list []*EnglishEmailViewResp, err error) {
  118. o := global.DbMap[utils.DbNameReport]
  119. sql := `SELECT
  120. report_id,
  121. report_type as click_type,
  122. COUNT(1) AS view_total,
  123. MAX(create_time) AS last_view_time
  124. FROM
  125. english_report_email_pv
  126. WHERE
  127. 1 = 1 `
  128. if condition != `` {
  129. sql += condition
  130. }
  131. sql += ` GROUP BY report_id, report_type`
  132. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  133. var totalNull sql2.NullInt64
  134. err = global.DbMap[utils.DbNameReport].Raw(totalSql, pars...).Scan(&totalNull).Error
  135. if err != nil {
  136. return
  137. }
  138. if totalNull.Valid {
  139. total = int(totalNull.Int64)
  140. }
  141. if orderRule != `` {
  142. sql += orderRule
  143. }
  144. sql += ` LIMIT ?,?`
  145. err = o.Raw(sql, pars, startSize, pageSize).Find(&list).Error
  146. return
  147. }