package models import ( "github.com/beego/beego/v2/client/orm" "strconv" ) 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客观"` CategoryIdSet int `description:"分类映射id"` PolymerizationId string `description:"分类聚合ID"` CeLueFieldId string `description:"策略平台领域ID"` } type ReportMappingHome struct { CategoryId int `description:"分类ID"` SubCategoryName string `description:"主题名称"` MatchTypeName string `description:"匹配类型"` IsRed bool `description:"是否标红"` } type TradeReportMapping struct { CategoryId int `description:"分类ID"` CategoryIdSet int `description:"分类映射id"` PolymerizationId string `description:"分类聚合ID"` MatchTypeName string `description:"匹配类型"` IsRed bool `description:"是否标红"` IsFollow bool `description:"是否关注"` FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"` UpdateTime string `description:"更新时间"` Readnum int `description:"阅读数量"` ListArticle []*HomeArticle `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 1=1 ORDER BY sort ASC ` _, err = o.Raw(sql).QueryRows(&items) return } // 获取策略下面的所有分类 func GetReportMappingStrategyHomeAll(userId, ChartPermissionId int) (items []*TradeReportMapping, err error) { o := orm.NewOrm() sql := `SELECT MAX( art.publish_date ) AS update_time, (SELECT COUNT(1) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id=art.article_id) AS readnum, 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 = ? GROUP BY re.match_type_name ORDER BY sort DESC , art.publish_date DESC` _, err = o.Raw(sql, ChartPermissionId).QueryRows(&items) return } // 获取策略下面的所有分类 func GetReportMappingStrategyHomeAllByCygx(userId, chartPermissionId int) (items []*TradeReportMapping, err error) { o := orm.NewOrm() sql := `SELECT MAX( art.publish_date ) AS update_time, (SELECT COUNT(1) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id=art.article_id) AS readnum, re.id AS category_id, re.match_type_name FROM cygx_report_mapping_cygx AS re INNER JOIN cygx_report_mapping_group AS mg ON mg.id_cygx = re.id INNER JOIN cygx_article AS art ON art.category_id = mg.category_id_celue WHERE 1 = 1 AND re.chart_permission_id = ? AND re.report_type = 1 AND re.list_group > 0 GROUP BY re.match_type_name ORDER BY sort DESC, art.publish_date DESC` _, err = o.Raw(sql, chartPermissionId).QueryRows(&items) return } // 行业列表 func GetTradeAll(ChartPermissionId int) (items []*TradeReportMapping, err error) { o := orm.NewOrm() sql := `SELECT re.category_id, re.category_id_set, re.polymerization_id, re.sub_category_name, re.match_type_name FROM cygx_report_mapping AS re WHERE re.chart_permission_id = ? AND re.report_type = 1 AND re.category_id NOT IN ( 67 ) ORDER BY re.sort 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"` FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"` List []*IndustrialToArticleCategoryRep ListSubject []*IndustrialSubject IndustryVideo *MicroVideoSimpleInfo AuthInfo *UserPermissionAuthInfo } // 通过分类ID获取详情 func GetdetailByCategoryId(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 } // 通过分类ID获取详情 func GetdetailByCategoryIdPush(categoryId int) (item *ReportMapping, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_report_mapping WHERE 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, reportType int) (item *ReportMapping, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? AND report_type = ? LIMIT 1` err = o.Raw(sql, categoryId, reportType).QueryRow(&item) return } // 通过分类ID获取详情 func GetdetailByCategoryIdSet(categoryId int) (ids string, err error) { o := orm.NewOrm() sql := `SELECT GROUP_CONCAT( DISTINCT category_id SEPARATOR ',' ) AS ids FROM cygx_report_mapping WHERE category_id_set = ? ` err = o.Raw(sql, categoryId).QueryRow(&ids) 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 GetTradeArticleAndProductInterior(ChartPermissionId int) (items []*TradeReportMapping, err error) { o := orm.NewOrm() sql := `SELECT map.sort, map.match_type_name, map.id AS category_id FROM cygx_report_mapping_cygx AS map INNER JOIN cygx_report_mapping_group AS g ON g.id_cygx = map.id INNER JOIN cygx_report_mapping_celue AS cl ON cl.category_id = g.category_id_celue INNER JOIN cygx_article AS art ON art.category_id = cl.category_id WHERE 1 = 1 AND map.report_type = 1 AND map.is_report = 1 AND art.is_report = 1 AND art.publish_status = 1 AND map.chart_permission_id = ? GROUP BY match_type_name UNION ALL SELECT map.sort, map.match_type_name, map.id AS category_id FROM cygx_report_mapping_cygx AS map INNER JOIN cygx_industrial_management AS im ON im.chart_permission_id = map.chart_permission_id INNER JOIN cygx_product_interior AS art ON art.match_type_id = map.id WHERE 1 = 1 AND art.STATUS = 1 AND art.visible_range = 1 AND map.report_type = 1 AND map.chart_permission_id = ? GROUP BY match_type_name ORDER BY sort DESC ` _, err = o.Raw(sql, ChartPermissionId, ChartPermissionId).QueryRows(&items) return }