user_view_statistics.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // UserViewStatistics 用户报告报告阅读数量统计表
  7. type UserViewStatistics struct {
  8. Id int `orm:"column(id)" description:"自增Id"`
  9. Mobile string `description:"手机号"`
  10. Email string `description:"手机号"`
  11. RealName string `description:"联系人名称"`
  12. CompanyName string `description:"客户名称"`
  13. ViewNum int `description:"阅读总数"`
  14. LastViewTime time.Time `description:"最近一次阅读时间"`
  15. Date time.Time `description:"阅读日期"`
  16. CreateTime time.Time `description:"添加时间"`
  17. }
  18. // AddUserViewStatistics 添加用户报告报告阅读数量统计记录
  19. func AddUserViewStatistics(item *UserViewStatistics) (err error) {
  20. o := orm.NewOrm()
  21. _, err = o.Insert(item)
  22. return
  23. }
  24. // AddMultiUserViewStatistics 添加用户报告报告阅读数量统计记录
  25. func AddMultiUserViewStatistics(list []*UserViewStatistics) (err error) {
  26. if len(list) <= 0 {
  27. return
  28. }
  29. o := orm.NewOrm()
  30. _, err = o.InsertMulti(len(list), list)
  31. return
  32. }
  33. // Update 更新用户报告报告阅读数量统计表
  34. func (userViewStatistics *UserViewStatistics) Update(cols []string) (err error) {
  35. o := orm.NewOrm()
  36. _, err = o.Update(userViewStatistics, cols...)
  37. return
  38. }
  39. // GetUserViewStatisticsByMobile 根据手机号、日期获取数据
  40. func GetUserViewStatisticsByMobile(mobile, date string) (item *UserViewStatistics, err error) {
  41. o := orm.NewOrm()
  42. sql := `SELECT * from user_view_statistics WHERE mobile=? and date = ?`
  43. err = o.Raw(sql, mobile, date).QueryRow(&item)
  44. return
  45. }
  46. // GetUserViewStatisticsByMobile 根据邮箱、日期获取数据
  47. func GetUserViewStatisticsByEmail(email, date string) (item *UserViewStatistics, err error) {
  48. o := orm.NewOrm()
  49. sql := `SELECT * from user_view_statistics WHERE email=? and date = ?`
  50. err = o.Raw(sql, email, date).QueryRow(&item)
  51. return
  52. }
  53. // UpdateLastViewTimeByMobile 根据手机号修改最近阅读时间
  54. func UpdateLastViewTimeByMobile(mobile, date string, lastViewTime time.Time) (err error) {
  55. o := orm.NewOrm()
  56. sql := `update user_view_statistics set last_view_time =? WHERE mobile=? and date = ?`
  57. _, err = o.Raw(sql, lastViewTime, mobile, date).Exec()
  58. return
  59. }
  60. // UpdateLastViewTimeByEmail 根据邮箱修改最近阅读时间
  61. func UpdateLastViewTimeByEmail(mobile, date string, lastViewTime time.Time) (err error) {
  62. o := orm.NewOrm()
  63. sql := `update user_view_statistics set last_view_time =? WHERE mobile=? and date = ?`
  64. _, err = o.Raw(sql, lastViewTime, mobile, date).Exec()
  65. return
  66. }
  67. // GetUserViewStatisticsCount 获取某天的用户报告报告阅读数量统计记录数量
  68. func GetUserViewStatisticsCount(dayStr string) (count int, err error) {
  69. o := orm.NewOrm()
  70. sql := `SELECT count(1) count FROM user_view_statistics WHERE date = ?`
  71. err = o.Raw(sql, dayStr).QueryRow(&count)
  72. return
  73. }
  74. // GetUserViewStatisticsGroup 获取某天的用户报告报告阅读数量统计记录数量
  75. func GetUserViewStatisticsGroup() (list []*UserViewStatistics, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT * FROM user_view_statistics where last_view_time is null group by date order by date asc`
  78. _, err = o.Raw(sql).QueryRows(&list)
  79. return
  80. }
  81. // DeleteUserViewStatisticsCount 获取某天的用户报告报告阅读数量统计记录数量
  82. func DeleteUserViewStatisticsCount(dayStr string) (err error) {
  83. o := orm.NewOrm()
  84. //产品权限
  85. sql := `delete from user_view_statistics WHERE date = ?`
  86. _, err = o.Raw(sql, dayStr).Exec()
  87. return
  88. }
  89. // UserViewMobileTotalSlice 根据用户手机号字符串获取用户的浏览数
  90. type UserViewMobileTotalSlice struct {
  91. Mobile string `description:"用户手机号"`
  92. CompanyName string `description:"客户名称"`
  93. RealName string `description:"用户名称"`
  94. Total int `description:"总阅读数"`
  95. ViewTime time.Time `description:"阅读时间"`
  96. }
  97. // UserViewEmailTotalSlice 根据用户邮箱字符串获取用户的浏览数
  98. type UserViewEmailTotalSlice struct {
  99. Email string `description:"用户邮箱"`
  100. CompanyName string `description:"客户名称"`
  101. RealName string `description:"用户名称"`
  102. Total int `description:"总阅读数"`
  103. ViewTime time.Time `description:"阅读时间"`
  104. }
  105. func GetCountUserViewHistoryByMobiles(date string) (items []*UserViewMobileTotalSlice, err error) {
  106. o := orm.NewOrm()
  107. sql := `SELECT count(1) total,mobile,company_name,real_name,max(created_time) view_time FROM user_view_history WHERE created_time >= ? and created_time <= ? and mobile != "" group by mobile`
  108. _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  109. return
  110. }
  111. func GetCountUserViewHistoryByEmails(date string) (items []*UserViewEmailTotalSlice, err error) {
  112. o := orm.NewOrm()
  113. sql := `SELECT count(1) total,email,company_name,real_name,max(created_time) view_time FROM user_view_history WHERE created_time >= ? and created_time <= ? and email != "" group by email`
  114. _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  115. return
  116. //return items2,err
  117. }
  118. func GetReportViewMaxTimeByMobiles(date string) (items []*UserViewMobileTotalSlice, err error) {
  119. o := orm.NewOrmUsingDB("rddp")
  120. rddpSql := `SELECT mobile,company_name,real_name,COUNT(1) AS total,max(create_time) view_time FROM report_view_record WHERE create_time >= ? and create_time <= ? and mobile != "" group by mobile`
  121. _, err = o.Raw(rddpSql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  122. return
  123. }
  124. func GetReportViewMaxTimeByEmails(date string) (items []*UserViewEmailTotalSlice, err error) {
  125. o := orm.NewOrmUsingDB("rddp")
  126. rddpSql := `SELECT email,company_name,real_name,COUNT(1) AS total,max(create_time) view_time FROM report_view_record WHERE create_time >= ? and create_time <= ? and email != "" group by email`
  127. _, err = o.Raw(rddpSql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  128. return
  129. }
  130. // GetAdvisoryCountUserViewHistoryByMobiles 每日资讯
  131. func GetAdvisoryCountUserViewHistoryByMobiles(date string) (items []*UserViewMobileTotalSlice, err error) {
  132. o := orm.NewOrm()
  133. sql := `SELECT count(1) total,mobile,company_name,real_name,max(create_time) view_time FROM advisory_user_chart_article_record WHERE create_time >= ? and create_time <= ? and mobile != "" group by mobile`
  134. _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  135. return
  136. }
  137. // GetAdvisoryCountUserViewHistoryByEmails 每日资讯
  138. func GetAdvisoryCountUserViewHistoryByEmails(date string) (items []*UserViewEmailTotalSlice, err error) {
  139. o := orm.NewOrm()
  140. sql := `SELECT count(1) total,email,company_name,real_name as created_time,max(create_time) view_time FROM advisory_user_chart_article_record WHERE create_time >= ? and create_time <= ? and email != "" group by email`
  141. _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  142. return
  143. //return items2,err
  144. }
  145. func GetMaxUserViewHistoryByMobiles() (items []*UserViewMobileTotalSlice, err error) {
  146. o := orm.NewOrm()
  147. sql := `SELECT count(1) total,mobile,company_name,real_name,max(created_time) view_time FROM user_view_history WHERE created_time <= "2022-02-15 00:00:00" and mobile != "" group by mobile`
  148. _, err = o.Raw(sql).QueryRows(&items)
  149. return
  150. }
  151. func GetMaxReportViewMaxTimeByMobiles() (items []*UserViewMobileTotalSlice, err error) {
  152. o := orm.NewOrmUsingDB("rddp")
  153. rddpSql := `SELECT mobile,company_name,real_name,COUNT(1) AS total,max(create_time) view_time FROM report_view_record WHERE create_time <= "2022-02-15 00:00:00" and mobile != "" group by mobile`
  154. _, err = o.Raw(rddpSql).QueryRows(&items)
  155. return
  156. }
  157. // GetAdvisoryCountUserViewHistoryByMobiles 每日资讯
  158. func GetMaxAdvisoryCountUserViewHistoryByMobiles() (items []*UserViewMobileTotalSlice, err error) {
  159. o := orm.NewOrm()
  160. sql := `SELECT count(1) total,mobile,company_name,real_name,max(create_time) view_time FROM advisory_user_chart_article_record WHERE create_time <= "2022-02-15 00:00:00" and mobile != "" group by mobile`
  161. _, err = o.Raw(sql).QueryRows(&items)
  162. return
  163. }
  164. // UserViewStatisticsInfo 根据用户手机号字符串获取用户的浏览数和最晚阅读次数
  165. type UserViewStatisticsInfo struct {
  166. Mobile string `description:"用户手机号"`
  167. Total int `description:"总阅读数"`
  168. LastViewTime time.Time `description:"用户浏览时间"`
  169. }
  170. // GetUserLastViewStatisticsByMobile 根据手机号获取最新的联系人的浏览次数
  171. func GetUserLastViewStatisticsByMobile(mobile string) (item *UserViewStatisticsInfo, err error) {
  172. o := orm.NewOrm()
  173. sql := `SELECT mobile,sum(view_num) total,max(last_view_time) last_view_time FROM user_view_statistics WHERE mobile = ? `
  174. err = o.Raw(sql, mobile).QueryRow(&item)
  175. return
  176. }