package models import ( "github.com/beego/beego/v2/client/orm" "hongze/hongze_clpt/utils" "time" ) type IndustrialManagementRep struct { IndustryName string `description:"产业名称"` IndustrialManagementId int `description:"产业id"` ChartPermissionId int `description:"权限id"` RecommendedIndex int `description:"推荐指数"` LayoutTime string `description:"布局时间"` ArticleReadNum int `description:"文章阅读数量"` IsResearch bool `description:"是否属于研选"` IsJump bool `description:"是否跳转"` IndustryNewLabel bool `description:"是否产业新标签"` } type IndustrialManagementCount struct { IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"` } type IndustrialManagementIdInt struct { IndustrialManagementId int `description:"产业Id"` IndustryName string `description:"产业名称"` SubjectName string `description:"标的名称"` ArticleId int `description:"文章ID"` IsResearch bool `description:"是否属于研选"` ChartPermissionId int `description:"权限id"` } type IndustrialManagementIdInts struct { IndustrialManagementId int `description:"产业Id"` IndustryName string `description:"产业名称"` SubjectNames string `description:"标的名称"` ArticleId int `description:"文章ID"` IndustrialAndSubjectIds string `description:"关联标的以及产业ID"` } type IndustrialManagementIdName struct { DepartmentId int `description:"作者ID"` ArticleId int `description:"文章id"` IndustryName string `description:"产业名称"` SubjectName string `description:"标的名称"` IsReport string `description:"1观点,0纪要"` } type IndustrialSubject struct { IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"` IndustrialManagementId int `description:"产业id"` SubjectName string `description:"标的名称"` IndustryName string `description:"产业名称"` } type IndustrialSubjectResp struct { IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"` SubjectName string `description:"标的名称"` } type IndustrialManagementArticle struct { IndustrialManagementId int `description:"产业Id"` IndustryName string `description:"产业名称"` ArticleId int `description:"文章ID"` PublishDate string `description:"发布时间"` } type IndustrialManagementResp struct { IndustrialManagementId int `description:"产业Id"` IndustryName string `description:"产业名称"` ChartPermissionId int `description:"权限id"` } // IndustryArtCount 产业文章数 type IndustryArtCount struct { ArtNum int `json:"art_num" description:"文章数"` IndustrialManagementId int `json:"industrial_management_id" description:"产业ID"` } type IndustryVideoDetailResp struct { IndustryVideo *MicroVideoSimpleInfo AuthInfo *UserPermissionAuthInfo } // 产业列表 func GetIndustrialManagementAllCount(condition string) (count int, err error) { o := orm.NewOrm() sql := `SELECT COUNT(*) as count FROM (SELECT COUNT(*) FROM cygx_industrial_management AS man INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id WHERE 1 = 1 AND re.report_type = 2 AND art.is_report = 1 AND art.is_class = 1 ` + condition + ` GROUP BY man.industrial_management_id) AS num ` err = o.Raw(sql).QueryRow(&count) return } // 获取产业下阅读数量第三的产业详情 func GetIndustrialManagementHot3(chartPermissionId int) (item *IndustrialManagementRep, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_industrial_management WHERE chart_permission_id = ? ORDER BY article_read_num DESC LIMIT 2,1` err = o.Raw(sql, chartPermissionId).QueryRow(&item) return } // 产业列表 func GetIndustrialManagementAll(uid int, condition, orderSrt string, startSize, pageSize int, isBillboard bool) (items []*IndustrialManagement, err error) { o := orm.NewOrm() var conditionBillboard string if isBillboard { var startTime string startTime = time.Now().AddDate(0, 0, -30).Format(utils.FormatDate) conditionBillboard = ` ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS f WHERE f.industrial_management_id = man.industrial_management_id AND f.follow_type = 1 AND f.create_time > '` + startTime + `' ) AS follow_num, ` } sql := `SELECT man.*, re.chart_permission_name, man.new_art_publish_date AS update_time , MIN(art.publish_date) AS min_report_time,` + conditionBillboard + ` IFNULL( f.follow_type_order, 0 ) AS follow_type_order FROM cygx_industrial_management AS man INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id LEFT JOIN cygx_industry_fllow AS f ON f.industrial_management_id = man.industrial_management_id AND f.user_id = ? WHERE 1= 1 AND re.report_type = 2 AND art.is_report = 1 AND art.is_class = 1 ` + condition + ` GROUP BY man.industry_name ORDER BY follow_type_order DESC , ` + orderSrt + ` LIMIT ?,?` _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items) return } // 标的列表 func GetIndustrialSubjectAll(IndustrialManagementId int) (items []*IndustrialSubject, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_industrial_subject WHERE industrial_management_id = ? ` _, err = o.Raw(sql, IndustrialManagementId).QueryRows(&items) return } // 获取该产业下最新的文章详情 func GetIndustrialNewArticleDetail(industrialManagementId int) (item *ArticleDetail, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_article WHERE article_id IN ( SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id = ? ) ORDER BY is_report DESC, publish_date DESC LIMIT 0,1` err = o.Raw(sql, industrialManagementId).QueryRow(&item) return } // 获取该产业下最新的文章详情 func GetNewArticleDetailByIndustrialIds(pars []interface{}, condition string) (items []*IndustrialManagementArticle, err error) { //arrLen := len(industrialIdArr) //if arrLen == 0 { // return //} o := orm.NewOrm() sql := `SELECT mg.industrial_management_id, MAX( a.article_id ) AS article_id, a.title, MAX( a.publish_date ) AS publish_date FROM cygx_industrial_article_group_management AS mg INNER JOIN cygx_article AS a ON mg.article_id = a.article_id WHERE 1 = 1 ` + condition + ` GROUP BY mg.industrial_management_id ` _, err = o.Raw(sql, pars).QueryRows(&items) return } // 获取产业数量 func GetIndustrialManagementCount(IndustrialManagementId int) (count int, err error) { sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industrial_management WHERE industrial_management_id=? ` o := orm.NewOrm() err = o.Raw(sqlCount, IndustrialManagementId).QueryRow(&count) return } // 获取关注数量 func GetCountCygxIndustryFllow(industrialManagementId, userId int, condition string) (count int, err error) { sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? ` + condition err = orm.NewOrm().Raw(sql, userId, industrialManagementId).QueryRow(&count) return } func GetIndustrialManagementDetail(industrialManagementId int) (items *IndustrialManagementRep, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_industrial_management WHERE industrial_management_id = ?` err = o.Raw(sql, industrialManagementId).QueryRow(&items) return } // 获取所有的产业 func GetindustrialManagement() (items []*IndustrialManagementRep, err error) { o := orm.NewOrm() sql := `SELECT i.* FROM cygx_industrial_management AS i INNER JOIN cygx_industrial_article_group_management AS m ON m.industrial_management_id = i.industrial_management_id GROUP BY i.industrial_management_id ` _, err = o.Raw(sql).QueryRows(&items) return } // 标的列表 func GetIndustrialSubjectAllByIndustrialId(pars []interface{}, condition string) (items []*IndustrialSubject, err error) { o := orm.NewOrm() sql := `SELECT m.subject_name, m.industrial_management_id, m.industrial_subject_id FROM cygx_article AS a INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id WHERE 1 = 1 AND a.publish_status = 1 ` + condition + ` GROUP BY m.industrial_subject_id ORDER BY a.publish_date DESC ` _, err = o.Raw(sql, pars).QueryRows(&items) return } // 获取标的列表 func GetIndustrialListByarticleId(pars []interface{}, condition string) (items []*IndustrialManagementIdInt, err error) { o := orm.NewOrm() sql := `SELECT mg.article_id, m.industry_name, m.chart_permission_id, mg.industrial_management_id FROM cygx_industrial_management AS m INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id WHERE 1 = 1 ` + condition + ` GROUP BY mg.article_id, mg.industrial_management_id ` _, err = o.Raw(sql, pars).QueryRows(&items) return } // GetIndustryArtCountByCondition 获取产业文章关联的文章数 func GetIndustryArtCountByCondition(condition string, pars []interface{}) (list []*IndustryArtCount, err error) { sql := `SELECT COUNT(1) AS art_num, agm.industrial_management_id FROM cygx_industrial_article_group_management AS agm JOIN cygx_industrial_management AS man ON man.industrial_management_id = agm.industrial_management_id WHERE 1 = 1 ` if condition != "" { sql += condition } sql += ` GROUP BY agm.industrial_management_id` _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list) return } type IndustrialArticleGroupManagementResp struct { IndustrialManagementId int `description:"产业Id"` ArticleId int `description:"文章ID"` } // GetIndustrialArticleGroupManagementByIndustrialManagementId 获取产业文章关联的文章ID func GetIndustrialArticleGroupManagementByIndustrialManagementId(industrialManagementId int) (list []*IndustrialArticleGroupManagementResp, err error) { sql := `SELECT * FROM cygx_industrial_article_group_management WHERE industrial_management_id = ? ` _, err = orm.NewOrm().Raw(sql, industrialManagementId).QueryRows(&list) return } // GetTopOneMonthArtReadNumIndustry 获取近一个月报告阅读数量最多的产业信息 func GetTopOneMonthArtReadNumIndustry(condition string, pars []interface{}) (item *IndustrialManagement, err error) { sql := `SELECT * FROM cygx_industrial_management WHERE 1 = 1 ` if condition != `` { sql += condition } sql += ` ORDER BY article_read_num DESC LIMIT 1` err = orm.NewOrm().Raw(sql, pars).QueryRow(&item) return } // GetTopOneMonthArtReadNumIndustry 获取近一个月报告阅读数量最多的产业信息 根据行业分组 func GetTopOneMonthArtReadNumIndustryAll(condition string, pars []interface{}) (items []*IndustrialManagement, err error) { sql := `SELECT * FROM cygx_industrial_management WHERE 1 = 1 ` if condition != `` { sql += condition } sql += ` ORDER BY article_read_num DESC ` _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&items) return } //// GetTopIndustryFollowData 获取关注度最高的产业关注数据 //func GetTopIndustryFollowData(startSize, pageSize int, condition string, pars []interface{}) (list []*IndustrialManagement, err error) { // sql := `SELECT // COUNT(1) AS one_month_follow_num, // man.* // FROM // cygx_industry_fllow AS idf // JOIN cygx_industrial_management AS man ON idf.industrial_management_id = man.industrial_management_id // WHERE 1 = 1 ` // if condition != "" { // sql += condition // } // sql += ` GROUP BY // idf.industrial_management_id // ORDER BY // one_month_follow_num DESC // LIMIT ?,?` // _, err = orm.NewOrm().Raw(sql, pars, startSize, pageSize).QueryRows(&list) // return //} // GetTopIndustryFollowData 获取关注度最高的产业关注数据 func GetTopIndustryFollowData(uid, startSize, pageSize int, condition string, pars []interface{}) (list []*IndustrialManagement, err error) { sql := `SELECT man.*, IFNULL( f.follow_type_order, 0 ) AS follow_type_order FROM cygx_industrial_management AS man LEFT JOIN cygx_industry_fllow AS f ON f.industrial_management_id = man.industrial_management_id AND f.user_id = ? WHERE 1 = 1 ` if condition != "" { sql += condition } sql += ` GROUP BY man.industrial_management_id ORDER BY follow_type_order DESC , man.one_month_follow_num DESC , man.industrial_management_id DESC LIMIT ?,?` _, err = orm.NewOrm().Raw(sql, uid, pars, startSize, pageSize).QueryRows(&list) return } // GetActiveArticleIndustryIds 获取有已归类行业报告的行业IDs func GetActiveArticleIndustryIds() (ids []int, err error) { sql := `SELECT man.industrial_management_id FROM cygx_industrial_management AS man JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id JOIN cygx_article AS art ON art.article_id = man_g.article_id WHERE 1 = 1 AND re.report_type = 2 AND art.is_report = 1 AND art.is_class = 1 AND art.publish_status = 1 GROUP BY man.industrial_management_id` _, err = orm.NewOrm().Raw(sql).QueryRows(&ids) return } // GetIndustryByName 通过名称获取产业 func GetIndustryByName(industryName string) (item *IndustrialManagement, err error) { sql := `SELECT * FROM cygx_industrial_management WHERE industry_name = ? LIMIT 1` err = orm.NewOrm().Raw(sql, industryName).QueryRow(&item) return } // GetSourceIndustryByName 通过名称获取资源包产业 func GetSourceIndustryByName(industryName string) (item *IndustrialManagement, err error) { sql := `SELECT m.industry_name, m.industrial_management_id, m.chart_permission_id FROM cygx_industrial_management AS m INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh' WHERE 1 = 1 AND m.industry_name = ? AND a.publish_status = 1 AND a.article_id < 1000000 GROUP BY m.industrial_management_id` err = orm.NewOrm().Raw(sql, industryName).QueryRow(&item) return } // 近期更新主题列表 func GetIndustrialManagementNewList(condition string) (items []*IndustrialManagementNewResp, err error) { o := orm.NewOrm() sql := `SELECT m.industrial_management_id, m.industry_name, m.article_read_num, MAX( a.publish_date ) AS publish_date FROM cygx_article AS a INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id WHERE 1 = 1 AND a.article_type_id > 0 AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date DESC LIMIT 12` _, err = o.Raw(sql).QueryRows(&items) return } // 获取该产业下最新的产品内测详情 func GetNewProductInteriorByIndustrialIds(industrialIdArr []int) (items []*IndustrialManagementArticle, err error) { arrLen := len(industrialIdArr) if arrLen == 0 { return } o := orm.NewOrm() sql := `SELECT mg.industrial_management_id, MAX( a.product_interior_id ) AS article_id, a.title, MAX( a.publish_time ) AS publish_date FROM cygx_product_interior_industrial_group_management AS mg INNER JOIN cygx_product_interior AS a ON mg.product_interior_id = a.product_interior_id WHERE 1 = 1 AND a.STATUS = 1 AND a.visible_range = 1 AND mg.industrial_management_id IN(` + utils.GetOrmInReplace(len(industrialIdArr)) + `) GROUP BY mg.industrial_management_id` _, err = o.Raw(sql, industrialIdArr).QueryRows(&items) return }