package models import ( "fmt" "github.com/beego/beego/v2/client/orm" "time" ) var ( SourceTypeMap = map[SourceType]string{ ReportSourceType: "报告", VideoSourceType: "视频", AudioSourceType: "音频", } ) type UserSourceClickFlow struct { Id int TraceId string UseId int Mobile string SourceId int SourceTitle string SourceType SourceType ClickTime time.Time ReadDurationSeconds int64 IpAddress string Hidden int Location string Referer string AdditionalData string } func (m *UserSourceClickFlow) ToView() UserSourceClickFlowView { return UserSourceClickFlowView{ ClickTime: m.ClickTime.Format(time.DateTime), SourceId: m.SourceId, SourceName: getSourceName(m.SourceType), SourceTitle: m.SourceTitle, ReadDurationMinutes: parseMinutes(m.ReadDurationSeconds / 1000), } } func getSourceName(sourceType SourceType) string { return SourceTypeMap[sourceType] } func parseMinutes(seconds int64) string { minutesPart := seconds / 60 secondsPart := seconds % 60 return fmt.Sprintf("%d分%02d秒", minutesPart, secondsPart) } type UserSourceClickFlowView struct { SourceId int SourceName string SourceTitle string PermissionNames string ClickTime string ReadDurationMinutes string } func GetUserSourceClickFlowListByUserId(userId int, condition string, pars []interface{}, startSize, pageSize int) (items []*UserSourceClickFlow, err error) { o := orm.NewOrm() sql := `SELECT * FROM user_source_click_flows WHERE user_id=? ` + condition + ` ORDER BY click_time DESC LIMIT ?,?` _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items) return } func GetUserSourceClickFlowListCountByUserId(userId int, condition string, pars []interface{}) (total int, err error) { o := orm.NewOrm() sql := `SELECT count(*) FROM user_source_click_flows WHERE user_id=? ` + condition err = o.Raw(sql, userId, pars).QueryRow(&total) return }