user_read_record.go 2.7 KB

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