123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_web_mfyx/utils"
- "strconv"
- "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.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 + `
- (SELECT COUNT( 1 ) FROM cygx_industry_fllow AS f WHERE f.user_id = ` + strconv.Itoa(uid) + ` AND f.industrial_management_id = man.industrial_management_id AND f.type = 1) AS is_follow
- 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.industry_name
- ORDER BY ` + orderSrt + ` LIMIT ?,?`
- _, err = o.Raw(sql, 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(startSize, pageSize int, condition string, pars []interface{}) (list []*IndustrialManagement, err error) {
- sql := `SELECT
- man.*
- FROM cygx_industrial_management AS man
- WHERE 1 = 1 `
- if condition != "" {
- sql += condition
- }
- sql += ` GROUP BY
- man.industrial_management_id
- ORDER BY
- man.one_month_follow_num DESC , man.industrial_management_id DESC
- LIMIT ?,?`
- _, err = orm.NewOrm().Raw(sql, 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
- }
|