english_report_email_pv.go 5.2 KB

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