user_read_record.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. }
  26. func (u *UserReadRecord) Insert() (insertId int64, err error) {
  27. o := orm.NewOrm()
  28. insertId, err = o.Insert(u)
  29. return
  30. }
  31. func (u *UserReadRecord) Update(cols []string) (err error) {
  32. o := orm.NewOrm()
  33. _, err = o.Update(u, cols...)
  34. return
  35. }
  36. func GetUserReadRecordListById(recordId int) (items *UserReadRecord, err error) {
  37. o := orm.NewOrm()
  38. sql := `SELECT * FROM user_read_record WHERE 1=1 AND user_read_record_id = ?`
  39. err = o.Raw(sql, recordId).QueryRow(&items)
  40. return
  41. }
  42. func GetUserReadRecordListByRcordIds(recordIds []string) (items []*UserReadRecord, err error) {
  43. o := orm.NewOrm()
  44. sql := `SELECT * FROM user_read_record WHERE 1=1 `
  45. var stringIds string
  46. if len(recordIds) > 0 {
  47. sql += ` AND user_read_record_id in (?) `
  48. stringIds = strings.Join(recordIds, ",")
  49. }
  50. _, err = o.Raw(sql, stringIds).QueryRows(&items)
  51. return
  52. }
  53. func UpdateUserReadRecordById(recordId, endTimeStamp, stayTime int, stayTimeStr string) (err error) {
  54. o := orm.NewOrm()
  55. sql := `UPDATE user_read_record SET end_timestamp=?, stay_timestamp=?, stay_time=? WHERE 1=1 AND user_read_record_id = ? `
  56. _, err = o.Raw(sql, endTimeStamp, stayTime, stayTimeStr, recordId).Exec()
  57. return
  58. }
  59. func UpdateUserReadRecordByRecordIds(recordIds []string, endTimeStamp, stayTime int, stayTimeStr string) (err error) {
  60. o := orm.NewOrm()
  61. sql := `UPDATE user_read_record SET end_timestamp=?, stay_timestamp=?, stay_time=? WHERE 1=1 `
  62. var stringIds string
  63. if len(recordIds) > 0 {
  64. sql += ` AND user_read_record_id in (?) `
  65. stringIds = strings.Join(recordIds, ",")
  66. }
  67. _, err = o.Raw(sql, endTimeStamp, stayTime, stayTimeStr, stringIds).Exec()
  68. return
  69. }