report_view.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. AND r.classify_name_first not in ("晨报","周报","大宗商品","数据点评","会议纪要","年报合集","需求报告")
  76. AND r.classify_id_second not in (113,114,127,134,141,149)
  77. ORDER BY uvh.create_time DESC
  78. `
  79. o := orm.NewOrm()
  80. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  81. return
  82. }
  83. type RddpWeekReportViewersDetail struct {
  84. RealName string
  85. CompanyName string
  86. CreatedTime string //访问时间
  87. ResearchReportName string
  88. ReportVariety string
  89. ResearchReportType string
  90. ReportCreateDate string
  91. ChapterTitle string
  92. ClassifyNameFirst string
  93. ClassifyNameSecond string
  94. }
  95. func GetRddpDayReportViewersDetail(startTime, endTime string) (items []*RddpWeekReportViewersDetail, err error) {
  96. sql := `
  97. SELECT
  98. u.real_name,c.company_name,uvh.create_time AS created_time,REPLACE ( SUBSTRING( r.create_time, 6, 5 ), '-', '' ) AS report_create_date,
  99. r.title AS research_report_name,r.classify_name_second AS research_report_type ,rc.title chapter_title,rc.type_name as report_variety
  100. FROM
  101. hongze_rddp.report_view_record AS uvh
  102. INNER JOIN hongze_rddp.report AS r ON uvh.report_id = r.id
  103. INNER JOIN hongze_rddp.report_chapter AS rc ON uvh.report_id = rc.report_id and uvh.report_chapter_id=rc.report_chapter_id
  104. INNER JOIN wx_user u ON u.user_id = uvh.user_id
  105. INNER JOIN company c ON c.company_id = u.company_id
  106. WHERE uvh.create_time >?
  107. AND uvh.create_time <=?
  108. AND c.company_id NOT IN (1)
  109. AND r.classify_name_first = "晨报"
  110. ORDER BY uvh.create_time DESC
  111. `
  112. o := orm.NewOrm()
  113. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  114. return
  115. }
  116. func GetRddpWeekReportViewersDetail(startTime, endTime string) (items []*RddpWeekReportViewersDetail, err error) {
  117. sql := `
  118. SELECT
  119. u.real_name,c.company_name,uvh.create_time AS created_time,REPLACE ( SUBSTRING( r.create_time, 6, 5 ), '-', '' ) AS report_create_date,
  120. r.title AS research_report_name,r.classify_name_second AS research_report_type ,rc.title chapter_title,rc.type_name as report_variety
  121. FROM
  122. hongze_rddp.report_view_record AS uvh
  123. INNER JOIN hongze_rddp.report AS r ON uvh.report_id = r.id
  124. INNER JOIN hongze_rddp.report_chapter AS rc ON uvh.report_id = rc.report_id and uvh.report_chapter_id=rc.report_chapter_id
  125. INNER JOIN wx_user u ON u.user_id = uvh.user_id
  126. INNER JOIN company c ON c.company_id = u.company_id
  127. WHERE uvh.create_time >?
  128. AND uvh.create_time <=?
  129. AND c.company_id NOT IN (1)
  130. AND r.classify_name_first = "周报"
  131. ORDER BY uvh.create_time DESC
  132. `
  133. o := orm.NewOrm()
  134. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  135. return
  136. }
  137. func GetRddpTwoWeekReportViewersDetail(startTime, endTime string) (items []*RddpWeekReportViewersDetail, err error) {
  138. sql := `
  139. SELECT
  140. u.real_name,c.company_name,uvh.create_time AS created_time,REPLACE ( SUBSTRING( r.create_time, 6, 5 ), '-', '' ) AS report_create_date,
  141. r.title AS research_report_name,r.classify_name_second AS research_report_type,r.classify_name_second
  142. FROM
  143. hongze_rddp.report_view_record AS uvh
  144. INNER JOIN hongze_rddp.report AS r ON uvh.report_id = r.id
  145. INNER JOIN wx_user u ON u.user_id = uvh.user_id
  146. INNER JOIN company c ON c.company_id = u.company_id
  147. WHERE uvh.create_time >?
  148. AND uvh.create_time <=?
  149. AND c.company_id NOT IN (1)
  150. AND r.classify_name_first = "大宗商品"
  151. ORDER BY uvh.create_time DESC
  152. `
  153. o := orm.NewOrm()
  154. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  155. return
  156. }
  157. // GetRddpMonthReportViewersDetail 获取月度数据
  158. func GetRddpMonthReportViewersDetail(startTime, endTime string) (items []*RddpWeekReportViewersDetail, err error) {
  159. sql := `
  160. SELECT
  161. u.real_name,c.company_name,uvh.create_time AS created_time,REPLACE ( SUBSTRING( r.create_time, 6, 5 ), '-', '' ) AS report_create_date,
  162. r.title AS research_report_name,r.classify_name_second AS research_report_type,r.classify_name_second
  163. FROM
  164. hongze_rddp.report_view_record AS uvh
  165. INNER JOIN hongze_rddp.report AS r ON uvh.report_id = r.id
  166. INNER JOIN wx_user u ON u.user_id = uvh.user_id
  167. INNER JOIN company c ON c.company_id = u.company_id
  168. WHERE uvh.create_time >?
  169. AND uvh.create_time <=?
  170. AND c.company_id NOT IN (1)
  171. AND r.classify_id_second in (113,114,127,134,141,149)
  172. ORDER BY uvh.create_time DESC
  173. `
  174. o := orm.NewOrm()
  175. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  176. return
  177. }
  178. // GetRddpDataReviewReportViewersDetail 获取数据点评数据
  179. func GetRddpDataReviewReportViewersDetail(startTime, endTime string) (items []*RddpWeekReportViewersDetail, err error) {
  180. sql := `
  181. SELECT
  182. u.real_name,c.company_name,uvh.create_time AS created_time,REPLACE ( SUBSTRING( r.create_time, 6, 5 ), '-', '' ) AS report_create_date,
  183. r.title AS research_report_name,r.classify_name_second AS research_report_type,r.classify_name_second,r.classify_name_first
  184. FROM
  185. hongze_rddp.report_view_record AS uvh
  186. INNER JOIN hongze_rddp.report AS r ON uvh.report_id = r.id
  187. INNER JOIN wx_user u ON u.user_id = uvh.user_id
  188. INNER JOIN company c ON c.company_id = u.company_id
  189. WHERE uvh.create_time >?
  190. AND uvh.create_time <=?
  191. AND c.company_id NOT IN (1)
  192. AND r.classify_name_first IN ("数据点评","会议纪要","年报合集","需求报告")
  193. ORDER BY uvh.create_time DESC
  194. `
  195. o := orm.NewOrm()
  196. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  197. return
  198. }
  199. type HistoryViewTimes struct {
  200. RealName string
  201. CompanyName string
  202. ViewCount int
  203. CreateTime string
  204. UserId int
  205. }
  206. func GetHistoryViewTimes() (items []*HistoryViewTimes, err error) {
  207. 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
  208. from user_view_history uvh
  209. inner join wx_user u on u.user_id = uvh.user_id
  210. inner join company c on c.company_id = u.company_id
  211. and c.company_id not in (1,16)
  212. group by uvh.user_id
  213. order by max(uvh.created_time) desc `
  214. o := orm.NewOrm()
  215. _, err = o.Raw(sql).QueryRows(&items)
  216. return
  217. }
  218. func GetRddpHistoryViewTimes() (items []*HistoryViewTimes, err error) {
  219. 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
  220. from hongze_rddp.report_view_record rvr
  221. inner join wx_user u on u.user_id = rvr.user_id
  222. inner join company c on c.company_id = u.company_id
  223. and c.company_id not in (1,16)
  224. group by rvr.user_id
  225. order by max(rvr.create_time) desc `
  226. o := orm.NewOrm()
  227. _, err = o.Raw(sql).QueryRows(&items)
  228. return
  229. }
  230. //每日资讯
  231. //func GetAdvisoryViewersDetail(startTime, endTime string) (items []*ResearchReportViewersDetail, err error) {
  232. // sql := `
  233. // SELECT
  234. // u.real_name,
  235. // c.company_name,
  236. // aavr.create_time AS created_time,
  237. // art.title AS research_report_name,
  238. // art.chart_permission_name AS research_report_type
  239. // FROM
  240. // advisory_article_view_record AS aavr
  241. // INNER JOIN advisory_article AS art ON aavr.article_id = art.advisory_article_id
  242. // INNER JOIN wx_user u ON u.user_id = aavr.user_id
  243. // INNER JOIN company c ON c.company_id = u.company_id
  244. // WHERE
  245. // aavr.create_time > ?
  246. // AND aavr.create_time <= ?
  247. // AND c.company_id NOT IN ( 1 )
  248. // ORDER BY
  249. // aavr.create_time DESC`
  250. // o := orm.NewOrm()
  251. // _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  252. // return
  253. //}
  254. func GetAdvisoryViewersDetail(startTime, endTime string) (items []*ResearchReportViewersDetail, err error) {
  255. sql := `
  256. SELECT
  257. u.real_name,
  258. c.company_name,
  259. aua.create_time AS created_time,
  260. cha.permission_name AS research_report_name
  261. FROM
  262. advisory_user_chart_article_record AS aua
  263. INNER JOIN chart_permission AS cha ON aua.chart_permission_id = cha.chart_permission_id
  264. INNER JOIN wx_user u ON u.user_id = aua.user_id
  265. INNER JOIN company c ON c.company_id = u.company_id
  266. WHERE
  267. aua.create_time > ?
  268. AND aua.create_time <= ?
  269. AND c.company_id NOT IN ( 1 )
  270. ORDER BY
  271. aua.create_time DESC
  272. `
  273. o := orm.NewOrm()
  274. _, err = o.Raw(sql, startTime, endTime).QueryRows(&items)
  275. return
  276. }