123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- package models
- import (
- "eta/eta_mini_crm_ht/utils"
- "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,plate_name"
- taskColumns = "id,author,published_time"
- )
- type Report struct {
- Id int `description:"id"`
- OrgId int `description:"组织id"`
- Source ReportSource `description:"来源"`
- Title string `description:"标题"`
- Abstract string `description:"摘要"`
- Author string `description:"作者"`
- CoverSrc int `description:"封面"`
- ClassifyId int `description:"分类Id"`
- PlateName string `description:"板块名称"`
- Status ReportStatus `description:"状态"`
- SendStatus SendStatus `description:"发送状态"`
- PublishedTime string `description:"发布时间"`
- CreatedTime time.Time `description:"创建时间"`
- UpdatedTime time.Time `description:"更新时间"`
- }
- type ReportView struct {
- Id int
- OrgId int
- Source ReportSource
- Title string
- Abstract string
- Author string
- CoverSrc string
- PlateName string
- PermissionNames 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,
- PlateName: r.PlateName,
- SendStatus: r.SendStatus,
- PublishedTime: r.PublishedTime,
- }
- return
- }
- func (r *Report) TableName() string {
- return "reports"
- }
- func (r *Report) UpdateSendStatus(status SendStatus) (err error) {
- o := orm.NewOrm()
- r.SendStatus = status
- _, err = o.Update(r, "send_status")
- return
- }
- 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 distinct id ,title,abstract,author,published_time,send_status,source,classify_id,plate_name FROM reports WHERE id =?`
- err = o.Raw(sql, id).QueryRow(&items)
- return
- }
- func GetReportIdByPermissionIds(id int) (items *Report, err error) {
- o := orm.NewOrm()
- sql := `SELECT distinct id ,title,abstract,author,published_time,send_status,source,classify_id,plate_name 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
- }
- func GetETAReportById(id int) (classifyId int, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT COALESCE(NULLIF(classify_id_third,0),NULLIF(classify_id_second,0),classify_id_first) classify_id FROM report WHERE id =?`
- err = o.Raw(sql, id).QueryRow(&classifyId)
- return
- }
- func GetETAReportIdByClassifyId(id int) (classifyId int, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT COALESCE(NULLIF(classify_id_third,0),NULLIF(classify_id_second,0),classify_id_first) classify_id FROM report WHERE id=? `
- err = o.Raw(sql, id).QueryRow(&classifyId)
- return
- }
- func GetReportIdByClassifyId(ids []int) (reportIds []int, err error) {
- o := orm.NewOrm()
- condition := "source='ETA' and classify_id in (" + utils.GetOrmReplaceHolder(len(ids)) + ") "
- sql := `SELECT distinct id FROM reports WHERE ` + condition
- _, err = o.Raw(sql, ids).QueryRows(&reportIds)
- return
- }
- func GetReportIdByPlateName(names []string) (reportIds []int, err error) {
- o := orm.NewOrm()
- condition := "source='HT' and plate_name in (" + utils.GetOrmReplaceHolder(len(names)) + ") "
- sql := `SELECT distinct id FROM reports WHERE ` + condition
- _, err = o.Raw(sql, names).QueryRows(&reportIds)
- return
- }
- func GetReportByIds(sortCondition string, ids []int, startSize int, pageSize int) (reports []Report, err error) {
- o := orm.NewOrm()
- condition := "id in (" + utils.GetOrmReplaceHolder(len(ids)) + ") " + sortCondition + " limit ?,?"
- sql := `SELECT * FROM reports WHERE ` + condition
- _, err = o.Raw(sql, ids, startSize, pageSize).QueryRows(&reports)
- return
- }
- func GetReportIdsByCondition(condition string, pars []interface{}) (ids []int, err error) {
- o := orm.NewOrm()
- sql := `SELECT id FROM reports WHERE 1=1 ` + condition
- _, err = o.Raw(sql, pars).QueryRows(&ids)
- return
- }
|