report_view.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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, 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 rr.type =?
  57. and c.company_id not in (1,16)
  58. `
  59. o := orm.NewOrm()
  60. _, err = o.Raw(sql, startTime, reportType).QueryRows(&items)
  61. return
  62. }
  63. func GetRddpReportViewersDetail(startTime string) (items []*ResearchReportViewersDetail, err error) {
  64. sql := `
  65. 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
  66. FROM hongze_rddp.report_view_record AS uvh
  67. INNER JOIN hongze_rddp.report AS r ON uvh.report_id=r.id
  68. INNER JOIN wx_user u ON u.user_id = uvh.user_id
  69. INNER JOIN company c ON c.company_id = u.company_id
  70. WHERE uvh.create_time >?
  71. AND c.company_id NOT IN (1,16)
  72. ORDER BY uvh.create_time DESC
  73. `
  74. o := orm.NewOrm()
  75. _, err = o.Raw(sql, startTime).QueryRows(&items)
  76. return
  77. }