package models import ( "time" "github.com/beego/beego/v2/client/orm" ) type MyReport struct { MyReportId int `orm:"pk" description:"id"` ReportId int `description:"报告id"` UserId int `description:"用户id"` Title string `description:"标题"` Abstract string `description:"摘要"` Author string `description:"作者"` PublishTime time.Time `description:"发布时间"` Stage int `description:"期数"` CreateTime time.Time `description:"创建时间"` ReportType int `description:"报告类型:1-普通研报;2-pdf研报"` } func (m *MyReport) Insert() (err error) { o := orm.NewOrm() _, err = o.Insert(m) return } func GetMyReportCountByUserIdAndReportId(userId, reportId, reportType int) (count int, err error) { o := orm.NewOrm() sql := `SELECT COUNT(*) AS count FROM my_report WHERE user_id = ? AND report_id = ? AND report_type = ? ` err = o.Raw(sql, userId, reportId, reportType).QueryRow(&count) return } func DeleteMyReportByUserIdAndReportId(userId, reportId, reportType int) (err error) { o := orm.NewOrm() sql := "DELETE FROM my_report WHERE user_id = ? AND report_id = ? AND report_type = ?" _, err = o.Raw(sql, userId, reportId, reportType).Exec() return } func GetMyReportListCountByUserId(userId int) (count int, err error) { o := orm.NewOrm() sql := "SELECT COUNT(*) AS count FROM my_report WHERE user_id = ?" err = o.Raw(sql, userId).QueryRow(&count) return } func GetMyReportListByUserId(userId, startSize, pageSize int) (items []*MyReport, err error) { o := orm.NewOrm() sql := "SELECT * FROM my_report WHERE user_id = ? ORDER BY create_time DESC LIMIT ?, ?" _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items) return }