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 }