123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- )
- type ReportMapping struct {
- CategoryId int `description:"分类ID"`
- SubCategoryName string `description:"主题"`
- MatchTypeName string `description:"分类名称"`
- ChartPermissionName string `description:"行业名称"`
- ChartPermissionId int `description:"行业ID"`
- IsRed bool `description:"是否标红"`
- PermissionType int `description:"1主观,2客观"`
- }
- type ReportMappingHome struct {
- CategoryId int `description:"分类ID"`
- SubCategoryName string `description:"主题名称"`
- MatchTypeName string `description:"匹配类型"`
- IsRed bool `description:"是否标红"`
- }
- type TradeReportMapping struct {
- CategoryId int `description:"分类ID"`
- SubCategoryName string `description:"主题名称"`
- MatchTypeName string `description:"匹配类型"`
- IsRed bool `description:"是否标红"`
- UpdateTime string `description:"更新时间"`
- Readnum int `description:"阅读数量"`
- }
- type ReportMappingResp struct {
- List []*ReportMapping
- }
- type ReportMappingHomeResp struct {
- List []*ReportMappingHome
- }
- type TradeReportMappingResp struct {
- List []*TradeReportMapping
- }
- //获取策略下面的所有分类
- func GetReportMappingStrategyAll() (items []*ReportMapping, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND chart_permission_id=23 ORDER BY sort ASC `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- //获取策略下面的所有分类
- func GetReportMappingStrategyHomeAll() (items []*ReportMappingHome, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- re.category_id,re.sub_category_name,re.match_type_name
- FROM
- cygx_report_mapping AS re
- INNER JOIN cygx_article AS art ON art.category_id = re.category_id
- WHERE
- re.report_type = 1
- AND re.chart_permission_id = 23
- GROUP BY
- re.match_type_name
- ORDER BY
- sort DESC , art.publish_date DESC`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- //行业列表
- func GetTradeAll(ChartPermissionId int) (items []*TradeReportMapping, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- MAX( art.publish_date ) AS update_time,
- re.category_id,
- re.sub_category_name,
- re.match_type_name
- FROM
- cygx_report_mapping AS re
- INNER JOIN cygx_article AS art ON re.category_id = art.category_id
- WHERE
- re.chart_permission_id =?
- AND re.report_type = 1
- AND art.is_class = 1
- AND re.category_id NOT IN (67)
- GROUP BY
- art.category_id
- ORDER BY
- update_time DESC`
- _, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
- return
- }
- type IndustrialToArticleCategoryRep struct {
- CategoryId int `description:"分类ID"`
- MatchTypeName string `description:"匹配类型"`
- IsRed bool `description:"是否标红"`
- }
- type IndustrialToArticleCategoryListRep struct {
- LayoutTime string `description:"布局时间"`
- IndustryName string `description:"产业名称"`
- IndustrialManagementId int `description:"产业D"`
- List []*IndustrialToArticleCategoryRep
- }
- //通过分类ID获取详情
- func GetdetailByCategoryId(categoryId int) (item *ReportMapping, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND category_id=? `
- err = o.Raw(sql, categoryId).QueryRow(&item)
- return
- }
- //通过分类ID获取详情主观客观
- func GetdetailByCategoryIdSando(categoryId int) (item *ReportMapping, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM cygx_report_mapping WHERE permission_type>0 AND category_id=? LIMIT 1`
- err = o.Raw(sql, categoryId).QueryRow(&item)
- return
- }
- //通过分类ID获取详情
- func GetdetailByCategoryIdOne(categoryId int) (item *ReportMapping, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? LIMIT 1`
- err = o.Raw(sql, categoryId).QueryRow(&item)
- return
- }
- //判断该分类下最新的文章用户是否阅读
- func CheckThisCategoryNewArticleIsRead(uid, categoryId int) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) count
- FROM cygx_article_history_record
- WHERE user_id = ?
- AND article_id = ( SELECT article_id FROM cygx_article WHERE category_id = ? AND is_class = 1 AND is_report = 1 AND is_filter = 0 ORDER BY publish_date DESC LIMIT 1)`
- err = o.Raw(sql, uid, categoryId).QueryRow(&count)
- return
- }
- //获取策略下面的所有分类
- func GetMatchTypeNamenNotNull() (items []*ReportMapping, err error) {
- o := orm.NewOrm()
- sql := `SELECT category_id,match_type_name FROM cygx_report_mapping WHERE match_type_name <> ''`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- type ReportMappingStatistical struct {
- CategoryId int `description:"分类ID"`
- SubCategoryName string `description:"主题名称"`
- MatchTypeName string `description:"匹配类型"`
- IsSummary string `description:"是否属于纪要,1 是,0否"`
- IsClass string `description:"是否归类,1 是,0否"`
- Pv int `description:"Pv"`
- Uv int `description:"Uv"`
- }
- //获取报表
- func GetStatisticalReportArtilce(chartPermissionId int) (items []*ReportMappingStatistical, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- m.category_id,
- m.chart_permission_name,
- a.article_id,
- a.title,
- a.is_summary,
- a.is_class,
- (SELECT count( 1 ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS pv,
- (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS uv
- FROM
- cygx_report_mapping AS m
- INNER JOIN cygx_article AS a ON a.category_id = m.category_id
- WHERE
- m.chart_permission_id = ?
- and a.is_class= 1
- and a.is_report= 1
- and m.id !=28
- and a.is_filter= 0
- GROUP BY a.article_id`
- _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
- return
- }
- //获取报表
- func GetStatisticalReportArtilceExpert() (items []*ReportMappingStatistical, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- a.article_id,
- a.title,
- a.is_summary,
- a.is_class,
- (SELECT count( 1 ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS pv,
- (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS uv
- FROM
- cygx_article AS a
- WHERE
- a.category_name LIKE '%研选%'`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
|