user_read_record.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package models
  2. import (
  3. "time"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. type UserReadRecord struct {
  7. UserReadRecordId int `orm:"pk" description:"id"`
  8. UserId int `description:"用户id"`
  9. ReportId int `description:"报告id"`
  10. ReportTitle string `description:"报告标题"`
  11. // ChartPermissionId1 string `description:"一级品种id"`
  12. // ChartPermissionId2 string `description:"二级品种id"`
  13. ChartPermissionName string `description:"二级品种名称"`
  14. ClassifyId1 int `description:"一级级分类id"`
  15. ClassifyName1 string `description:"一级分类名称"`
  16. ClassifyId2 int `description:"二级分类id"`
  17. ClassifyName2 string `description:"二级分类名称"`
  18. Timestamp int `description:"阅读开始时间戳"`
  19. EndTimestamp int `description:"阅读结束时间戳"`
  20. CreateTime time.Time `description:"创建时间"`
  21. CreateDate string `description:"创建日期"`
  22. StayTime string `description:"停留时间"`
  23. StayTimestamp string `description:"停留时间戳"`
  24. ReportType int `description:"报告类型:1-普通研报;2-pdf研报"`
  25. }
  26. type ReadCntStaitc struct {
  27. CreateDate string
  28. Count int
  29. }
  30. type PermissionCntStaitc struct {
  31. ChartPermissionId int
  32. PermissionName string
  33. Count int
  34. Percent float64
  35. }
  36. func GetUserReadRecordByUserId(userId int, condition string, pars []interface{}, startSize, pageSize int) (items []*UserReadRecord, err error) {
  37. o := orm.NewOrm()
  38. sql := `SELECT DISTINCT ur.user_read_record_id, ur.report_id, ur.report_title, ur.chart_permission_name, ur.classify_name2,
  39. ur.create_time, ur.stay_time, ur.classify_id2
  40. FROM user_read_record AS ur
  41. LEFT JOIN user_read_permission2 AS urp2
  42. ON ur.user_read_record_id = urp2.user_read_record_id
  43. WHERE user_id = ? `
  44. if condition != "" {
  45. sql += condition
  46. }
  47. sql += ` ORDER BY create_time DESC LIMIT ?, ?`
  48. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  49. return
  50. }
  51. func GetUserReadRecordCountByUserId(userId int, condition string, pars []interface{}) (count int, err error) {
  52. o := orm.NewOrm()
  53. sql := `SELECT COUNT(DISTINCT ur.user_read_record_id) AS count
  54. FROM user_read_record AS ur
  55. LEFT JOIN user_read_permission2 AS urp2
  56. ON ur.user_read_record_id = urp2.user_read_record_id
  57. WHERE user_id = ? `
  58. if condition != "" {
  59. sql += condition
  60. }
  61. err = o.Raw(sql, userId, pars).QueryRow(&count)
  62. return
  63. }
  64. func GetStaticReadCnt(condition string, pars []interface{}, startDate, endDate string) (items []*ReadCntStaitc, err error) {
  65. o := orm.NewOrm()
  66. sql := `SELECT create_date, COUNT(*) AS count
  67. FROM user_read_record AS ur
  68. LEFT JOIN user_read_permission2 AS urp
  69. ON ur.user_read_record_id = urp.user_read_record_id
  70. WHERE 1=1 `
  71. if condition != "" {
  72. sql += condition
  73. }
  74. sql += ` AND (ur.create_date BETWEEN ? AND ?) GROUP BY ur.create_date`
  75. _, err = o.Raw(sql, pars, startDate, endDate).QueryRows(&items)
  76. return
  77. }
  78. func GetStaticPermissionCnt(condition string, pars []interface{}) (items []*PermissionCntStaitc, err error) {
  79. o := orm.NewOrm()
  80. sql := `SELECT urp.chart_permission_id, urp.permission_name,COUNT(*) AS count
  81. FROM user_read_permission1 AS urp
  82. LEFT JOIN user_read_record AS ur
  83. ON urp.user_read_record_id = ur.user_read_record_id
  84. WHERE 1=1 `
  85. if condition != "" {
  86. sql += condition
  87. }
  88. sql += ` GROUP BY urp.chart_permission_id`
  89. _, err = o.Raw(sql, pars).QueryRows(&items)
  90. return
  91. }