123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- package models
- import (
- "eta/eta_mini_bridge/utils"
- "fmt"
- "time"
- "github.com/beego/beego/v2/client/orm"
- )
- type ReportList struct {
- Id int `description:"报告Id"`
- AddType int `description:"新增方式:1:新增报告,2:继承报告"`
- ClassifyIdFirst int `description:"一级分类id"`
- ClassifyNameFirst string `description:"一级分类名称"`
- ClassifyIdSecond int `description:"二级分类id"`
- ClassifyNameSecond string `description:"二级分类名称"`
- ClassifyIdThird int `description:"三级分类id"`
- ClassifyNameThird string `description:"三级分类名称"`
- PermissionNames []string `description:"二级分类名称"`
- Title string `description:"标题"`
- Abstract string `description:"摘要"`
- Author string `description:"作者"`
- Frequency string `description:"频度"`
- CreateTime string `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- State int `description:"1:未发布,2:已发布"`
- PublishTime string `description:"发布时间"`
- Stage int `description:"期数"`
- MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
- Content string `description:"内容"`
- VideoUrl string `description:"音频文件URL"`
- VideoName string `description:"音频文件名称"`
- VideoPlaySeconds string `description:"音频播放时长"`
- VideoSize string `description:"音频文件大小,单位M"`
- HasPermission int `description:"是否拥有报告权限,1:拥有,0:没有"`
- TitleType string `description:"标题类型,FICC或者权益"`
- IsCurrentDate int `description:"是否当前日期:1是,0不是"`
- ClassifyDetail
- }
- 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报告"`
- PublishTime time.Time `description:"报告发布时间"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- PushTime 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:"报告作者"`
- Stage int `description:"期数"`
- State int `description:"报告状态:0-未推送,1-已推送"`
- PushTime string `description:"推送时间"`
- PublishTime string `description:"报告发布时间"`
- ReportType int `description:"报告类型:1-eta报告"`
- CreateTime string `description:"创建时间"`
- ModifyTime string `description:"修改时间"`
- }
- // GetReportDailyListCount 获得今日报告数量
- func GetReportDailyListCount() (count int, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := ` SELECT COUNT(*) AS count FROM report WHERE 1=1 AND (state=2 OR state=6) AND DATE(publish_time)=DATE(NOW()) `
- err = o.Raw(sql).QueryRow(&count)
- return
- }
- // func GetReportDailyList(startSize, pageSize int) (items []*ReportList, err error) {
- // o := orm.NewOrmUsingDB("rddp")
- // sql := ` SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,
- // a.create_time,a.modify_time,a.state,a.publish_time,a.stage,a.msg_is_send,b.id AS classify_id,b.classify_name,b.descript,b.report_author,b.author_descript,
- // b.report_img_url,b.head_img_url,b.avatar_img_url,b.column_img_url,a.video_url,a.video_name,a.video_play_seconds,a.video_size,
- // CASE WHEN DATE(a.publish_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
- // FROM report AS a
- // INNER JOIN classify AS b ON a.classify_id_second=b.id
- // WHERE (a.state=2 OR a.state=6) AND DATE(a.publish_time)=DATE(NOW())
- // ORDER BY a.publish_time DESC LIMIT ?,? `
- // _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- // return
- // }
- func GetReportDailyList(startSize, pageSize int) (items []*ReportList, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := ` SELECT * FROM report WHERE (state=2 OR state=6) AND DATE(publish_time)=DATE(NOW()) ORDER BY publish_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- // GetReportRecentListCount 获得报告数量
- func GetReportRecentListCount() (count int, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := ` SELECT COUNT(*) AS count FROM report
- WHERE 1=1 AND (state=2 OR state=6) AND classify_id_second IN (
- SELECT DISTINCT classify_id
- FROM chart_permission_search_key_word_mapping
- )`
- err = o.Raw(sql).QueryRow(&count)
- return
- }
- func GetReportRecentList(startSize, pageSize int) (items []*ReportList, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := ` SELECT * FROM report WHERE (state=2 OR state=6) ORDER BY publish_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string) (count int, err error) {
- if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT COUNT(*) AS count FROM report AS a WHERE (a.state=2 OR a.state=6) AND (1=2 `
- if len(classifyFirstIds) > 0 {
- sql += fmt.Sprintf(" OR a.classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
- }
- if len(classifySecondIds) > 0 {
- sql += fmt.Sprintf(" OR a.classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
- }
- if len(classifyThirdIds) > 0 {
- sql += fmt.Sprintf(" OR a.classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
- }
- sql += ` ) `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, classifyFirstIds, classifySecondIds, classifyThirdIds).QueryRow(&count)
- return
- }
- func GetPushReportCountByClassifyIds(reportType int, classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string) (count int, err error) {
- if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
- return
- }
- o := orm.NewOrm()
- sql := `SELECT COUNT(*) AS count FROM report_push_status WHERE state=1 AND report_type=? AND (1=2 `
- if len(classifyFirstIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
- }
- if len(classifySecondIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
- }
- if len(classifyThirdIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
- }
- sql += ` ) `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, reportType, classifyFirstIds, classifySecondIds, classifyThirdIds).QueryRow(&count)
- return
- }
- func GetPushReportListByClassifyIds(reportType int, classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string, startSize, pageSize int) (items []*ReportPushView, err error) {
- if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
- return
- }
- o := orm.NewOrm()
- sql := `SELECT * FROM report_push_status WHERE state=1 AND report_type=? AND (1=2 `
- // AND (a.classify_id_first IN (%s) OR a.classify_id_second IN (%s) OR a.classify_id_third IN (%s)) `
- if len(classifyFirstIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
- }
- if len(classifySecondIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
- }
- if len(classifyThirdIds) > 0 {
- sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
- }
- sql += `) `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY publish_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, reportType, classifyFirstIds, classifySecondIds, classifyThirdIds, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetPushReportCount(reportType int, classifyIds []int, dateCondition string) (count int, err error) {
- o := orm.NewOrm()
- sql := ` SELECT COUNT(*) AS count FROM report_push_status WHERE state=1 AND report_type=? `
- var pars []interface{}
- if len(classifyIds) > 0 {
- sql += ` AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s)) `
- sql = fmt.Sprintf(sql, utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)))
- pars = append(pars, classifyIds, classifyIds, classifyIds)
- }
- if dateCondition != "" {
- sql += dateCondition
- }
- tmpPars := []interface{}{reportType}
- tmpPars = append(tmpPars, pars...)
- err = o.Raw(sql, tmpPars).QueryRow(&count)
- return
- }
- func GetPushReportListByPage(reportType int, classifyIds []int, dateCondition string, startSize, pageSize int) (items []*ReportPushView, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM report_push_status WHERE state=1 AND report_type=? `
- var pars []interface{}
- if len(classifyIds) > 0 {
- sql += ` AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s)) `
- sql = fmt.Sprintf(sql, utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)))
- pars = append(pars, classifyIds, classifyIds, classifyIds)
- }
- if dateCondition != "" {
- sql += dateCondition
- }
- sql += ` ORDER BY publish_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, reportType, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetReportByClassifyIds(classifyIds []int, condition string) (count int, err error) {
- if len(classifyIds) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT COUNT(*) AS count FROM report AS a
- WHERE (a.state=2 OR a.state=6) AND a.classify_id_second IN (%s) `
- sql = fmt.Sprintf(sql, utils.GetOrmReplaceHolder(len(classifyIds)))
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, classifyIds).QueryRow(&count)
- return
- }
- func GetReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string, startSize, pageSize int) (items []*ReportList, err error) {
- if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,
- a.create_time,a.modify_time,a.state,a.publish_time,a.stage,a.msg_is_send,b.id AS classify_id,b.classify_name,b.descript,b.report_author,b.author_descript,
- b.report_img_url,b.head_img_url,b.avatar_img_url,b.column_img_url,a.video_url,a.video_name,a.video_play_seconds,a.video_size,
- CASE WHEN DATE(a.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
- FROM report AS a
- INNER JOIN classify AS b ON a.classify_id_second=b.id
- WHERE (a.state=2 OR a.state=6) AND (1=2 `
- // AND (a.classify_id_first IN (%s) OR a.classify_id_second IN (%s) OR a.classify_id_third IN (%s)) `
- if len(classifyFirstIds) > 0 {
- sql += fmt.Sprintf(" OR a.classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
- }
- if len(classifySecondIds) > 0 {
- sql += fmt.Sprintf(" OR a.classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
- }
- if len(classifyThirdIds) > 0 {
- sql += fmt.Sprintf(" OR a.classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
- }
- sql += `) `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY a.publish_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, classifyFirstIds, classifySecondIds, classifyThirdIds, startSize, pageSize).QueryRows(&items)
- return
- }
- type ReportDetail struct {
- Id int `description:"报告Id"`
- AddType int `description:"新增方式:1:新增报告,2:继承报告"`
- ClassifyIdFirst int `description:"一级分类id"`
- ClassifyNameFirst string `description:"一级分类名称"`
- ClassifyIdSecond int `description:"二级分类id"`
- ClassifyNameSecond string `description:"二级分类名称"`
- ClassifyIdThird int `description:"三级分类id"`
- ClassifyNameThird string `description:"三级分类名称"`
- Title string `description:"标题"`
- Abstract string `description:"摘要"`
- Author string `description:"作者"`
- Frequency string `description:"频度"`
- CreateTime string `description:"创建时间"`
- ModifyTime string `description:"修改时间"`
- State int `description:"1:未发布,2:已发布"`
- PublishTime string `description:"发布时间"`
- Stage int `description:"期数"`
- MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
- Content string `description:"内容"`
- ChapterContent []*ReportChapter `description:"章节内容"`
- VideoUrl string `description:"音频文件URL"`
- VideoName string `description:"音频文件名称"`
- VideoPlaySeconds string `description:"音频播放时长"`
- VideoSize string `description:"音频文件大小,单位M"`
- ContentSub string `description:"内容前两个章节"`
- IsShowNewLabel int `description:"是否显示新标签"`
- IsCurrentDate int `description:"是否当前日期"`
- ClassifyName string `description:"分类名称"`
- TitleType string `description:"标题类型,FICC或者权益"`
- IsPublic bool `description:"是否是公共报告 "`
- HeadResourceId int `description:"版头资源库id"`
- EndResourceId int `description:"版尾资源库id"`
- HeadResource *SmartReportResource `description:"版头资源库"`
- EndResource *SmartReportResource `description:"版尾资源库"`
- CollaborateType int `description:"合作类型, 1:个人,2:多人协作"`
- ReportLayout int `description:"报告布局, 1:常规布局,2:智能布局"`
- HasChapter int `description:"是否有章节: 0-否 1-是"`
- }
- type ReportChapter struct {
- Title string `description:"章节标题"`
- Content string `description:"章节内容"`
- }
- func GetReportChapterList(reportId int) (items []*ReportChapter, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM report_chapter WHERE report_id=? ORDER BY sort ASC`
- _, err = o.Raw(sql, reportId).QueryRows(&items)
- return
- }
- func GetReportById(reportId int) (item *ReportDetail, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM report WHERE (state=2 OR state=6) AND id=?`
- err = o.Raw(sql, reportId).QueryRow(&item)
- return
- }
- type ReportCollectListItem struct {
- ReportId int `description:"报告Id"`
- ReportChapterId int `description:"报告章节Id"`
- ClassifyIdFirst int `description:"一级分类id"`
- ClassifyNameFirst string `description:"一级分类名称" `
- ClassifyIdSecond int `description:"二级分类id"`
- ClassifyNameSecond string `description:"二级分类名称"`
- ReportChapterTypeId int `description:"报告章节类型id"`
- PublishTime time.Time `description:"发布时间"`
- Title string `description:"标题"`
- ContentSub string `description:"内容前两个章节"`
- Abstract string `description:"摘要"`
- Stage string `description:"期数"`
- Author string `description:"作者"`
- PdfUrl string `description:"pdf文件url"`
- ReportType int `description:"报告类型:1:eta报告,2:小程序pdf报告"`
- }
- type SmartReportResource struct {
- ResourceId int `description:"资源库id"`
- ImgUrl string `description:"图片url"`
- Type int `description:"资源类型:1-版头 2-版尾"`
- Style string `description:"版图样式"`
- }
- func GetSmartReportResourceById(resourceId int) (item *SmartReportResource, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM smart_report_resource WHERE resource_id=?`
- err = o.Raw(sql, resourceId).QueryRow(&item)
- return
- }
|