user_view_history.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_mobile_admin/utils"
  5. "time"
  6. )
  7. type UserViewHistory struct {
  8. ViewHistoryId int `orm:"column(id);pk"`
  9. UserId int `description:"用户id"`
  10. Mobile string `description:"手机号"`
  11. Email string `description:"邮箱"`
  12. RealName string `description:"用户实际姓名"`
  13. CompanyName string `description:"公司名称"`
  14. ViewTitle string `description:"访问标题"`
  15. ViewPage string `description:"访问页面"`
  16. ReportChapterModule string `description:"访问核心观点或者图文逻辑"`
  17. CreatedTime string `description:"创建时间"`
  18. LastUpdatedTime time.Time `description:"访问历史类型,weekly_report 周报,pdf;默认值:weekly_report"`
  19. ResearchReportId int `description:"研报id"`
  20. ResearchReportTypeId int `description:"报告章节id,为0时表示查看目录或者首页"`
  21. }
  22. //根据用户id字符串获取用户的浏览数
  23. type UserViewTotalSlice struct {
  24. UserId int `description:"用户id"`
  25. Total int `description:"总阅读数"`
  26. CreatedTime time.Time `description:"用户浏览时间"`
  27. }
  28. func GetCountUserViewHistoryByUserIds(userIds string) (items []*UserViewTotalSlice, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT count(1) total,user_id,max(created_time) as created_time FROM user_view_history WHERE user_id in (` + userIds + `) group by user_id`
  31. _, err = o.Raw(sql).QueryRows(&items)
  32. return
  33. //return items2,err
  34. }
  35. //根据用户手机号字符串获取用户的浏览数
  36. type UserViewMobileTotalSlice struct {
  37. Mobile string `description:"用户手机号"`
  38. Total int `description:"总阅读数"`
  39. CreatedTime time.Time `description:"用户浏览时间"`
  40. }
  41. func GetCountUserViewHistoryByMobiles(mobiles string) (items []*UserViewMobileTotalSlice, err error) {
  42. o := orm.NewOrm()
  43. sql := `SELECT count(1) total,mobile,max(created_time) as created_time FROM user_view_history WHERE mobile in (` + mobiles + `) group by mobile`
  44. _, err = o.Raw(sql).QueryRows(&items)
  45. return
  46. }
  47. //根据用户id字符串获取用户的浏览数
  48. type UserViewEmailTotalSlice struct {
  49. Email string `description:"用户邮箱"`
  50. Total int `description:"总阅读数"`
  51. CreatedTime time.Time `description:"用户浏览时间"`
  52. }
  53. func GetCountUserViewHistoryByEmails(emails string) (items []*UserViewEmailTotalSlice, err error) {
  54. o := orm.NewOrm()
  55. sql := `SELECT count(1) total,email,max(created_time) as created_time FROM user_view_history WHERE email in (` + emails + `) group by email`
  56. _, err = o.Raw(sql).QueryRows(&items)
  57. return
  58. //return items2,err
  59. }
  60. func GetCountCygxArticleHistoryRecordByMobiles(mobiles string) (items []*UserViewMobileTotalSlice, err error) {
  61. o := orm.NewOrm()
  62. sql := `SELECT count(1) total,mobile,max(create_time) as created_time FROM cygx_article_history_record_newpv WHERE mobile in (` + mobiles + `) AND company_id != 16 group by mobile`
  63. _, err = o.Raw(sql).QueryRows(&items)
  64. return
  65. }
  66. func GetCountCygxArticleHistoryRecordByEmails(emails string) (items []*UserViewEmailTotalSlice, err error) {
  67. o := orm.NewOrm()
  68. sql := `SELECT count(1) total,email,max(created_time) as created_time FROM cygx_article_history_record_newpv WHERE email in (` + emails + `) AND company_id != 16 group by email`
  69. _, err = o.Raw(sql).QueryRows(&items)
  70. return
  71. }
  72. // CompanyViewTotalSlice 获取客户的浏览次数
  73. type CompanyViewTotalSlice struct {
  74. CompanyId int `description:"客户id"`
  75. ViewTotal int `description:"用户浏览次数"`
  76. }
  77. // GetCountUserViewHistoryByCompanyIdsMobile 根据手机号获取客户的浏览次数
  78. func GetCountUserViewHistoryByCompanyIdsMobile(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  79. o := orm.NewOrm()
  80. sql := `SELECT
  81. a.company_id ,count(1) view_total FROM wx_user a
  82. JOIN user_view_history b ON a.mobile = b.mobile
  83. WHERE a.company_id IN ( ` + companyIds + ` ) and b.mobile !="" GROUP BY company_id`
  84. _, err = o.Raw(sql).QueryRows(&items)
  85. return
  86. }
  87. // GetCountUserViewHistoryByCompanyIdsEmail 根据邮箱获取客户的浏览次数
  88. func GetCountUserViewHistoryByCompanyIdsEmail(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  89. o := orm.NewOrm()
  90. sql := `SELECT
  91. a.company_id ,count(1) view_total
  92. FROM
  93. wx_user a
  94. JOIN user_view_history b ON a.email = b.email
  95. WHERE a.company_id IN ( ` + companyIds + ` ) and b.email !="" and b.mobile="" GROUP BY company_id`
  96. _, err = o.Raw(sql).QueryRows(&items)
  97. return
  98. }
  99. // GetCountAdvisoryArticleViewRecordByCompanyIdsMobile 根据手机号获取客户的浏览次数
  100. func GetCountAdvisoryArticleViewRecordByCompanyIdsMobile(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  101. o := orm.NewOrm()
  102. sql := `SELECT
  103. a.company_id ,count(1) view_total
  104. FROM
  105. wx_user a
  106. JOIN advisory_user_chart_article_record b ON a.mobile = b.mobile
  107. WHERE
  108. a.company_id IN ( ` + companyIds + ` ) and b.mobile !="" GROUP BY company_id`
  109. _, err = o.Raw(sql).QueryRows(&items)
  110. return
  111. }
  112. // GetCountAdvisoryArticleViewRecordByCompanyIdsEmail 根据邮箱获取客户的浏览次数
  113. func GetCountAdvisoryArticleViewRecordByCompanyIdsEmail(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  114. o := orm.NewOrm()
  115. sql := `SELECT
  116. a.company_id ,count(1) view_total
  117. FROM
  118. wx_user a
  119. JOIN advisory_user_chart_article_record b ON a.email = b.email
  120. WHERE a.company_id IN ( ` + companyIds + ` ) and b.email !="" and b.mobile="" GROUP BY company_id`
  121. _, err = o.Raw(sql).QueryRows(&items)
  122. return
  123. }
  124. // GetCountCygxArticleViewRecordByCompanyIdsMobile 根据手机号获取客户的浏览次数
  125. func GetCountCygxArticleViewRecordByCompanyIdsMobile(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  126. o := orm.NewOrm()
  127. //dataName := ""
  128. //if utils.RunMode == "debug" {
  129. // dataName = "test_v2_hongze_rddp"
  130. //} else {
  131. // dataName = "hongze_rddp"
  132. //}
  133. sql := `SELECT
  134. a.company_id ,count(1) view_total
  135. FROM
  136. wx_user a
  137. JOIN cygx_article_history_record_newpv b ON a.mobile = b.mobile
  138. WHERE
  139. a.company_id IN ( ` + companyIds + ` ) and b.mobile !="" GROUP BY company_id`
  140. _, err = o.Raw(sql).QueryRows(&items)
  141. return
  142. }
  143. // GetCountCygxArticleViewRecordByCompanyIdsEmail 根据邮箱获取客户的浏览次数
  144. func GetCountCygxArticleViewRecordByCompanyIdsEmail(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  145. o := orm.NewOrm()
  146. sql := `SELECT
  147. a.company_id ,count(1) view_total
  148. FROM
  149. wx_user a
  150. JOIN cygx_article_history_record_newpv b ON a.email = b.email
  151. WHERE a.company_id IN ( ` + companyIds + ` ) and b.email !="" and b.mobile="" GROUP BY company_id`
  152. _, err = o.Raw(sql).QueryRows(&items)
  153. return
  154. }
  155. // GetCountReportViewRecordByCompanyIdsMobile 根据手机号获取客户的浏览次数
  156. func GetCountReportViewRecordByCompanyIdsMobile(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  157. o := orm.NewOrm()
  158. dataName := ""
  159. if utils.RunMode == "debug" {
  160. dataName = "test_v2_hongze_rddp"
  161. } else {
  162. dataName = "hongze_rddp"
  163. }
  164. sql := `SELECT
  165. a.company_id ,count(1) view_total
  166. FROM
  167. wx_user a
  168. JOIN ` + dataName + `.report_view_record b ON a.mobile = b.mobile
  169. WHERE
  170. a.company_id IN ( ` + companyIds + ` ) and b.mobile !="" GROUP BY company_id`
  171. _, err = o.Raw(sql).QueryRows(&items)
  172. return
  173. }
  174. // GetCountReportViewRecordByCompanyIdsEmail 根据邮箱获取客户的浏览次数
  175. func GetCountReportViewRecordByCompanyIdsEmail(companyIds string) (items []*CompanyViewTotalSlice, err error) {
  176. o := orm.NewOrm()
  177. dataName := ""
  178. if utils.RunMode == "debug" {
  179. dataName = "test_v2_hongze_rddp"
  180. } else {
  181. dataName = "hongze_rddp"
  182. }
  183. sql := `SELECT a.company_id ,count(1) view_total FROM wx_user a
  184. JOIN ` + dataName + `.report_view_record b ON a.email = b.email
  185. WHERE a.company_id IN ( ` + companyIds + ` ) and b.email !="" and b.mobile="" GROUP BY company_id`
  186. _, err = o.Raw(sql).QueryRows(&items)
  187. return
  188. }