user_read_record.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package models
  2. import (
  3. "strings"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. type UserReadRecord struct {
  8. UserReadRecordId int `orm:"pk" description:"id"`
  9. UserId int `description:"用户id"`
  10. ReportId int `description:"报告id"`
  11. ReportTitle string `description:"报告标题"`
  12. // ChartPermissionId1 string `description:"一级品种id"`
  13. // ChartPermissionId2 string `description:"二级品种id"`
  14. ChartPermissionName string `description:"二级品种名称"`
  15. ClassifyId1 int `description:"一级级分类id"`
  16. ClassifyName1 string `description:"一级分类名称"`
  17. ClassifyId2 int `description:"二级分类id"`
  18. ClassifyName2 string `description:"二级分类名称"`
  19. ClassifyId3 int `description:"三级分类id"`
  20. ClassifyName3 string `description:"三级分类名称"`
  21. Timestamp int `description:"阅读开始时间戳"`
  22. EndTimestamp int `description:"阅读结束时间戳"`
  23. CreateTime time.Time `description:"创建时间"`
  24. CreateDate string `description:"创建日期"`
  25. StayTime string `description:"停留时间"`
  26. StayTimestamp string `description:"停留时间戳"`
  27. ReportType int `description:"报告类型:1-普通研报;2-pdf研报"`
  28. }
  29. func (u *UserReadRecord) Insert() (insertId int64, err error) {
  30. o := orm.NewOrm()
  31. insertId, err = o.Insert(u)
  32. return
  33. }
  34. func (u *UserReadRecord) Update(cols []string) (err error) {
  35. o := orm.NewOrm()
  36. _, err = o.Update(u, cols...)
  37. return
  38. }
  39. func GetUserReadRecordListById(recordId int) (items *UserReadRecord, err error) {
  40. o := orm.NewOrm()
  41. sql := `SELECT * FROM user_read_record WHERE 1=1 AND user_read_record_id = ?`
  42. err = o.Raw(sql, recordId).QueryRow(&items)
  43. return
  44. }
  45. func GetUserReadRecordCountByReportPdfIdAndUserId(reportId, userId int) (count int, err error) {
  46. o := orm.NewOrm()
  47. sql := `SELECT COUNT(*) AS count FROM user_read_record WHERE 1=1 AND report_id=? AND user_id = ? AND report_type = 2`
  48. err = o.Raw(sql, reportId, userId).QueryRow(&count)
  49. return
  50. }
  51. func GetUserReadRecordListByRcordIds(recordIds []string) (items []*UserReadRecord, err error) {
  52. o := orm.NewOrm()
  53. sql := `SELECT * FROM user_read_record WHERE 1=1 `
  54. var stringIds string
  55. if len(recordIds) > 0 {
  56. sql += ` AND user_read_record_id in (?) `
  57. stringIds = strings.Join(recordIds, ",")
  58. }
  59. _, err = o.Raw(sql, stringIds).QueryRows(&items)
  60. return
  61. }
  62. func UpdateUserReadRecordById(recordId, endTimeStamp, stayTime int, stayTimeStr string) (err error) {
  63. o := orm.NewOrm()
  64. sql := `UPDATE user_read_record SET end_timestamp=?, stay_timestamp=?, stay_time=? WHERE 1=1 AND user_read_record_id = ? `
  65. _, err = o.Raw(sql, endTimeStamp, stayTime, stayTimeStr, recordId).Exec()
  66. return
  67. }
  68. func UpdateUserReadRecordByRecordIds(recordIds []string, endTimeStamp, stayTime int, stayTimeStr string) (err error) {
  69. o := orm.NewOrm()
  70. sql := `UPDATE user_read_record SET end_timestamp=?, stay_timestamp=?, stay_time=? WHERE 1=1 `
  71. var stringIds string
  72. if len(recordIds) > 0 {
  73. sql += ` AND user_read_record_id in (?) `
  74. stringIds = strings.Join(recordIds, ",")
  75. }
  76. _, err = o.Raw(sql, endTimeStamp, stayTime, stayTimeStr, stringIds).Exec()
  77. return
  78. }