english_report_email_pv.go 4.9 KB

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