user_source_click_flow.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. var (
  8. SourceTypeMap = map[SourceType]string{
  9. ReportSourceType: "报告",
  10. VideoSourceType: "视频",
  11. AudioSourceType: "音频",
  12. }
  13. )
  14. type UserSourceClickFlow struct {
  15. Id int
  16. TraceId string
  17. UseId int
  18. Mobile string
  19. SourceId int
  20. SourceTitle string
  21. SourceType SourceType
  22. ClickTime time.Time
  23. ReadDurationSeconds int64
  24. IpAddress string
  25. Hidden int
  26. Location string
  27. Referer string
  28. AdditionalData string
  29. }
  30. func (m *UserSourceClickFlow) ToView() UserSourceClickFlowView {
  31. return UserSourceClickFlowView{
  32. ClickTime: m.ClickTime.Format(time.DateTime),
  33. SourceId: m.SourceId,
  34. SourceName: getSourceName(m.SourceType),
  35. SourceTitle: m.SourceTitle,
  36. ReadDurationMinutes: parseMinutes(m.ReadDurationSeconds / 1000),
  37. }
  38. }
  39. func getSourceName(sourceType SourceType) string {
  40. return SourceTypeMap[sourceType]
  41. }
  42. func parseMinutes(seconds int64) string {
  43. minutesPart := seconds / 60
  44. secondsPart := seconds % 60
  45. return fmt.Sprintf("%d分%02d秒", minutesPart, secondsPart)
  46. }
  47. type UserSourceClickFlowView struct {
  48. SourceId int
  49. SourceName string
  50. SourceTitle string
  51. PermissionNames string
  52. ClickTime string
  53. ReadDurationMinutes string
  54. }
  55. func GetUserSourceClickFlowListByUserId(userId int, condition string, pars []interface{}, startSize, pageSize int) (items []*UserSourceClickFlow, err error) {
  56. o := orm.NewOrm()
  57. sql := `SELECT * FROM user_source_click_flows WHERE user_id=? ` + condition +
  58. ` ORDER BY click_time DESC LIMIT ?,?`
  59. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  60. return
  61. }
  62. func GetUserSourceClickFlowListCountByUserId(userId int, condition string, pars []interface{}) (total int, err error) {
  63. o := orm.NewOrm()
  64. sql := `SELECT count(*) FROM user_source_click_flows WHERE user_id=? ` + condition
  65. err = o.Raw(sql, userId, pars).QueryRow(&total)
  66. return
  67. }