1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package models
- import (
- "fmt"
- "time"
- "github.com/beego/beego/v2/client/orm"
- )
- // UserReadRecord 用户阅读统计表
- type UserReadRecord struct {
- Id int `orm:"column(id);pk"`
- UserId int `description:"用户ID"`
- ReportId int `description:"报告ID"`
- ReportTitle string `description:"报告标题"`
- ClassifyIdFirst int `description:"一级分类ID"`
- ClassifyNameFirst string `description:"一级分类名称"`
- ClassifyIdSecond int `description:"二级分类ID"`
- ClassifyNameSecond string `description:"二级分类名称"`
- ClassifyIdThird int `description:"三级分类ID"`
- ClassifyNameThird string `description:"三级分类名称"`
- StartTimestamp int `description:"阅读开始时间戳"`
- EndTimestamp int `description:"阅读结束时间戳"`
- ReportSource int `description:"报告来源:1-研报中心;2-文档管理库"`
- CreateTime time.Time `description:"创建时间"`
- }
- func (m *UserReadRecord) TableName() string {
- return "user_read_record"
- }
- type UserReadRecordCols struct {
- PrimaryId string
- UserId string
- ReportId string
- ReportTitle string
- ClassifyIdFirst string
- ClassifyNameFirst string
- ClassifyIdSecond string
- ClassifyNameSecond string
- ClassifyIdThird string
- ClassifyNameThird string
- StartTimestamp string
- EndTimestamp string
- ReportSource string
- CreateTime string
- }
- func (m *UserReadRecord) Cols() UserReadRecordCols {
- return UserReadRecordCols{
- PrimaryId: "id",
- UserId: "user_id",
- ReportId: "report_id",
- ReportTitle: "report_title",
- ClassifyIdFirst: "classify_id_first",
- ClassifyNameFirst: "classify_name_first",
- ClassifyIdSecond: "classify_id_second",
- ClassifyNameSecond: "classify_name_second",
- ClassifyIdThird: "classify_id_third",
- ClassifyNameThird: "classify_name_third",
- StartTimestamp: "start_timestamp",
- EndTimestamp: "end_timestamp",
- ReportSource: "report_source",
- CreateTime: "create_time",
- }
- }
- func (m *UserReadRecord) Create() (err error) {
- o := orm.NewOrm()
- id, err := o.Insert(m)
- if err != nil {
- return
- }
- m.Id = int(id)
- return
- }
- func (m *UserReadRecord) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(m, cols...)
- return
- }
- func (m *UserReadRecord) GetItemById(id int) (item *UserReadRecord, err error) {
- o := orm.NewOrm()
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
- err = o.Raw(sql, id).QueryRow(&item)
- return
- }
|