report_view.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. )
  5. type ResearchReportViewers struct {
  6. ResearchReportName string
  7. ReportType string
  8. Count int //访问次数
  9. UserCount int //访问人数
  10. CreateDate string
  11. }
  12. func GetResearchReportViewers(reportType string) (items []*ResearchReportViewers, err error) {
  13. sql := `select rr.research_report_name,rr.type as report_type,count(*) AS count,count(DISTINCT user_id) AS user_count
  14. from user_view_history uvh
  15. inner join research_report rr on rr.research_report_id = uvh.research_report_id
  16. where rr.type = ?
  17. group by rr.research_report_id
  18. order by rr.research_report_date desc`
  19. o := orm.NewOrm()
  20. _, err = o.Raw(sql, reportType).QueryRows(&items)
  21. return
  22. }
  23. func GetRddpReportViewers() (items []*ResearchReportViewers, err error) {
  24. sql := `select b.title as research_report_name, replace(SUBSTRING(b.create_time,6,5),'-','') as create_date ,b.classify_name_second AS report_type,count(*) AS count,count(DISTINCT a.user_id) AS user_count
  25. from report_view_record as a
  26. inner join report as b on a.report_id=b.id
  27. group by b.id
  28. order by b.create_time desc
  29. `
  30. o := orm.NewOrmUsingDB("rddp")
  31. _, err = o.Raw(sql).QueryRows(&items)
  32. return
  33. }
  34. type ReportType struct {
  35. TypeName string
  36. TypeValue string
  37. }
  38. type ResearchReportViewersDetail struct {
  39. RealName string
  40. CompanyName string
  41. CreatedTime string //访问时间
  42. ResearchReportName string
  43. ReportVariety string
  44. ResearchReportType string
  45. ReportCreateDate string
  46. }
  47. func GetResearchReportViewersDetail(startTime, endTime, reportType string) (items []*ResearchReportViewersDetail, err error) {
  48. sql := `
  49. select u.real_name,c.company_name,uvh.created_time,rr.research_report_name,ifnull(rct.report_chapter_type_name,rr.report_variety) as report_variety,rr.type as research_report_type
  50. from user_view_history uvh
  51. inner join wx_user u on u.user_id = uvh.user_id
  52. inner join company c on c.company_id = u.company_id
  53. inner join research_report rr on rr.research_report_id = uvh.research_report_id
  54. left join research_report_type rrt on rrt.research_report_type_id = uvh.research_report_type_id
  55. left join report_chapter_type rct on rct.report_chapter_type_id = rrt.type_id
  56. where uvh.created_time > ?
  57. and uvh.created_time <= ?
  58. and rr.type =?
  59. and c.company_id not in (1)
  60. `
  61. o := orm.NewOrm()
  62. _, err = o.Raw(sql, startTime, endTime, reportType).QueryRows(&items)
  63. return
  64. }
  65. func GetRddpReportViewersDetail(startTime, endTime string) (items []*ResearchReportViewersDetail, err error) {
  66. sql := `
  67. SELECT u.real_name,c.company_name,uvh.create_time as created_time,REPLACE(SUBSTRING(r.create_time,6,5),'-','') AS report_create_date,r.title as research_report_name,r.classify_name_second as research_report_type
  68. FROM hongze_rddp.report_view_record AS uvh
  69. INNER JOIN hongze_rddp.report AS r ON uvh.report_id=r.id
  70. INNER JOIN wx_user u ON u.user_id = uvh.user_id
  71. INNER JOIN company c ON c.company_id = u.company_id
  72. WHERE uvh.create_time >?
  73. AND uvh.create_time <=?
  74. AND c.company_id NOT IN (1)
  75. ORDER BY uvh.create_time DESC
  76. `
  77. o := orm.NewOrm()
  78. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  79. return
  80. }
  81. type HistoryViewTimes struct {
  82. RealName string
  83. CompanyName string
  84. ViewCount int
  85. CreateTime string
  86. UserId int
  87. }
  88. func GetHistoryViewTimes() (items []*HistoryViewTimes, err error) {
  89. sql := `select u.user_id,u.real_name,c.company_name,count(distinct(DATE_FORMAT(uvh.created_time,'%Y-%m-%d'))) AS view_count,max(uvh.created_time) AS create_time
  90. from user_view_history uvh
  91. inner join wx_user u on u.user_id = uvh.user_id
  92. inner join company c on c.company_id = u.company_id
  93. and c.company_id not in (1,16)
  94. group by uvh.user_id
  95. order by max(uvh.created_time) desc `
  96. o := orm.NewOrm()
  97. _, err = o.Raw(sql).QueryRows(&items)
  98. return
  99. }
  100. func GetRddpHistoryViewTimes() (items []*HistoryViewTimes, err error) {
  101. sql := `select u.user_id,u.real_name,c.company_name,count(distinct(DATE_FORMAT(rvr.create_time,'%Y-%m-%d'))) AS view_count ,max(rvr.create_time) AS create_time
  102. from hongze_rddp.report_view_record rvr
  103. inner join wx_user u on u.user_id = rvr.user_id
  104. inner join company c on c.company_id = u.company_id
  105. and c.company_id not in (1,16)
  106. group by rvr.user_id
  107. order by max(rvr.create_time) desc `
  108. o := orm.NewOrm()
  109. _, err = o.Raw(sql).QueryRows(&items)
  110. return
  111. }
  112. //每日资讯
  113. //func GetAdvisoryViewersDetail(startTime, endTime string) (items []*ResearchReportViewersDetail, err error) {
  114. // sql := `
  115. // SELECT
  116. // u.real_name,
  117. // c.company_name,
  118. // aavr.create_time AS created_time,
  119. // art.title AS research_report_name,
  120. // art.chart_permission_name AS research_report_type
  121. // FROM
  122. // advisory_article_view_record AS aavr
  123. // INNER JOIN advisory_article AS art ON aavr.article_id = art.advisory_article_id
  124. // INNER JOIN wx_user u ON u.user_id = aavr.user_id
  125. // INNER JOIN company c ON c.company_id = u.company_id
  126. // WHERE
  127. // aavr.create_time > ?
  128. // AND aavr.create_time <= ?
  129. // AND c.company_id NOT IN ( 1 )
  130. // ORDER BY
  131. // aavr.create_time DESC`
  132. // o := orm.NewOrm()
  133. // _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  134. // return
  135. //}
  136. func GetAdvisoryViewersDetail(startTime, endTime string) (items []*ResearchReportViewersDetail, err error) {
  137. sql := `
  138. SELECT
  139. u.real_name,
  140. c.company_name,
  141. aua.create_time AS created_time,
  142. cha.permission_name AS research_report_name
  143. FROM
  144. advisory_user_chart_article_record AS aua
  145. INNER JOIN chart_permission AS cha ON aua.chart_permission_id = cha.chart_permission_id
  146. INNER JOIN wx_user u ON u.user_id = aua.user_id
  147. INNER JOIN company c ON c.company_id = u.company_id
  148. WHERE
  149. aua.create_time > ?
  150. AND aua.create_time <= ?
  151. AND c.company_id NOT IN ( 1 )
  152. ORDER BY
  153. aua.create_time DESC
  154. `
  155. o := orm.NewOrm()
  156. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  157. return
  158. }