package models import ( "eta/eta_hub/utils" "fmt" "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" "strings" "time" ) type EnglishReport struct { Id int `orm:"column(id)" description:"报告Id"` AddType int `description:"新增方式:1:新增报告,2:继承报告"` ClassifyIdFirst int `description:"一级分类id"` ClassifyNameFirst string `description:"一级分类名称"` ClassifyIdSecond int `description:"二级分类id"` ClassifyNameSecond string `description:"二级分类名称"` Title string `description:"标题"` Abstract string `description:"摘要"` Author string `description:"作者"` Frequency string `description:"频度"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"` PublishTime time.Time `description:"发布时间"` PrePublishTime time.Time `description:"预发布时间"` Stage int `description:"期数"` Content string `description:"内容"` VideoUrl string `description:"音频文件URL"` VideoName string `description:"音频文件名称"` VideoPlaySeconds string `description:"音频播放时长"` VideoSize string `description:"音频文件大小,单位M"` ContentSub string `description:"内容前两个章节"` ReportCode string `description:"报告唯一编码"` Pv int `description:"Pv"` PvEmail int `description:"邮箱PV"` EmailState int `description:"群发邮件状态: 0-未发送; 1-已发送"` Overview string `description:"英文概述部分"` KeyTakeaways string `description:"关键点"` FromReportId int `description:"继承的报告ID(英文策略报告ID)"` AdminId int `description:"创建者账号"` AdminRealName string `description:"创建者姓名"` ApproveTime time.Time `description:"审批时间"` ApproveId int `description:"审批ID"` } func (m *EnglishReport) Update(cols []string) (err error) { o := orm.NewOrmUsingDB("rddp") _, err = o.Update(m, cols...) return } func (m *EnglishReport) GetItemById(id int) (item *EnglishReport, err error) { o := orm.NewOrmUsingDB("rddp") sql := `SELECT * FROM english_report WHERE id = ? LIMIT 1` err = o.Raw(sql, id).QueryRow(&item) return } func (m *EnglishReport) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { o := orm.NewOrmUsingDB("rddp") sql := fmt.Sprintf(`SELECT COUNT(1) FROM english_report WHERE 1=1 %s`, condition) err = o.Raw(sql, pars).QueryRow(&count) return } func (m *EnglishReport) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EnglishReport, err error) { o := orm.NewOrmUsingDB("rddp") fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY create_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM english_report WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } func (m *EnglishReport) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EnglishReport, err error) { o := orm.NewOrmUsingDB("rddp") fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM english_report WHERE 1=1 %s %s LIMIT ?,?`, fields, condition, order) _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return } type EnglishReportItem struct { Id int `description:"报告Id"` ReportCode string `description:"报告唯一编码"` ClassifyIdFirst int `description:"一级分类id"` ClassifyNameFirst string `description:"一级分类名称"` ClassifyIdSecond int `description:"二级分类id"` ClassifyNameSecond string `description:"二级分类名称"` Title string `description:"标题"` Abstract string `description:"摘要"` Author string `description:"作者"` Frequency string `description:"频度"` State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"` Stage int `description:"期数"` Content string `description:"内容"` VideoUrl string `description:"音频文件URL"` VideoName string `description:"音频文件名称"` VideoPlaySeconds string `description:"音频播放时长"` VideoSize string `description:"音频文件大小,单位M"` AdminId int `description:"创建者账号"` AdminRealName string `description:"创建者姓名"` ApproveTime string `description:"审批时间"` PublishTime string `description:"发布时间"` CreateTime string `description:"创建时间"` ModifyTime string `description:"修改时间"` } func FormatEnglishReport2Item(origin *EnglishReport) (item *EnglishReportItem) { if origin == nil { return } item = new(EnglishReportItem) item.Id = origin.Id item.ReportCode = origin.ReportCode item.ClassifyIdFirst = origin.ClassifyIdFirst item.ClassifyNameFirst = origin.ClassifyNameFirst item.ClassifyIdSecond = origin.ClassifyIdSecond item.ClassifyNameSecond = origin.ClassifyNameSecond item.Title = origin.Title item.Abstract = origin.Abstract item.Author = origin.Author item.Frequency = origin.Frequency item.State = origin.State item.Stage = origin.Stage item.Content = origin.Content item.VideoUrl = origin.VideoUrl item.VideoName = origin.VideoName item.VideoPlaySeconds = origin.VideoPlaySeconds item.VideoSize = origin.VideoSize item.AdminId = origin.AdminId item.AdminRealName = origin.AdminRealName item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime) item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime) item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } type EnglishReportListResp struct { List []*EnglishReportItem Paging *paging.PagingItem `description:"分页数据"` } // EnglishReportApproveReq 英文研报审批请求体 type EnglishReportApproveReq struct { ReportId int `description:"报告ID"` Pass bool `description:"是否通过审批"` } type ElasticEnglishReportDetail struct { Id string `description:"报告id或者线上路演Id"` ReportId int `description:"报告id"` VideoId int `description:"线上路演Id"` ClassifyIdFirst int `description:"一级分类id"` ClassifyNameFirst string `description:"一级分类名称"` ClassifyIdSecond int `description:"二级分类id"` ClassifyNameSecond string `description:"二级分类名称"` StageStr string `description:"报告期数"` Title string `description:"标题"` Abstract string `description:"摘要"` Author string `description:"作者"` Frequency string `description:"频度"` PublishState int `description:"状态:1:未发布,2:已发布"` BodyContent string `description:"内容"` ContentSub string `description:"前两段内容"` CreateTime string `description:"创建时间"` PublishTime string `description:"发布时间"` ReportCode string `description:"报告唯一编码"` Overview string `description:"英文概述部分"` } type EnglishClassifyList struct { Id int `orm:"column(id);pk"` ClassifyName string `description:"分类名称"` Sort int `description:"排序"` ParentId int `description:"父级分类id"` RootId int `description:"一级分类ID"` CreateTime string `description:"创建时间"` ModifyTime string `description:"修改时间"` ClassifyLabel string `description:"分类标签"` ShowType int `json:"-" description:"展示类型:1-列表 2-专栏"` IsShow int `json:"-" description:"是否在小程序显示:1-显示 0-隐藏"` //ClassifyType int `description:"分类类型:0英文报告,1英文线上路演"` EnPermissions []int `description:"英文权限IDs"` Child []*EnglishClassifyList } type EnglishClassifyListResp struct { List []*EnglishClassifyList Paging *paging.PagingItem `description:"分页数据"` } // GetEnglishClassifyRootId 获取一级分类列表 func GetEnglishClassifyRootId(startSize, pageSize int, keyword string) (items []*EnglishClassifyList, err error) { sql := `` o := orm.NewOrmUsingDB("rddp") if keyword != "" { sql = `SELECT * FROM ( SELECT * FROM english_classify WHERE parent_id=0 AND classify_name ? UNION SELECT * FROM english_classify WHERE id IN(SELECT parent_id FROM english_classify WHERE parent_id>0 AND classify_name LIKE ?) )AS t ORDER BY sort ASC,create_time ASC LIMIT ?,? ` _, err = o.Raw(sql, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword), startSize, pageSize).QueryRows(&items) } else { sql = `SELECT * FROM english_classify WHERE parent_id=0 ORDER BY sort ASC,create_time ASC LIMIT ?,? ` _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items) } return } func GetEnglishClassifyListCount(keyword string) (count int, err error) { sqlCount := `` o := orm.NewOrmUsingDB("rddp") if keyword != "" { sqlCount = `SELECT COUNT(1) AS count FROM ( SELECT * FROM english_classify WHERE parent_id=0 AND classify_name LIKE ? UNION SELECT * FROM english_classify WHERE id IN(SELECT parent_id FROM english_classify WHERE parent_id>0 AND classify_name LIKE ?) )AS t ` err = o.Raw(sqlCount, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword)).QueryRow(&count) } else { sqlCount = `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=0` err = o.Raw(sqlCount).QueryRow(&count) } return } func GetEnglishClassifyListByRootId(rootIds []int, keyword string) (items []*EnglishClassifyList, err error) { sql := `` pars := make([]interface{}, 0) o := orm.NewOrmUsingDB("rddp") if keyword != "" { sql = `SELECT a.* FROM english_classify a LEFT JOIN english_classify b ON a.root_id = b.id LEFT JOIN english_classify c ON a.parent_id = c.id WHERE a.parent_id>0 and a.classify_name LIKE ? and a.root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `)` pars = append(pars, utils.GetLikeKeyword(keyword)) pars = append(pars, rootIds) _, err = o.Raw(sql, pars).QueryRows(&items) } else { sql = `SELECT * FROM english_classify WHERE parent_id>0 and root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `) ` _, err = o.Raw(sql, rootIds).QueryRows(&items) } return } type RSChildClassifyList []*EnglishClassifyList func (m RSChildClassifyList) Len() int { return len(m) } func (m RSChildClassifyList) Less(i, j int) bool { return m[i].Sort < m[j].Sort } func (m RSChildClassifyList) Swap(i, j int) { m[i], m[j] = m[j], m[i] } func GetEnglishClassifyChildByIds(ids []int) (items []*EnglishClassifyList, err error) { o := orm.NewOrmUsingDB("rddp") sql := `SELECT * FROM english_classify WHERE id IN (` + utils.GetOrmInReplace(len(ids)) + `) ORDER BY create_time ASC ` _, err = o.Raw(sql, ids).QueryRows(&items) return } type RSClassifyList []*EnglishClassifyList func (m RSClassifyList) Len() int { return len(m) } func (m RSClassifyList) Less(i, j int) bool { return m[i].Sort < m[j].Sort } func (m RSClassifyList) Swap(i, j int) { m[i], m[j] = m[j], m[i] }