1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package models
- import (
- "rdluck_tools/orm"
- "strconv"
- //"rdluck_tools/paging"
- )
- type IndustrialManagementList struct {
- List []*IndustrialManagement
- }
- type IndustrialManagement struct {
- IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
- IndustryName string `description:"产业名称"`
- RecommendedIndex int `description:"推荐指数"`
- CategoryId int `description:"文章分类ID"`
- LayoutTime string `description:"布局时间"`
- UpdateTime string `description:"更新时间"`
- IsRed bool `description:"是否标记红点"`
- IsTop bool `description:"是否置顶"`
- AnalystList []*IndustrialAnalyst `description:"分析师列表"`
- Analyst string `description:"分析师"`
- IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
- }
- type IndustrialAnalyst struct {
- AnalystName string `description:"分析师名称"`
- IndustrialManagementId int `description:"产业id"`
- }
- type IndustrialSubject struct {
- IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"`
- IndustrialManagementId int `description:"产业id"`
- SubjectName string `description:"标的名称"`
- }
- //获取产业报告数量
- func GetReportIndustrialCount(categoryId, industrialManagementId int) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) count
- FROM
- cygx_article AS a
- INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
- WHERE
- a.publish_status = 1
- AND category_id = ?
- AND man_g.industrial_management_id = ?`
- err = o.Raw(sql, categoryId, industrialManagementId).QueryRow(&count)
- return
- }
- //获取产业报告列表
- func GetReportIndustrialList(pars []interface{}, categoryId, industrialManagementId, userId, startSize, pageSize int) (items []*ReportArticle, err error) {
- o := orm.NewOrm()
- sql := `SELECT *,( SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id = a.article_id ) AS readnum
- FROM
- cygx_article AS a
- INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
- WHERE
- a.publish_status = 1
- AND category_id = ?
- AND man_g.industrial_management_id = ?`
- sql += ` ORDER BY publish_date DESC LIMIT ?,? `
- _, err = o.Raw(sql, pars, categoryId, industrialManagementId, startSize, pageSize).QueryRows(&items)
- return
- }
- //产业下所关联的文章分类列表
- func IndustrialToArticleCategory(industrialManagementId int) (items []*IndustrialToArticleCategoryRep, err error) {
- o := orm.NewOrm()
- sql := `SELECT map.match_type_name,map.category_id
- FROM cygx_report_mapping AS map
- INNER JOIN cygx_article AS art ON art.category_id = map.category_id
- INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
- WHERE map.report_type = 2
- AND man_g.industrial_management_id =?
- GROUP BY map.match_type_name`
- _, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
- return
- }
- //判断用户是否阅读该产业下,某一分类的文章
- func IndustrialUserRecordArticleCount(userId, industrialManagementId, categoryId int) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- COUNT(1) count
- FROM
- cygx_article_history_record
- WHERE
- article_id = ( SELECT article_id FROM cygx_article WHERE article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id = ? ) AND category_id = ? ORDER BY publish_date DESC LIMIT 0, 1 )
- AND user_id = ? `
- err = o.Raw(sql, industrialManagementId, categoryId, userId).QueryRow(&count)
- return
- }
|