report_view.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package models
  2. import "rdluck_tools/orm"
  3. type ResearchReportViewers struct {
  4. ResearchReportName string
  5. ReportType string
  6. Count int //访问次数
  7. UserCount int //访问人数
  8. CreateDate string
  9. }
  10. func GetResearchReportViewers(reportType string) (items []*ResearchReportViewers, err error) {
  11. sql := `select rr.research_report_name,rr.type as report_type,count(*) AS count,count(DISTINCT user_id) AS user_count
  12. from user_view_history uvh
  13. inner join research_report rr on rr.research_report_id = uvh.research_report_id
  14. where rr.type = ?
  15. group by rr.research_report_id
  16. order by rr.research_report_date desc`
  17. o := orm.NewOrm()
  18. _, err = o.Raw(sql, reportType).QueryRows(&items)
  19. return
  20. }
  21. func GetRddpReportViewers() (items []*ResearchReportViewers, err error) {
  22. 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
  23. from report_view_record as a
  24. inner join report as b on a.report_id=b.id
  25. group by b.id
  26. order by b.create_time desc
  27. `
  28. o := orm.NewOrm()
  29. o.Using("rddp")
  30. _, err = o.Raw(sql).QueryRows(&items)
  31. return
  32. }
  33. type ReportType struct {
  34. TypeName string
  35. TypeValue string
  36. }
  37. type ResearchReportViewersDetail struct {
  38. RealName string
  39. CompanyName string
  40. CreatedTime string //访问时间
  41. ResearchReportName string
  42. ReportVariety string
  43. ResearchReportType string
  44. ReportCreateDate string
  45. }
  46. func GetResearchReportViewersDetail(startTime, endTime, reportType string) (items []*ResearchReportViewersDetail, err error) {
  47. sql := `
  48. 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
  49. from user_view_history uvh
  50. inner join wx_user u on u.user_id = uvh.user_id
  51. inner join company c on c.company_id = u.company_id
  52. inner join research_report rr on rr.research_report_id = uvh.research_report_id
  53. left join research_report_type rrt on rrt.research_report_type_id = uvh.research_report_type_id
  54. left join report_chapter_type rct on rct.report_chapter_type_id = rrt.type_id
  55. where uvh.created_time > ?
  56. and uvh.created_time <= ?
  57. and rr.type =?
  58. and c.company_id not in (1,16)
  59. `
  60. o := orm.NewOrm()
  61. _, err = o.Raw(sql, startTime, endTime, reportType).QueryRows(&items)
  62. return
  63. }
  64. func GetRddpReportViewersDetail(startTime, endTime string) (items []*ResearchReportViewersDetail, err error) {
  65. sql := `
  66. 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
  67. FROM hongze_rddp.report_view_record AS uvh
  68. INNER JOIN hongze_rddp.report AS r ON uvh.report_id=r.id
  69. INNER JOIN wx_user u ON u.user_id = uvh.user_id
  70. INNER JOIN company c ON c.company_id = u.company_id
  71. WHERE uvh.create_time >?
  72. AND uvh.create_time <=?
  73. AND c.company_id NOT IN (1,16)
  74. ORDER BY uvh.create_time DESC
  75. `
  76. o := orm.NewOrm()
  77. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  78. return
  79. }
  80. type HistoryViewTimes struct {
  81. RealName string
  82. CompanyName string
  83. ViewCount int
  84. CreateTime string
  85. UserId int
  86. }
  87. func GetHistoryViewTimes() (items []*HistoryViewTimes, err error) {
  88. 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
  89. from user_view_history uvh
  90. inner join wx_user u on u.user_id = uvh.user_id
  91. inner join company c on c.company_id = u.company_id
  92. and c.company_id not in (1,16)
  93. group by uvh.user_id
  94. order by max(uvh.created_time) desc `
  95. o := orm.NewOrm()
  96. _, err = o.Raw(sql).QueryRows(&items)
  97. return
  98. }
  99. func GetRddpHistoryViewTimes() (items []*HistoryViewTimes, err error) {
  100. 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
  101. from hongze_rddp.report_view_record rvr
  102. inner join wx_user u on u.user_id = rvr.user_id
  103. inner join company c on c.company_id = u.company_id
  104. and c.company_id not in (1,16)
  105. group by rvr.user_id
  106. order by max(rvr.create_time) desc `
  107. o := orm.NewOrm()
  108. _, err = o.Raw(sql).QueryRows(&items)
  109. return
  110. }