123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- package models
- import (
- "eta/eta_mini_crm/utils"
- "time"
- "github.com/beego/beego/v2/client/orm"
- )
- type ReportPushStatus struct {
- ReportPushStatusId int `orm:"pk"`
- ReportId int `description:"报告id"`
- State int `description:"报告状态:0-未推送,1-已推送"`
- Title string `description:"报告标题"`
- Abstract string `description:"报告摘要"`
- Stage int `description:"期数"`
- ClassifyIdFirst int `description:"一级分类id"`
- ClassifyNameFirst string `description:"一级分类名称"`
- ClassifyIdSecond int `description:"二级分类id"`
- ClassifyNameSecond string `description:"二级分类名称"`
- ClassifyIdThird int `description:"三级分类id"`
- ClassifyNameThird string `description:"三级分类名称"`
- Author string `description:"报告作者"`
- ReportType int `description:"报告类型:1-eta报告 2-pdf报告"`
- PublishTime time.Time `description:"报告发布时间"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- PushTime time.Time `description:"推送时间"`
- }
- type Report struct {
- Id int `description:"报告id"` // id
- ClassifyIdFirst int `description:"一级分类id"` // 一级分类id
- ClassifyNameFirst string `description:"一级分类名称"` // 一级分类名称
- ClassifyIdSecond int `description:"二级分类id"` // 二级分类id
- ClassifyNameSecond string `description:"二级分类名称"` // 二级分类名称
- ClassifyIdThird int `description:"三级分类id"` // 三级分类id
- ClassifyNameThird string `description:"三级分类名称"` // 三级分类名称
- Title string `description:"报告标题"` // 标题
- Abstract string `description:"摘要"` // 摘要
- Author string `description:"作者"` // 作者
- CreateTime time.Time `description:"创建时间"` // 创建时间
- ModifyTime time.Time `description:"修改时间"` // 修改时间
- PublishTime time.Time `description:"发布时间"` // 发布时间
- Stage int `description:"期数"` // 期数
- ContentModifyTime time.Time `description:"内容更新时间"` // 内容更新时间
- ReportCreateTime time.Time `description:"创建时间"` // 报告时间创建时间
- }
- type ReportPushView struct {
- ReportPushStatusId int `orm:"pk"`
- ReportId int `description:"报告id"`
- Title 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:"二级分类名称"`
- Author string `description:"报告作者"`
- State int `description:"报告状态:0-未推送,1-已推送"`
- PushTime string `description:"推送时间"`
- PublishTime string `description:"报告发布时间"`
- ReportType int `description:"报告类型:1-eta报告 2-pdf报告"`
- CreateTime string `description:"创建时间"`
- ModifyTime string `description:"修改时间"`
- }
- func (r *ReportPushStatus) Insert() (insertId int64, err error) {
- o := orm.NewOrm()
- insertId, err = o.Insert(r)
- return
- }
- func (r *ReportPushStatus) MultiInsert(items []*ReportPushStatus) (err error) {
- o := orm.NewOrm()
- _, err = o.InsertMulti(500, items)
- return
- }
- func (r *ReportPushStatus) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(r, cols...)
- return
- }
- func (r *ReportPushStatus) Delete() (err error) {
- o := orm.NewOrm()
- _, err = o.Delete(r)
- return
- }
- func GetReportPushStatusByReportId(reportPushStatusId, state int) (item *ReportPushStatus, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM report_push_status WHERE report_push_status_id=? AND state=?`
- err = o.Raw(sql, reportPushStatusId, state).QueryRow(&item)
- return
- }
- func GetReportPushStatusByReportIdAndState(reportId []int, state int) (items []*ReportPushStatus, err error) {
- if len(reportId) == 0 {
- return
- }
- o := orm.NewOrm()
- sql := `SELECT * FROM report_push_status WHERE report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `) AND state=?`
- _, err = o.Raw(sql, reportId, state).QueryRows(&items)
- return
- }
- func GetReportPushStatusByIdAndState(Id []int, state int) (items []*ReportPushStatus, err error) {
- if len(Id) == 0 {
- return
- }
- o := orm.NewOrm()
- sql := `SELECT * FROM report_push_status WHERE report_push_status_id IN (` + utils.GetOrmReplaceHolder(len(Id)) + `) AND state=?`
- _, err = o.Raw(sql, Id, state).QueryRows(&items)
- return
- }
- func GetReportPushStatusByReportIds(reportType int, reportId []int) (items []*ReportPushStatus, err error) {
- if len(reportId) == 0 {
- return
- }
- o := orm.NewOrm()
- sql := `SELECT * FROM report_push_status WHERE report_type=? AND report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `) `
- _, err = o.Raw(sql, reportType, reportId).QueryRows(&items)
- return
- }
- func GetReportPushStatusListByCondition(condition, sortCondition string, pars []interface{}, startSize, pageSize int) (items []*ReportPushView, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM report_push_status WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- if sortCondition != "" {
- sql += sortCondition
- }
- sql += ` LIMIT ?,? `
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetReportByCondition(condition string, pars []interface{}) (items []*Report, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM report WHERE 1=1 AND (state=2 OR state=6) `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars...).QueryRows(&items)
- return
- }
- func GetReportIdListByCondition(condition string, pars []interface{}) (reportId []int, err error) {
- o := orm.NewOrm()
- sql := `SELECT report_id FROM report_push_status WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars).QueryRows(&reportId)
- return
- }
- func GetReportPushStatusIdListByCondition(condition string, pars []interface{}) (reportPushStatusId []int, err error) {
- o := orm.NewOrm()
- sql := `SELECT report_push_status_id FROM report_push_status WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars).QueryRows(&reportPushStatusId)
- return
- }
- func GetReportCountById(id int) (count int, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT COUNT(*) AS count FROM report WHERE (state=2 OR state=6) AND id=?`
- err = o.Raw(sql, id).QueryRow(&count)
- return
- }
- func GetReportCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(*) AS count FROM report_push_status WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- // BatchPushReport 批量推送报告
- func BatchPushReport(reportPushStatusId []int) (err error) {
- if len(reportPushStatusId) == 0 {
- return
- }
- o := orm.NewOrm()
- sql := `UPDATE report_push_status SET state=1, push_time=NOW() WHERE report_push_status_id IN (` + utils.GetOrmReplaceHolder(len(reportPushStatusId)) + `)`
- _, err = o.Raw(sql, reportPushStatusId).Exec()
- return
- }
- // BatchPushCancelReport 批量撤销推送报告
- func BatchPushCancelReport(reportPushStatusId []int) (err error) {
- if len(reportPushStatusId) == 0 {
- return
- }
- o := orm.NewOrm()
- sql := `UPDATE report_push_status SET state=0, modify_time=NOW() WHERE report_push_status_id IN (` + utils.GetOrmReplaceHolder(len(reportPushStatusId)) + `)`
- _, err = o.Raw(sql, reportPushStatusId).Exec()
- return
- }
- // BatchAddReportPushStatus 批量添加报告
- func BatchAddReportPushStatus(items []*ReportPushStatus) (err error) {
- if len(items) == 0 {
- return
- }
- o := orm.NewOrm()
- _, err = o.InsertMulti(100, items)
- return
- }
- func GetMaxSyncIdReportPush(report_type int) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT MAX(report_id) AS max_id FROM report_push_status WHERE report_type=?`
- err = o.Raw(sql, report_type).QueryRow(&count)
- return
- }
- func GetBatchReport(maxId, batchSize int) (items []*Report, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM report WHERE id>? AND (state=2 OR state=6) LIMIT ?`
- o.Raw(sql, maxId, batchSize).QueryRows(&items)
- return
- }
|