report_view.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package models
  2. import (
  3. "rdluck_tools/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.NewOrm()
  31. o.Using("rddp")
  32. _, err = o.Raw(sql).QueryRows(&items)
  33. return
  34. }
  35. type ReportType struct {
  36. TypeName string
  37. TypeValue string
  38. }
  39. type ResearchReportViewersDetail struct {
  40. RealName string
  41. CompanyName string
  42. CreatedTime string //访问时间
  43. ResearchReportName string
  44. ReportVariety string
  45. ResearchReportType string
  46. ReportCreateDate string
  47. }
  48. func GetResearchReportViewersDetail(startTime, endTime, reportType string) (items []*ResearchReportViewersDetail, err error) {
  49. sql := `
  50. 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
  51. from user_view_history uvh
  52. inner join wx_user u on u.user_id = uvh.user_id
  53. inner join company c on c.company_id = u.company_id
  54. inner join research_report rr on rr.research_report_id = uvh.research_report_id
  55. left join research_report_type rrt on rrt.research_report_type_id = uvh.research_report_type_id
  56. left join report_chapter_type rct on rct.report_chapter_type_id = rrt.type_id
  57. where uvh.created_time > ?
  58. and uvh.created_time <= ?
  59. and rr.type =?
  60. and c.company_id not in (1)
  61. `
  62. o := orm.NewOrm()
  63. _, err = o.Raw(sql, startTime, endTime, reportType).QueryRows(&items)
  64. return
  65. }
  66. func GetRddpReportViewersDetail(startTime, endTime string) (items []*ResearchReportViewersDetail, err error) {
  67. sql := `
  68. 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
  69. FROM hongze_rddp.report_view_record AS uvh
  70. INNER JOIN hongze_rddp.report AS r ON uvh.report_id=r.id
  71. INNER JOIN wx_user u ON u.user_id = uvh.user_id
  72. INNER JOIN company c ON c.company_id = u.company_id
  73. WHERE uvh.create_time >?
  74. AND uvh.create_time <=?
  75. AND c.company_id NOT IN (1)
  76. ORDER BY uvh.create_time DESC
  77. `
  78. o := orm.NewOrm()
  79. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  80. return
  81. }
  82. type HistoryViewTimes struct {
  83. RealName string
  84. CompanyName string
  85. ViewCount int
  86. CreateTime string
  87. UserId int
  88. }
  89. func GetHistoryViewTimes() (items []*HistoryViewTimes, err error) {
  90. 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
  91. from user_view_history uvh
  92. inner join wx_user u on u.user_id = uvh.user_id
  93. inner join company c on c.company_id = u.company_id
  94. and c.company_id not in (1,16)
  95. group by uvh.user_id
  96. order by max(uvh.created_time) desc `
  97. o := orm.NewOrm()
  98. _, err = o.Raw(sql).QueryRows(&items)
  99. return
  100. }
  101. func GetRddpHistoryViewTimes() (items []*HistoryViewTimes, err error) {
  102. 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
  103. from hongze_rddp.report_view_record rvr
  104. inner join wx_user u on u.user_id = rvr.user_id
  105. inner join company c on c.company_id = u.company_id
  106. and c.company_id not in (1,16)
  107. group by rvr.user_id
  108. order by max(rvr.create_time) desc `
  109. o := orm.NewOrm()
  110. _, err = o.Raw(sql).QueryRows(&items)
  111. return
  112. }
  113. //每日资讯
  114. //func GetAdvisoryViewersDetail(startTime, endTime string) (items []*ResearchReportViewersDetail, err error) {
  115. // sql := `
  116. // SELECT
  117. // u.real_name,
  118. // c.company_name,
  119. // aavr.create_time AS created_time,
  120. // art.title AS research_report_name,
  121. // art.chart_permission_name AS research_report_type
  122. // FROM
  123. // advisory_article_view_record AS aavr
  124. // INNER JOIN advisory_article AS art ON aavr.article_id = art.advisory_article_id
  125. // INNER JOIN wx_user u ON u.user_id = aavr.user_id
  126. // INNER JOIN company c ON c.company_id = u.company_id
  127. // WHERE
  128. // aavr.create_time > ?
  129. // AND aavr.create_time <= ?
  130. // AND c.company_id NOT IN ( 1 )
  131. // ORDER BY
  132. // aavr.create_time DESC`
  133. // o := orm.NewOrm()
  134. // _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  135. // return
  136. //}
  137. func GetAdvisoryViewersDetail(startTime, endTime string) (items []*ResearchReportViewersDetail, err error) {
  138. sql := `
  139. SELECT
  140. u.real_name,
  141. c.company_name,
  142. aua.create_time AS created_time,
  143. cha.permission_name AS research_report_name
  144. FROM
  145. advisory_user_chart_article_record AS aua
  146. INNER JOIN chart_permission AS cha ON aua.chart_permission_id = cha.chart_permission_id
  147. INNER JOIN wx_user u ON u.user_id = aua.user_id
  148. INNER JOIN company c ON c.company_id = u.company_id
  149. WHERE
  150. aua.create_time > ?
  151. AND aua.create_time <= ?
  152. AND c.company_id NOT IN ( 1 )
  153. ORDER BY
  154. aua.create_time DESC
  155. `
  156. o := orm.NewOrm()
  157. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  158. return
  159. }