123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package models
- import (
- "time"
- "github.com/beego/beego/v2/client/orm"
- )
- type ReportStatus string
- type ReportSource string
- const (
- SourceETA ReportSource = "ETA"
- SourceHT ReportSource = "HT"
- StatusInit ReportStatus = "INIT"
- StatusPending ReportStatus = "PENDING"
- StatusDone ReportStatus = "DONE"
- MaxBatchNum = 1000
- CommonColumns = "id,org_id,author,abstract,title,source,cover_src,published_time"
- taskColumns = "id,author,published_time"
- )
- type Report struct {
- ID int
- OrgID int
- Source ReportSource
- Title string
- Abstract string
- Author string
- CoverSrc string
- Status ReportStatus
- SendStatus SendStatus
- PublishedTime string
- CreatedTime time.Time
- UpdatedTime time.Time
- }
- type ReportView struct {
- ID int
- OrgID int
- Source ReportSource
- Title string
- Abstract string
- Author string
- CoverSrc string
- SendStatus SendStatus
- PublishedTime string
- }
- func (r *Report) ToView() (item *ReportView) {
- item = &ReportView{
- ID: r.ID,
- OrgID: r.OrgID,
- Source: r.Source,
- Title: r.Title,
- Abstract: r.Abstract,
- Author: r.Author,
- CoverSrc: r.CoverSrc,
- SendStatus: r.SendStatus,
- PublishedTime: r.PublishedTime,
- }
- return
- }
- func (r *Report) UpdateSendStatus() (err error) {
- o := orm.NewOrm()
- r.SendStatus = SEND
- _, err = o.Update(r, "send_status")
- return
- }
- func (r *Report) tableName() string {
- return "reports"
- }
- func GetReportCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(*) AS count FROM reports WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func GetReportById(id int) (items *Report, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM reports WHERE id =?`
- err = o.Raw(sql, id).QueryRow(&items)
- return
- }
- func GetReportByCondition(condition, sortCondition string, pars []interface{}, startPage, pageSize int) (items []*Report, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM reports WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- if sortCondition != "" {
- sql += sortCondition // 排序
- }
- sql += ` LIMIT ?,?`
- _, err = o.Raw(sql, pars, startPage, pageSize).QueryRows(&items)
- return
- }
- func GetETAReportIdsByCondition(condition string, pars []interface{}) (ids []int, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT distinct id FROM report WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars).QueryRows(&ids)
- return
- }
|