user_read_record.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. Timestamp int `description:"阅读开始时间戳"`
  20. EndTimestamp int `description:"阅读结束时间戳"`
  21. CreateTime time.Time `description:"创建时间"`
  22. CreateDate string `description:"创建日期"`
  23. StayTime string `description:"停留时间"`
  24. StayTimestamp string `description:"停留时间戳"`
  25. ReportType int `description:"报告类型:1-普通研报;2-pdf研报"`
  26. }
  27. func (u *UserReadRecord) Insert() (insertId int64, err error) {
  28. o := orm.NewOrm()
  29. insertId, err = o.Insert(u)
  30. return
  31. }
  32. func (u *UserReadRecord) Update(cols []string) (err error) {
  33. o := orm.NewOrm()
  34. _, err = o.Update(u, cols...)
  35. return
  36. }
  37. func GetUserReadRecordListById(recordId int) (items *UserReadRecord, err error) {
  38. o := orm.NewOrm()
  39. sql := `SELECT * FROM user_read_record WHERE 1=1 AND user_read_record_id = ?`
  40. err = o.Raw(sql, recordId).QueryRow(&items)
  41. return
  42. }
  43. func GetUserReadRecordListByRcordIds(recordIds []string) (items []*UserReadRecord, err error) {
  44. o := orm.NewOrm()
  45. sql := `SELECT * FROM user_read_record WHERE 1=1 `
  46. var stringIds string
  47. if len(recordIds) > 0 {
  48. sql += ` AND user_read_record_id in (?) `
  49. stringIds = strings.Join(recordIds, ",")
  50. }
  51. _, err = o.Raw(sql, stringIds).QueryRows(&items)
  52. return
  53. }
  54. func UpdateUserReadRecordById(recordId, endTimeStamp, stayTime int, stayTimeStr string) (err error) {
  55. o := orm.NewOrm()
  56. sql := `UPDATE user_read_record SET end_timestamp=?, stay_timestamp=?, stay_time=? WHERE 1=1 AND user_read_record_id = ? `
  57. _, err = o.Raw(sql, endTimeStamp, stayTime, stayTimeStr, recordId).Exec()
  58. return
  59. }
  60. func UpdateUserReadRecordByRecordIds(recordIds []string, endTimeStamp, stayTime int, stayTimeStr string) (err error) {
  61. o := orm.NewOrm()
  62. sql := `UPDATE user_read_record SET end_timestamp=?, stay_timestamp=?, stay_time=? WHERE 1=1 `
  63. var stringIds string
  64. if len(recordIds) > 0 {
  65. sql += ` AND user_read_record_id in (?) `
  66. stringIds = strings.Join(recordIds, ",")
  67. }
  68. _, err = o.Raw(sql, endTimeStamp, stayTime, stayTimeStr, stringIds).Exec()
  69. return
  70. }