english_report_email_pv.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. pars = append(pars, startSize, pageSize)
  72. err = o.Raw(sql, pars...).Find(&list).Error
  73. return
  74. }
  75. // GetEnglishReportEmailUvPageList 获取邮箱uv列表-分页
  76. func GetEnglishReportEmailUvPageList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*EnglishReportEmailUvResp, err error) {
  77. o := global.DbMap[utils.DbNameReport]
  78. sql := `SELECT
  79. b.name,
  80. b.email,
  81. MAX(a.create_time) AS recent_click_time
  82. FROM
  83. english_report_email_pv AS a
  84. JOIN english_report_email AS b ON a.email_id = b.id
  85. WHERE 1 = 1 `
  86. if condition != `` {
  87. sql += condition
  88. }
  89. sql += ` GROUP BY a.email_id `
  90. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  91. var totalNull sql2.NullInt64
  92. err = global.DbMap[utils.DbNameReport].Raw(totalSql, pars...).Scan(&totalNull).Error
  93. if err != nil {
  94. return
  95. }
  96. if totalNull.Valid {
  97. total = int(totalNull.Int64)
  98. }
  99. sql += ` ORDER BY recent_click_time DESC LIMIT ?,?`
  100. pars = append(pars, startSize, pageSize)
  101. err = o.Raw(sql, pars...).Find(&list).Error
  102. return
  103. }
  104. // EnglishEmailViewPageListResp 邮箱/联系人阅读分页列表响应体
  105. type EnglishEmailViewPageListResp struct {
  106. List []*EnglishEmailViewResp
  107. Paging *paging.PagingItem `description:"分页数据"`
  108. }
  109. // EnglishEmailViewResp 邮箱/联系人阅读数据响应体
  110. type EnglishEmailViewResp struct {
  111. ReportId int `description:"英文研报ID"`
  112. ClickType int `description:"类型:0英文研报,1英文线上路演"`
  113. ReportTitle string `description:"报告标题"`
  114. ReportType string `description:"报告类型"`
  115. ViewTotal int `description:"点击量"`
  116. LastViewTime string `description:"最近一次点击时间"`
  117. }
  118. // GetEnglishEmailViewPageList 获取英文邮箱/联系人阅读列表-分页
  119. func GetEnglishEmailViewPageList(condition string, pars []interface{}, orderRule string, startSize, pageSize int) (total int, list []*EnglishEmailViewResp, err error) {
  120. o := global.DbMap[utils.DbNameReport]
  121. sql := `SELECT
  122. report_id,
  123. report_type as click_type,
  124. COUNT(1) AS view_total,
  125. MAX(create_time) AS last_view_time
  126. FROM
  127. english_report_email_pv
  128. WHERE
  129. 1 = 1 `
  130. if condition != `` {
  131. sql += condition
  132. }
  133. sql += ` GROUP BY report_id, report_type`
  134. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  135. var totalNull sql2.NullInt64
  136. err = global.DbMap[utils.DbNameReport].Raw(totalSql, pars...).Scan(&totalNull).Error
  137. if err != nil {
  138. return
  139. }
  140. if totalNull.Valid {
  141. total = int(totalNull.Int64)
  142. }
  143. if orderRule != `` {
  144. sql += orderRule
  145. }
  146. sql += ` LIMIT ?,?`
  147. pars = append(pars, startSize, pageSize)
  148. err = o.Raw(sql, pars...).Find(&list).Error
  149. return
  150. }