123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- package models
- import (
- "eta/eta_mini_api/utils"
- "fmt"
- "time"
- "github.com/beego/beego/v2/client/orm"
- )
- type ReportPdf struct {
- ReportPdfId int `orm:"pk" description:"id"`
- PdfUrl string `description:"pdf文件URL"`
- Title string `description:"pdf文件标题"`
- Author string `description:"作者"`
- Abstract string `description:"摘要"`
- ClassifyIdFirst int `description:"一级分类id"`
- ClassifyNameFirst string `description:"一级分类名称"`
- ClassifyIdSecond int `description:"二级分类id"`
- ClassifyNameSecond string `description:"二级分类名称"`
- ClassifyIdThird int `description:"三级分类id"`
- ClassifyNameThird string `description:"三级分类名称"`
- Stage int `description:"期数"`
- PublishTime time.Time `description:"发布时间"`
- ModifyTime time.Time `description:"更新时间"`
- Pv int `description:"pv"`
- Uv int `description:"uv"`
- SysUserId int `description:"创建人id"`
- SysRealName string `description:"创建人姓名"`
- State int `description:"状态:1-已发布;2-未发布"`
- }
- type ReportPdfView struct {
- ReportPdfId int `orm:"pk" description:"id"`
- PdfUrl string `description:"pdf文件URL"`
- Title string `description:"pdf文件标题"`
- Author string `description:"作者"`
- Abstract string `description:"摘要"`
- ClassifyIdFirst int `description:"一级分类id"`
- ClassifyNameFirst string `description:"一级分类名称"`
- ClassifyIdSecond int `description:"二级分类id"`
- ClassifyNameSecond string `description:"二级分类名称"`
- ClassifyIdThird int `description:"三级分类id"`
- ClassifyNameThird string `description:"三级分类名称"`
- Stage int `description:"期数"`
- PublishTime string `description:"发布时间"`
- ModifyTime string `description:"更新时间"`
- Pv int `description:"pv"`
- Uv int `description:"uv"`
- SysUserId int `description:"创建人id"`
- SysRealName string `description:"创建人姓名"`
- State int `description:"状态:1-已发布;2-未发布"`
- IsPublic bool `description:"是否公开"`
- IsCollect bool `description:"是否收藏"`
- }
- func GetRecentReportPdfList(startSize, pageSize int) (items []*ReportPdf, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM report_pdf WHERE state=1 ORDER BY publish_time DESC LIMIT ?,?`
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetReportPdfListByCondition(firstClassifyIds, secondClassifyIds, thirdClassifyIds []int, condition string, startSize, pageSize int) (reportPdfs []*ReportPdf, err error) {
- if len(firstClassifyIds) == 0 && len(secondClassifyIds) == 0 && len(thirdClassifyIds) == 0 {
- return
- }
- o := orm.NewOrm()
- sql := `SELECT * FROM report_pdf WHERE 1=1 AND (1=2`
- if len(firstClassifyIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(firstClassifyIds)))
- }
- if len(secondClassifyIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(secondClassifyIds)))
- }
- if len(thirdClassifyIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(thirdClassifyIds)))
- }
- sql += ")"
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY publish_time DESC LIMIT ?,?`
- _, err = o.Raw(sql, firstClassifyIds, secondClassifyIds, thirdClassifyIds, startSize, pageSize).QueryRows(&reportPdfs)
- return
- }
- func GetReportPdfDailyList() (reportPdfs []*ReportPdf, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM report_pdf WHERE 1=1 AND state=1 AND DATE(publish_time) = DATE(NOW()) ORDER BY publish_time DESC `
- _, err = o.Raw(sql).QueryRows(&reportPdfs)
- return
- }
- func GetReportPdfCountByCondition(firstClassifyIds, secondClassifyIds, thirdClassifyIds []int, condition string) (count int, err error) {
- if len(firstClassifyIds) == 0 && len(secondClassifyIds) == 0 && len(thirdClassifyIds) == 0 {
- return
- }
- o := orm.NewOrm()
- sql := `SELECT COUNT(*) AS count FROM report_pdf WHERE 1=1 AND (1=2 `
- if len(firstClassifyIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(firstClassifyIds)))
- }
- if len(secondClassifyIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(secondClassifyIds)))
- }
- if len(thirdClassifyIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(thirdClassifyIds)))
- }
- sql += ` )`
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, firstClassifyIds, secondClassifyIds, thirdClassifyIds).QueryRow(&count)
- return
- }
- func GetReportPdfCountById(id int) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(*) AS count FROM report_pdf WHERE report_pdf_id = ? `
- err = o.Raw(sql, id).QueryRow(&count)
- return
- }
- func GetReportPdfById(id int) (item *ReportPdfView, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM report_pdf WHERE report_pdf_id = ? `
- err = o.Raw(sql, id).QueryRow(&item)
- return
- }
- // 更新pv
- func UpdateReportPdfPv(id int) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE report_pdf SET pv = pv + 1 WHERE report_pdf_id = ?`
- _, err = o.Raw(sql, id).Exec()
- return
- }
- // 更新uv和pv
- func UpdateReportPdfUvAndPv(id int) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE report_pdf SET uv = uv + 1, pv = pv + 1 WHERE report_pdf_id = ?`
- _, err = o.Raw(sql, id).Exec()
- return
- }
|