123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_clpt/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:"是否跳转"`
- }
- 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,
- MAX( 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(industrialIdArr []int) (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
- AND a.article_id < ?
- AND a.is_report = 1
- AND a.is_class = 1
- AND mg.industrial_management_id IN(` + utils.GetOrmInReplace(len(industrialIdArr)) + `)
- GROUP BY
- mg.industrial_management_id `
- _, err = o.Raw(sql, utils.SummaryArticleId, industrialIdArr).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 int, mobile, condition string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE mobile=? AND industrial_management_id=? ` + condition
- err = orm.NewOrm().Raw(sql, mobile, 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(industrialIdArr []int) (items []*IndustrialSubject, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM cygx_industrial_subject WHERE industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `) `
- _, err = o.Raw(sql, industrialIdArr).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
- }
|