article_history_record.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_clpt/utils"
  5. "time"
  6. )
  7. type CygxArticleHistoryResp struct {
  8. Pv int `description:"阅读PV"`
  9. ArticleId int `description:"文章id"`
  10. Num int `description:"数量"`
  11. }
  12. // ArticleTopHistoryRecord 报告阅读飙升榜
  13. type ArticleTopHistoryRecord struct {
  14. Id int `orm:"column(id);pk"`
  15. ArticleId int `description:"文章ID"`
  16. Title string `description:"文章标题"`
  17. PublishDate string `description:"发布日期"`
  18. ChartPermissionId int `description:"行业ID"`
  19. PermissionName string `description:"行业名称"`
  20. Pv int `description:"PV"`
  21. CreateTime time.Time `description:"创建时间"`
  22. }
  23. // 获取用户阅读记录
  24. func GetUserToArticleCount(uid, articleId int) (count int, err error) {
  25. sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE user_id=? AND article_id=? `
  26. o := orm.NewOrm()
  27. err = o.Raw(sqlCount, uid, articleId).QueryRow(&count)
  28. return
  29. }
  30. // 获取用户阅读记录
  31. func GetUserToArticleHistory(uid int, articleIdArr []int) (items []*CygxArticleHistoryResp, err error) {
  32. arrLen := len(articleIdArr)
  33. if arrLen == 0 {
  34. return
  35. }
  36. sql := `SELECT
  37. article_id
  38. FROM
  39. cygx_article_history_record
  40. WHERE
  41. 1 = 1
  42. AND user_id = ?
  43. AND article_id IN (` + utils.GetOrmInReplace(len(articleIdArr)) + `)
  44. GROUP BY
  45. article_id `
  46. o := orm.NewOrm()
  47. _, err = o.Raw(sql, uid, articleIdArr).QueryRows(&items)
  48. return
  49. }
  50. // GetTopReadRecordArticleListByCondition 获取阅读量排行榜
  51. func GetTopReadRecordArticleListByCondition(limit int, condition string, pars []interface{}) (list []*ArticleListResp, err error) {
  52. sql := `SELECT
  53. a.title,
  54. a.article_id,
  55. a.publish_date,
  56. a.annotation,
  57. a.abstract,
  58. a.article_type_id,
  59. m.chart_permission_name,
  60. a.category_id
  61. FROM
  62. cygx_article_top_history_record as r
  63. INNER JOIN cygx_article as a ON a.article_id = r.article_id
  64. INNER JOIN cygx_report_mapping as m ON m.category_id = a.category_id_two`
  65. if condition != `` {
  66. sql += condition
  67. }
  68. sql += ` GROUP BY a.article_id ORDER BY r.pv DESC, a.publish_date DESC LIMIT ?`
  69. _, err = orm.NewOrm().Raw(sql, pars, limit).QueryRows(&list)
  70. return
  71. }
  72. // GetTopReadRecordArticleListByConditionYx 获取研选阅读量排行榜
  73. func GetTopReadRecordArticleListByConditionYx(limit int, condition string, pars []interface{}) (list []*ArticleListResp, err error) {
  74. sql := `SELECT
  75. a.article_id,
  76. a.title,
  77. a.publish_date,
  78. a.article_type_id,
  79. '31' AS chart_permission_id,
  80. '买方研选' AS permission_name,
  81. COUNT( 1 ) AS pv
  82. FROM
  83. cygx_article_history_record_newpv AS l
  84. JOIN cygx_article AS a ON a.article_id = l.article_id
  85. WHERE
  86. a.publish_status = 1 `
  87. if condition != `` {
  88. sql += condition
  89. }
  90. sql += ` GROUP BY a.article_id ORDER BY pv DESC, a.publish_date DESC LIMIT ?`
  91. _, err = orm.NewOrm().Raw(sql, pars, limit).QueryRows(&list)
  92. return
  93. }
  94. type AddStopTimeRep struct {
  95. ArticleId int `description:"文章ID"`
  96. StopTime int `description:"停留时间"`
  97. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  98. Source string `description:"来源,MOBILE:手机端,PC:电脑端"`
  99. }
  100. type ArticleDetailAddStopTimeRep struct {
  101. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  102. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  103. }