123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package models
- import (
- "eta/eta_mini_crm_ht/utils"
- "time"
- "github.com/beego/beego/v2/client/orm"
- )
- type ReportPdf struct {
- ReportPdfId int `orm:"pk" description:"id"`
- PdfUrl string `description:"pdf文件URL"`
- PdfName string `description:"pdf文件名称"`
- 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:"状态"`
- }
- type ReportPdfView struct {
- ReportPdfId int `orm:"pk" description:"id"`
- PdfUrl string `description:"pdf文件URL"`
- PdfName string `description:"pdf文件名称"`
- 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 time.Time `description:"更新时间"`
- Pv int `description:"pv"`
- Uv int `description:"uv"`
- SysUserId int `description:"创建人id"`
- SysRealName string `description:"创建人姓名"`
- State int `description:"状态"`
- }
- func (r *ReportPdf) Insert() (insertId int64, err error) {
- o := orm.NewOrm()
- // 计算研报期数
- sql := `SELECT MAX(stage) + 1 AS count FROM report_pdf WHERE classify_id_second=?`
- err = o.Raw(sql, r.ClassifyIdSecond).QueryRow(&r.Stage)
- if r.Stage == 0 {
- r.Stage = 1
- }
- if err != nil {
- return
- }
- insertId, err = o.Insert(r)
- return
- }
- func (r *ReportPdf) ToView() (item *ReportPdfView) {
- item = new(ReportPdfView)
- item.ReportPdfId = r.ReportPdfId
- item.PdfUrl = r.PdfUrl
- item.PdfName = r.PdfName
- item.Title = r.Title
- item.Author = r.Author
- item.Abstract = r.Abstract
- item.ClassifyIdFirst = r.ClassifyIdFirst
- item.ClassifyNameFirst = r.ClassifyNameFirst
- item.ClassifyIdSecond = r.ClassifyIdSecond
- item.ClassifyNameSecond = r.ClassifyNameSecond
- item.Stage = r.Stage
- item.State = r.State
- item.PublishTime = r.PublishTime.Format(utils.FormatDateTime)
- item.ModifyTime = r.ModifyTime
- item.Pv = r.Pv
- item.Uv = r.Uv
- item.SysUserId = r.SysUserId
- item.SysRealName = r.SysRealName
- return
- }
- func (r *ReportPdf) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(r, cols...)
- return
- }
- func (r *ReportPdf) Delete() (err error) {
- o := orm.NewOrm()
- _, err = o.Delete(r)
- return
- }
- func GetReportPdfCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(*) AS count FROM report_pdf WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func GetReportPdfByCondition(condition, sortCondition string, pars []interface{}, startPage, pageSize int) (items []*ReportPdf, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM report_pdf WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- if sortCondition != "" {
- sql += sortCondition // 排序
- }
- sql += ` LIMIT ?,?`
- _, err = o.Raw(sql, pars, startPage, pageSize).QueryRows(&items)
- return
- }
- func GetReportPdfById(id int) (item *ReportPdf, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM report_pdf WHERE report_pdf_id=?`
- err = o.Raw(sql, id).QueryRow(&item)
- return
- }
|