123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strconv"
- //"github.com/rdlucklib/rdluck_tools/paging"
- )
- type IndustrialManagementList struct {
- Paging *paging.PagingItem
- 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:"是否置顶"`
- IsHot bool `description:"是否是热门"`
- IsFollow int `description:"是否关注"`
- Analyst string `description:"分析师"`
- ArticleReadNum int `description:"文章阅读数量"`
- AnalystList []*IndustrialAnalyst `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 IN (SELECT
- category_id
- FROM
- cygx_report_mapping
- WHERE
- chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` )
- AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` ) )
- AND a.is_class = 1
- AND man_g.industrial_management_id = ?`
- err = o.Raw(sql, 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 IN (SELECT
- category_id
- FROM
- cygx_report_mapping
- WHERE
- chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` )
- AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` ) )
- AND a.is_class = 1
- AND man_g.industrial_management_id = ?`
- sql += ` ORDER BY publish_date DESC LIMIT ?,? `
- _, err = o.Raw(sql, pars, industrialManagementId, startSize, pageSize).QueryRows(&items)
- return
- }
- //产业下所关联的文章分类列表
- func IndustrialToArticleCategory(industrialManagementId, chartPermissionId 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 map.is_report = 1
- AND art.is_report = 1
- AND art.publish_status = 1
- AND man_g.industrial_management_id =?
- AND map.chart_permission_id = ?
- GROUP BY map.match_type_name`
- _, err = o.Raw(sql, industrialManagementId, chartPermissionId).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
- }
- //获取最新文章
- func GetNewIndustrialUserRecordArticle(industrialManagementId, categoryId 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 = ? ) AND category_id = ? ORDER BY publish_date DESC LIMIT 0, 1`
- err = o.Raw(sql, industrialManagementId, categoryId).QueryRow(&item)
- return
- }
- //获取最新文章
- func GetNewArticleByCategoryId(categoryId int) (item *ArticleDetail, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM cygx_article WHERE category_id = ? ORDER BY publish_date DESC LIMIT 0, 1`
- err = o.Raw(sql, categoryId).QueryRow(&item)
- return
- }
- func GetIndustrialManagementIdsBykeyWord(condition string) (industrialManagementIds string, err error) {
- sql := `SELECT GROUP_CONCAT(DISTINCT industrial_management_id SEPARATOR ',') AS industrial_management_ids FROM cygx_industrial_management WHERE` + condition
- o := orm.NewOrm()
- err = o.Raw(sql).QueryRow(&industrialManagementIds)
- return
- }
- type ReportArticleWhichIndustrial struct {
- ArticleId int `description:"文章id"`
- Title string `description:"标题"`
- PublishDate string `description:"发布时间"`
- IndustryName string `description:"产业名称"`
- SubjectName string `description:"标的名称"`
- NickName string `description:"作者昵称"`
- IsRed bool `description:"是否标记红点"`
- Readnum int `description:"阅读数量"`
- IsResearch bool `description:"是否属于研选"`
- Pv int `description:"PV"`
- ImgUrlPc string `description:"图片链接"`
- }
- type ReportArticleWhichIndustrialRepList struct {
- HaveResearch bool `description:"是否有研选权限"`
- Paging *paging.PagingItem `description:"分页数据"`
- NickName string `description:"作者昵称"`
- IndustryName string `description:"产业名称"`
- List []*ReportArticleWhichIndustrial
- }
- //列表
- func IndustrialToArticleWhichDepartment(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*ReportArticleWhichIndustrial, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- art.* ,m.industry_name,d.nick_name,
- (SELECT count(1) FROM cygx_article_history_record_newpv as h WHERE h.article_id = art.article_id ) as pv,
- ( SELECT COUNT( 1 ) FROM cygx_article_history_record_newpv AS rec WHERE rec.user_id = ` + strconv.Itoa(uid) + ` AND rec.article_id = art.article_id ) AS readnum
- FROM
- cygx_article AS art
- INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
- INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
- INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
- WHERE 1 = 1
- AND art.publish_status = 1`
- if condition != "" {
- sql += condition
- }
- sql += ` LIMIT ?,?`
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetWhichDepartmentCount(condition string) (count int, err error) {
- o := orm.NewOrm()
- //sql := `SELECT COUNT(*) count
- // FROM(
- // SELECT COUNT(1) count
- // FROM
- // cygx_article AS art
- // INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
- // INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
- // INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
- // WHERE 1 = 1
- // AND art.publish_status = 1`
- //if condition != "" {
- // sql += condition
- //}
- //sql += ` ) AS num`
- sql := `SELECT COUNT(1) count
- FROM
- cygx_article AS art
- INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
- INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
- INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
- WHERE 1 = 1
- AND art.publish_status = 1`
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql).QueryRow(&count)
- return
- }
- type IsShow struct {
- IsShow bool `description:"是否展示"`
- }
- //获取用户是否有查看权限
- func GetUserIsAdminCount(mobile string) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) count FROM admin
- WHERE
- mobile = ?
- AND (group_id IN (11, 13, 14, 15, 16, 17) OR department_id = 3 ) AND enabled = 1`
- err = o.Raw(sql, mobile).QueryRow(&count)
- return
- }
- type ReportDetailRoadshow struct {
- ArticleId int `description:"报告Id"`
- Title string `description:"标题"`
- Department string `orm:"column(seller_and_mobile)"description:"作者"`
- PublishDate string `description:"发布时间"`
- VideoUrl string `description:"链接"`
- VideoPlaySeconds string `description:"时长"`
- VideoName string `description:"音频名称"`
- Abstract string `description:"摘要"`
- Body string `description:"内容"`
- CategoryName string `description:"行业名称"`
- ReportLink string `orm:"column(link_article_id)"description:"报告链接"`
- }
- type RoadshowDetailResp struct {
- Detail *ReportDetailRoadshow
- HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
- HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
- }
- func GetReportRoadshowDetailById(articleId int) (item *ReportDetailRoadshow, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
- err = o.Raw(sql, articleId).QueryRow(&item)
- return
- }
- type CygxIndustryAndArticleList struct {
- ArticleId int `orm:"column(article_id);pk"description:"报告id"`
- Title string `description:"标题"`
- PublishDate string `description:"发布时间"`
- IndustryName string `description:"产业名称"`
- SubjectName string `description:"标的名称"`
- }
- type CygxIndustrySearchList struct {
- ArtList []*CygxIndustryAndArticleList `description:"文章列表"`
- IndList []*IndustrialManagement `description:"产业列表"`
- }
- type CygxIndustrySearchListPc struct {
- DepartmentList []*CygxArticleDepartmentRepPc
- IndList []*IndustrialManagement `description:"产业列表"`
- }
- //列表
- func GetCygxIndustryAndArticleList(keyWord string) (items []*CygxIndustryAndArticleList, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- art.title,
- art.article_id,
- art.publish_date
- FROM
- cygx_article AS art
- LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
- LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = mg.article_id
- LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
- WHERE
- category_name LIKE '%研选%'
- AND art.article_id IN ( SELECT article_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_subject WHERE subject_name LIKE '%` + keyWord + `%' ) GROUP BY sg.article_id )
- OR ( art.article_id IN ( SELECT article_id FROM cygx_industrial_article_group_management AS mg WHERE mg.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_management WHERE industry_name LIKE '%` + keyWord + `%' ) GROUP BY mg.article_id ) AND category_name LIKE '%研选%' )
- GROUP BY
- art.article_id`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetArticleIdsBySubId(subjectId string) (articleIds string, err error) {
- o := orm.NewOrm()
- sql := `SELECT GROUP_CONCAT( DISTINCT a.article_id SEPARATOR ',' ) AS articleIds
- FROM cygx_article AS a
- WHERE subject_ids LIKE '%` + subjectId + `%'`
- err = o.Raw(sql).QueryRow(&articleIds)
- return
- } //end
- //用户收藏榜start
- type ArticleCollectionResp struct {
- ArticleId int `description:"文章id"`
- Title string `description:"标题"`
- PublishDate string `description:"发布时间"`
- IndustrialManagementId int `description:"产业Id"`
- IndustryName string `description:"产业名称"`
- DepartmentId int `description:"作者Id"`
- NickName string `description:"作者昵称"`
- Pv int `description:"PV"`
- CollectNum int `description:"收藏人数"`
- MyCollectNum int `description:"本人是否收藏"`
- IsCollect bool `description:"本人是否收藏"`
- }
- type ArticleCollectionLIstResp struct {
- List []*ArticleCollectionResp
- }
- //列表
- func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- a.article_id,
- a.title,
- date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
- m.industry_name,
- m.industrial_management_id,
- d.nick_name,
- d.department_id,
- ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
- ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id ) AS collect_num,
- ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
- 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
- INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
- WHERE
- 1 = 1 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, userId).QueryRows(&items)
- return
- } //end
- //用户收藏榜start
- type IndustrialManagementHotResp struct {
- IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
- IndustryName string `description:"产业名称"`
- IsFollw bool `description:"是否关注"`
- FllowNum int `description:"关注数量"`
- IsNew bool `description:"是否新标签"`
- IsHot bool `description:"是否新标签"`
- PublishDate string `description:"发布时间"`
- ArticleReadNum int `description:"文章阅读数量"`
- IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
- }
- type IndustrialManagementHotListResp struct {
- List []*IndustrialManagementHotResp
- }
- //产业列表
- func GetThemeHeatList(permissionName string, userId int, condition string) (items []*IndustrialManagementHotResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- m.industry_name,
- m.industrial_management_id,
- m.article_read_num,
- date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date,
- ( SELECT count( 1 ) FROM cygx_industry_fllow AS f WHERE f.industrial_management_id = m.industrial_management_id AND user_id =? AND f.type = 1 ) AS fllow_num,
- m.article_read_num + ( SELECT count( 1 ) FROM cygx_activity_meet_detail_log AS la WHERE la.activity_id IN (SELECT activity_id FROM cygx_industrial_activity_group_management WHERE industrial_management_id = m.industrial_management_id )) AS sum_num
- FROM
- cygx_industrial_management AS m
- LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
- LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
- LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
- WHERE
- 1 = 1
- AND a.category_name LIKE '%` + permissionName + `%'
- AND publish_status = 1
- GROUP BY m.industrial_management_id ` + condition
- _, err = o.Raw(sql, userId).QueryRows(&items)
- return
- }
- //标的列表
- func GetThemeHeatSubjectList(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`
- if condition != "" {
- sql += condition
- }
- sql += ` AND publish_status = 1
- GROUP BY
- m.industrial_subject_id
- ORDER BY
- publish_date DESC`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- } //end
- //Kol sratr
- type DepartmentResp struct {
- DepartmentId int `description:"作者Id"`
- NickName string `description:"作者昵称"`
- ImgUrl string `description:"图片链接"`
- IsFollw bool `description:"是否关注"`
- FllowNum int `description:"关注数量"`
- List []*IndustrialDepartmentListResp
- }
- type DepartmentListResp struct {
- List []*DepartmentResp
- }
- type IndustrialDepartmentListResp struct {
- IndustrialManagementId int `description:"产业Id"`
- IndustryName string `description:"产业名称"`
- DepartmentId int `description:"作者Id"`
- }
- //作者列表
- func GetDepartmentList(permissionName string, userId int) (items []*DepartmentResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- d.nick_name,
- d.department_id,
- d.img_url,
- ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND user_id =? AND f.type= 1 ) AS fllow_num,
- ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.type= 1 ) +( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id) AS sum_num
- FROM
- cygx_article_department AS d
- INNER JOIN cygx_article AS a ON d.department_id = a.department_id
- WHERE
- 1 = 1
- AND a.category_name LIKE '%` + permissionName + `%'
- AND publish_status = 1
- GROUP BY
- d.department_id
- ORDER BY
- sum_num DESC
- LIMIT 15`
- _, err = o.Raw(sql, userId).QueryRows(&items)
- return
- }
- //作者文章所关联的产业列表
- func GetIndustrialDepartmentList(permissionName string) (items []*IndustrialDepartmentListResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- m.industrial_management_id,
- m.industry_name,
- d.department_id
- FROM
- cygx_article_department AS d
- INNER JOIN cygx_article AS a ON d.department_id = a.department_id
- 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.category_name LIKE '%` + permissionName + `%'
- AND publish_status = 1
- GROUP BY
- a.article_id
- ORDER BY
- a.publish_date DESC`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- //主题详情start
- type GetThemeDetailListResp struct {
- ArticleId int `description:"文章id"`
- Title string `description:"标题"`
- PublishDate string `description:"发布时间"`
- SubjectName string `description:"标的名称"`
- IndustrialSubjectId int `description:"标的id"`
- DepartmentId int `description:"作者Id"`
- NickName string `description:"作者昵称"`
- Pv int `description:"PV"`
- CollectNum int `description:"收藏人数"`
- IndustrialManagementId int `description:"产业Id"`
- IndustryName string `description:"产业名称"`
- FllowNum int `description:"关注数量"`
- MyCollectNum int `description:"本人是否收藏"`
- IsCollect bool `description:"本人是否收藏"`
- }
- type GetThemeAericleListResp struct {
- ArticleId int `description:"文章id"`
- Title string `description:"标题"`
- PublishDate string `description:"发布时间"`
- SubjectName string `description:"标的名称"`
- IndustrialSubjectId int `description:"标的ID"`
- DepartmentId int `description:"作者Id"`
- NickName string `description:"作者昵称"`
- Pv int `description:"PV"`
- CollectNum int `description:"收藏人数"`
- FllowNum int `description:"关注数量"`
- MyCollectNum int `description:"本人是否收藏"`
- IsCollect bool `description:"本人是否收藏"`
- }
- type GetThemeAericleListBuSubjectResp struct {
- SubjectName string `description:"标的名称"`
- List []*GetThemeAericleListResp
- }
- //主题详情start
- type GetThemeDetailResp struct {
- IndustrialManagementId int `description:"产业Id"`
- IndustryName string `description:"产业名称"`
- IsFollw bool `description:"是否关注"`
- ListSubject []*IndustrialSubject `description:"标的列表"`
- List []*GetThemeAericleListResp
- }
- //列表
- func GetThemeDetail(userId, industrialManagementId int) (items []*GetThemeDetailListResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- a.article_id,
- a.title,
- date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
- m.industry_name,
- m.industrial_management_id,
- d.nick_name,
- d.department_id,
- s.industrial_subject_id,
- s.subject_name,
- ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
- ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
- ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num,
- ( SELECT count( 1 ) FROM cygx_industry_fllow AS ac WHERE user_id = ? AND ac.industrial_management_id = m.industrial_management_id AND ac.type= 1) AS fllow_num
- FROM
- cygx_article AS a
- INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
- LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
- LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
- LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
- LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
- WHERE
- 1 = 1
- AND m.industrial_management_id = ?
- AND publish_status = 1
- AND a.category_name LIKE '%研选%'
- ORDER BY
- publish_date DESC`
- _, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)
- return
- } //end
- //用户收藏榜start
- type DepartmentDetailResp struct {
- DepartmentId int `description:"作者Id"`
- NickName string `description:"作者昵称"`
- ImgUrl string `description:"图片链接"`
- FllowNum int `description:"多少人关注"`
- ArticleNum int `description:"文章数量"`
- CollectNum int `description:"收藏人数"`
- IsFllow bool `description:"是否关注"`
- List []*ArticleCollectionResp
- }
- type DepartmentDetail struct {
- DepartmentId int `description:"作者Id"`
- NickName string `description:"作者昵称"`
- ImgUrl string `description:"图片链接"`
- FllowNum int `description:"多少人关注"`
- ArticleNum int `description:"文章数量"`
- CollectNum int `description:"收藏人数"`
- IsFllow bool `description:"是否关注"`
- MyFllowNum int `description:"本人是否关注"`
- }
- //列表
- func GetDepartmentDetail(userId, departmentId int) (item DepartmentDetail, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- d.department_id,
- d.nick_name,
- d.img_url,
- ( SELECT count( 1 ) FROM cygx_article_department_follow AS af WHERE af.user_id = ? AND af.department_id = d.department_id AND af.type= 1 ) AS my_fllow_num,
- ( SELECT count( 1 ) FROM cygx_article_department_follow AS f INNER JOIN wx_user as u ON u.user_id = f.user_id WHERE f.department_id = d.department_id AND f.type= 1 ) AS fllow_num,
- ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ) AS article_num,
- ( SELECT count( 1 ) FROM cygx_article_collect AS c INNER JOIN wx_user as u ON u.user_id = c.user_id WHERE c.article_id IN (SELECT article_id FROM cygx_article AS a WHERE a.department_id = d.department_id )) AS collect_num
- FROM
- cygx_article_department AS d
- WHERE
- d.department_id = ?`
- err = o.Raw(sql, userId, departmentId).QueryRow(&item)
- return
- } //end
- //报告搜索start
- type ReoprtSearchResp struct {
- ListYx []*ArticleCollectionResp `description:"研选报告"`
- ListHz []*ArticleCollectionResp `description:"弘则报告"`
- }
- //列表
- func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- a.article_id,
- a.title,
- date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
- m.industry_name,
- m.industrial_management_id,
- ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
- ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
- ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
- 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 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, userId).QueryRows(&items)
- return
- } //end
- //搜索资源包 start
- type SearchResourceResp struct {
- ListHz []*IndustrialManagementHotResp `description:"弘则"`
- ListYx []*IndustrialManagementHotResp `description:"研选"`
- }
- //产业列表
- func GetSearchResourceList(condition string) (items []*IndustrialManagementHotResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- m.industry_name,
- m.industrial_management_id,
- date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
- 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
- WHERE
- 1 = 1
- AND publish_status = 1 ` + condition
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
|