report.go 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "strconv"
  6. //"github.com/rdlucklib/rdluck_tools/paging"
  7. )
  8. type IndustrialManagementList struct {
  9. Paging *paging.PagingItem
  10. List []*IndustrialManagement
  11. }
  12. type IndustrialManagement struct {
  13. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  14. IndustryName string `description:"产业名称"`
  15. RecommendedIndex int `description:"推荐指数"`
  16. CategoryId int `description:"文章分类ID"`
  17. LayoutTime string `description:"布局时间"`
  18. UpdateTime string `description:"更新时间"`
  19. MinReportTime string `description:"报告最早发布时间"`
  20. IsRed bool `description:"是否标记红点"`
  21. IsTop bool `description:"是否置顶"`
  22. IsHot bool `description:"是否是热门-近一个月内,产业下关联的报告阅读次数最多的"`
  23. IsFollow int `description:"是否关注"`
  24. IsNew bool `description:"是否为新-关联报告的发布时间,均在3个月以内的"`
  25. Analyst string `description:"分析师"`
  26. ArticleReadNum int `description:"文章阅读数量"`
  27. OneMonFollowNum int `description:"近一个月关注增量"`
  28. AnalystList []*IndustrialAnalyst `description:"分析师列表"`
  29. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  30. ChartPermissionId int `description:"行业ID"`
  31. PermissionName string `description:"行业名称"`
  32. IndustryVideo *MicroVideoSimpleInfo
  33. AuthInfo *UserPermissionAuthInfo
  34. ArticleId int `description:"文章id"`
  35. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  36. }
  37. type MicroVideoSimpleInfo struct {
  38. Id int `description:"视频ID"`
  39. Title string `description:"标题"`
  40. ResourceUrl string `description:"链接"`
  41. BackgroundImg string `description:"背景图"`
  42. PlaySeconds int `description:"音视频时长"`
  43. DetailImgUrl string `description:"产业详情页背景图"`
  44. ChartPermissionId int `description:"行业ID"`
  45. ChartPermissionName string `description:"行业名称"`
  46. }
  47. type IndustrialAnalyst struct {
  48. AnalystName string `description:"分析师名称"`
  49. IndustrialManagementId int `description:"产业id"`
  50. }
  51. type IndustrialSubject struct {
  52. IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"`
  53. IndustrialManagementId int `description:"产业id"`
  54. SubjectName string `description:"标的名称"`
  55. IndustryName string `description:"产业名称"`
  56. LayoutTime string `description:"产业布局时间"`
  57. }
  58. //获取产业报告数量
  59. func GetReportIndustrialCount(categoryId, industrialManagementId int) (count int, err error) {
  60. o := orm.NewOrm()
  61. sql := `SELECT COUNT(1) count
  62. FROM
  63. cygx_article AS a
  64. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  65. WHERE
  66. a.publish_status = 1
  67. AND category_id IN (SELECT
  68. category_id
  69. FROM
  70. cygx_report_mapping
  71. WHERE
  72. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` )
  73. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` ) )
  74. AND a.is_class = 1
  75. AND man_g.industrial_management_id = ? `
  76. err = o.Raw(sql, industrialManagementId).QueryRow(&count)
  77. return
  78. }
  79. //获取产业报告列表
  80. func GetReportIndustrialList(pars []interface{}, categoryId, industrialManagementId, userId, startSize, pageSize int) (items []*ReportArticle, err error) {
  81. o := orm.NewOrm()
  82. 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
  83. FROM
  84. cygx_article AS a
  85. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  86. WHERE
  87. a.publish_status = 1
  88. AND category_id IN (SELECT
  89. category_id
  90. FROM
  91. cygx_report_mapping
  92. WHERE
  93. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` )
  94. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` ) )
  95. AND a.is_class = 1
  96. AND man_g.industrial_management_id = ?`
  97. sql += ` GROUP BY a.article_id ORDER BY publish_date DESC LIMIT ?,? `
  98. _, err = o.Raw(sql, pars, industrialManagementId, startSize, pageSize).QueryRows(&items)
  99. return
  100. }
  101. //产业下所关联的文章分类列表
  102. func IndustrialToArticleCategory(industrialManagementId, chartPermissionId int) (items []*IndustrialToArticleCategoryRep, err error) {
  103. o := orm.NewOrm()
  104. sql := `SELECT map.match_type_name,map.category_id
  105. FROM cygx_report_mapping AS map
  106. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  107. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  108. WHERE map.report_type = 2
  109. AND map.is_report = 1
  110. AND art.is_report = 1
  111. AND art.publish_status = 1
  112. AND man_g.industrial_management_id =?
  113. AND map.chart_permission_id = ?
  114. GROUP BY map.match_type_name`
  115. _, err = o.Raw(sql, industrialManagementId, chartPermissionId).QueryRows(&items)
  116. return
  117. }
  118. //产业下所关联的文章分类列表 2022-10-13
  119. func IndustrialToArticleCategoryNew(industrialManagementId int) (items []*IndustrialToArticleCategoryRep, err error) {
  120. o := orm.NewOrm()
  121. sql := `SELECT map.match_type_name,map.category_id
  122. FROM cygx_report_mapping AS map
  123. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  124. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  125. WHERE map.report_type = 2
  126. AND map.is_report = 1
  127. AND art.is_report = 1
  128. AND art.publish_status = 1
  129. AND man_g.industrial_management_id =?
  130. GROUP BY map.match_type_name`
  131. _, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
  132. return
  133. }
  134. //判断用户是否阅读该产业下,某一分类的文章
  135. func IndustrialUserRecordArticleCount(userId, industrialManagementId, categoryId int) (count int, err error) {
  136. o := orm.NewOrm()
  137. sql := `SELECT
  138. COUNT(1) count
  139. FROM
  140. cygx_article_history_record
  141. WHERE
  142. 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 )
  143. AND user_id = ? `
  144. err = o.Raw(sql, industrialManagementId, categoryId, userId).QueryRow(&count)
  145. return
  146. }
  147. //获取最新文章
  148. func GetNewIndustrialUserRecordArticle(industrialManagementId, categoryId int) (item *ArticleDetail, err error) {
  149. o := orm.NewOrm()
  150. 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`
  151. err = o.Raw(sql, industrialManagementId, categoryId).QueryRow(&item)
  152. return
  153. }
  154. //获取最新文章
  155. func GetNewArticleByCategoryId(categoryId int) (item *ArticleDetail, err error) {
  156. o := orm.NewOrm()
  157. sql := ` SELECT * FROM cygx_article WHERE category_id = ? ORDER BY publish_date DESC LIMIT 0, 1`
  158. err = o.Raw(sql, categoryId).QueryRow(&item)
  159. return
  160. }
  161. func GetIndustrialManagementIdsBykeyWord(condition string) (industrialManagementIds string, err error) {
  162. sql := `SELECT GROUP_CONCAT(DISTINCT industrial_management_id SEPARATOR ',') AS industrial_management_ids FROM cygx_industrial_management WHERE` + condition
  163. o := orm.NewOrm()
  164. err = o.Raw(sql).QueryRow(&industrialManagementIds)
  165. return
  166. }
  167. type ReportArticleWhichIndustrial struct {
  168. ArticleId int `description:"文章id"`
  169. Title string `description:"标题"`
  170. PublishDate string `description:"发布时间"`
  171. IndustryName string `description:"产业名称"`
  172. SubjectName string `description:"标的名称"`
  173. NickName string `description:"作者昵称"`
  174. IsRed bool `description:"是否标记红点"`
  175. Readnum int `description:"阅读数量"`
  176. IsResearch bool `description:"是否属于研选"`
  177. Pv int `description:"PV"`
  178. ImgUrlPc string `description:"图片链接"`
  179. }
  180. type ReportArticleWhichIndustrialRepList struct {
  181. HaveResearch bool `description:"是否有研选权限"`
  182. Paging *paging.PagingItem `description:"分页数据"`
  183. NickName string `description:"作者昵称"`
  184. IndustryName string `description:"产业名称"`
  185. List []*ReportArticleWhichIndustrial
  186. }
  187. //列表
  188. func IndustrialToArticleWhichDepartment(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*ReportArticleWhichIndustrial, err error) {
  189. o := orm.NewOrm()
  190. sql := `SELECT
  191. art.* ,m.industry_name,d.nick_name,
  192. (SELECT count(1) FROM cygx_article_history_record_newpv as h WHERE h.article_id = art.article_id ) as pv,
  193. ( 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
  194. FROM
  195. cygx_article AS art
  196. INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  197. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  198. INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
  199. WHERE 1 = 1
  200. AND art.publish_status = 1`
  201. if condition != "" {
  202. sql += condition
  203. }
  204. sql += ` LIMIT ?,?`
  205. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  206. return
  207. }
  208. func GetWhichDepartmentCount(condition string) (count int, err error) {
  209. o := orm.NewOrm()
  210. sql := `SELECT COUNT(1) count
  211. FROM
  212. cygx_article AS art
  213. INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  214. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  215. INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
  216. WHERE 1 = 1
  217. AND art.publish_status = 1`
  218. if condition != "" {
  219. sql += condition
  220. }
  221. err = o.Raw(sql).QueryRow(&count)
  222. return
  223. }
  224. type IsShow struct {
  225. IsShow bool `description:"绝密内参按钮是否展示"`
  226. IsShowFreeButton bool `description:"免费送月卡按钮是否展示"`
  227. IsShowResearch bool `description:"研选是否展示限免"`
  228. IsShowChart bool `description:"图表是否展示限免"`
  229. IsShowList bool `description:"榜单是否展示"`
  230. LinkWxExplain string `description:"关注微信公众号链接说明地址"`
  231. YanXuan_Explain bool `description:"研选说明"`
  232. ActivitySpecialExplain string `description:"专项调研活动"`
  233. SearchTxtList SearchTxt `description:"搜索栏回显内容说明"`
  234. }
  235. type SearchTxt struct {
  236. SummarySearch string `description:"素材库搜索说明"`
  237. ReportSearch string `description:"报告搜索说明"`
  238. YanXuanSearch string `description:"研选搜索说明"`
  239. ActivitySearch string `description:"活动搜索说明"`
  240. TabSearch string `description:"素材库搜索说明"`
  241. }
  242. //获取用户是否有查看权限
  243. func GetUserIsAdminCount(mobile string) (count int, err error) {
  244. o := orm.NewOrm()
  245. sql := `SELECT COUNT(1) count FROM admin
  246. WHERE
  247. mobile = ?
  248. AND (group_id IN (11, 13, 14, 15, 16, 17) OR department_id = 3 ) AND enabled = 1`
  249. err = o.Raw(sql, mobile).QueryRow(&count)
  250. return
  251. }
  252. type ReportDetailRoadshow struct {
  253. ArticleId int `description:"报告Id"`
  254. Title string `description:"标题"`
  255. Department string `orm:"column(seller_and_mobile)"description:"作者"`
  256. PublishDate string `description:"发布时间"`
  257. VideoUrl string `description:"链接"`
  258. VideoPlaySeconds string `description:"时长"`
  259. VideoName string `description:"音频名称"`
  260. Abstract string `description:"摘要"`
  261. Body string `description:"内容"`
  262. CategoryName string `description:"行业名称"`
  263. ReportLink string `orm:"column(link_article_id)"description:"报告链接"`
  264. }
  265. type RoadshowDetailResp struct {
  266. Detail *ReportDetailRoadshow
  267. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  268. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  269. }
  270. func GetReportRoadshowDetailById(articleId int) (item *ReportDetailRoadshow, err error) {
  271. o := orm.NewOrm()
  272. sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
  273. err = o.Raw(sql, articleId).QueryRow(&item)
  274. return
  275. }
  276. type CygxIndustryAndArticleList struct {
  277. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  278. Title string `description:"标题"`
  279. PublishDate string `description:"发布时间"`
  280. IndustryName string `description:"产业名称"`
  281. SubjectName string `description:"标的名称"`
  282. }
  283. type CygxIndustrySearchList struct {
  284. ArtList []*CygxIndustryAndArticleList `description:"文章列表"`
  285. IndList []*IndustrialManagement `description:"产业列表"`
  286. }
  287. type CygxIndustrySearchListPc struct {
  288. DepartmentList []*CygxArticleDepartmentRepPc
  289. IndList []*IndustrialManagement `description:"产业列表"`
  290. }
  291. //列表
  292. func GetCygxIndustryAndArticleList(keyWord string) (items []*CygxIndustryAndArticleList, err error) {
  293. o := orm.NewOrm()
  294. sql := `SELECT
  295. art.title,
  296. art.article_id,
  297. art.publish_date
  298. FROM
  299. cygx_article AS art
  300. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
  301. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = mg.article_id
  302. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  303. WHERE
  304. category_name LIKE '%研选%'
  305. 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 )
  306. 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 '%研选%' )
  307. GROUP BY
  308. art.article_id`
  309. _, err = o.Raw(sql).QueryRows(&items)
  310. return
  311. }
  312. func GetArticleIdsBySubId(subjectId string) (articleIds string, err error) {
  313. o := orm.NewOrm()
  314. sql := `SELECT GROUP_CONCAT( DISTINCT a.article_id SEPARATOR ',' ) AS articleIds
  315. FROM cygx_article AS a
  316. WHERE subject_ids LIKE '%` + subjectId + `%'`
  317. err = o.Raw(sql).QueryRow(&articleIds)
  318. return
  319. } //end
  320. //用户收藏榜start
  321. type ArticleCollectionResp struct {
  322. ArticleId int `description:"文章id"`
  323. Title string `description:"标题"`
  324. PublishDate string `description:"发布时间"`
  325. IndustrialManagementId int `description:"产业Id"`
  326. IndustryName string `description:"产业名称"`
  327. DepartmentId int `description:"作者Id"`
  328. NickName string `description:"作者昵称"`
  329. MyCollectNum int `description:"本人是否收藏"`
  330. IsCollect bool `description:"本人是否收藏"`
  331. Pv int `description:"PV"`
  332. CollectNum int `description:"收藏人数"`
  333. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  334. }
  335. type ArticleCollectionLIstResp struct {
  336. List []*ArticleCollectionResp
  337. }
  338. //列表
  339. func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  340. o := orm.NewOrm()
  341. sql := `SELECT
  342. a.article_id,
  343. a.title,
  344. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  345. m.industry_name,
  346. m.industrial_management_id,
  347. d.nick_name,
  348. d.department_id,
  349. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  350. ( 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,
  351. ( 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 AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  352. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  353. FROM
  354. cygx_article AS a
  355. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  356. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  357. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  358. WHERE
  359. 1 = 1 AND a.publish_status = 1 `
  360. if condition != "" {
  361. sql += condition
  362. }
  363. _, err = o.Raw(sql, userId).QueryRows(&items)
  364. return
  365. } //end
  366. //用户收藏榜start
  367. type IndustrialManagementHotResp struct {
  368. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  369. IndustryName string `description:"产业名称"`
  370. IsFollw bool `description:"是否关注"`
  371. FllowNum int `description:"关注数量"`
  372. IsNew bool `description:"是否新标签"`
  373. IsHot bool `description:"是否新标签"`
  374. PublishDate string `description:"发布时间"`
  375. ArticleReadNum int `description:"文章阅读数量"`
  376. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  377. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  378. IndustryVideo *MicroVideoSimpleInfo `description:"产业视频"`
  379. AuthInfo *UserPermissionAuthInfo
  380. }
  381. type IndustrialManagementHotListResp struct {
  382. Paging *paging.PagingItem `description:"分页数据"`
  383. List []*IndustrialManagementHotResp
  384. }
  385. //产业列表
  386. func GetThemeHeatList(userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  387. o := orm.NewOrm()
  388. sql := `SELECT
  389. m.industry_name,
  390. m.industrial_management_id,
  391. m.article_read_num,
  392. MAX( a.publish_date ) AS publish_date,
  393. ( 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,
  394. 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 ) AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( la.activity_time ) ) AS sum_num
  395. FROM
  396. cygx_industrial_management AS m
  397. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  398. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  399. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  400. WHERE
  401. 1 = 1
  402. AND a.article_type_id > 0
  403. AND publish_status = 1
  404. GROUP BY m.industrial_management_id ` + condition + ` LIMIT ?,?`
  405. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  406. return
  407. }
  408. //获取数量
  409. func GetThemeHeatListCount(condition string) (count int, err error) {
  410. o := orm.NewOrm()
  411. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  412. cygx_industrial_management AS m
  413. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  414. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  415. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  416. WHERE
  417. 1 = 1
  418. AND a.article_type_id > 0 AND a.publish_status = 1 ` + condition
  419. err = o.Raw(sql).QueryRow(&count)
  420. return
  421. }
  422. //标的列表
  423. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  424. o := orm.NewOrm()
  425. sql := `SELECT
  426. m.subject_name,
  427. m.industrial_management_id,
  428. m.industrial_subject_id
  429. FROM
  430. cygx_article AS a
  431. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  432. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  433. WHERE
  434. 1 = 1`
  435. if condition != "" {
  436. sql += condition
  437. }
  438. sql += ` AND publish_status = 1
  439. GROUP BY
  440. m.industrial_subject_id
  441. ORDER BY
  442. publish_date DESC`
  443. _, err = o.Raw(sql).QueryRows(&items)
  444. return
  445. } //end
  446. //Kol sratr
  447. type DepartmentResp struct {
  448. DepartmentId int `description:"作者Id"`
  449. NickName string `description:"作者昵称"`
  450. ImgUrl string `description:"图片链接"`
  451. IsFollw bool `description:"是否关注"`
  452. FllowNum int `description:"关注数量"`
  453. List []*IndustrialDepartmentListResp
  454. }
  455. type DepartmentListResp struct {
  456. List []*DepartmentResp
  457. }
  458. type IndustrialDepartmentListResp struct {
  459. IndustrialManagementId int `description:"产业Id"`
  460. IndustryName string `description:"产业名称"`
  461. DepartmentId int `description:"作者Id"`
  462. }
  463. //作者列表
  464. func GetDepartmentList(userId int) (items []*DepartmentResp, err error) {
  465. o := orm.NewOrm()
  466. sql := `SELECT
  467. d.nick_name,
  468. d.department_id,
  469. d.img_url,
  470. ( 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,
  471. ( 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 ) +( 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 IN (SELECT article_id FROM cygx_article WHERE department_id = d.department_id ) AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS sum_num
  472. FROM
  473. cygx_article_department AS d
  474. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  475. WHERE
  476. 1 = 1
  477. AND a.article_type_id > 0
  478. AND publish_status = 1
  479. GROUP BY
  480. d.department_id
  481. ORDER BY
  482. sum_num DESC
  483. LIMIT 15`
  484. _, err = o.Raw(sql, userId).QueryRows(&items)
  485. return
  486. }
  487. //作者文章所关联的产业列表
  488. func GetIndustrialDepartmentList() (items []*IndustrialDepartmentListResp, err error) {
  489. o := orm.NewOrm()
  490. sql := `SELECT
  491. m.industrial_management_id,
  492. m.industry_name,
  493. d.department_id
  494. FROM
  495. cygx_article_department AS d
  496. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  497. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  498. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  499. WHERE
  500. 1 = 1
  501. AND a.article_type_id > 0
  502. AND publish_status = 1
  503. GROUP BY
  504. a.article_id
  505. ORDER BY
  506. a.publish_date DESC`
  507. _, err = o.Raw(sql).QueryRows(&items)
  508. return
  509. }
  510. //主题详情start
  511. type GetThemeDetailListResp struct {
  512. ArticleId int `description:"文章id"`
  513. Title string `description:"标题"`
  514. PublishDate string `description:"发布时间"`
  515. SubjectName string `description:"标的名称"`
  516. IndustrialSubjectId int `description:"标的id"`
  517. DepartmentId int `description:"作者Id"`
  518. NickName string `description:"作者昵称"`
  519. Pv int `description:"PV"`
  520. CollectNum int `description:"收藏人数"`
  521. IndustrialManagementId int `description:"产业Id"`
  522. IndustryName string `description:"产业名称"`
  523. FllowNum int `description:"关注数量"`
  524. MyCollectNum int `description:"本人是否收藏"`
  525. IsCollect bool `description:"本人是否收藏"`
  526. }
  527. type GetThemeAericleListResp struct {
  528. ArticleId int `description:"文章id"`
  529. Title string `description:"标题"`
  530. PublishDate string `description:"发布时间"`
  531. SubjectName string `description:"标的名称"`
  532. IndustrialSubjectId int `description:"标的ID"`
  533. DepartmentId int `description:"作者Id"`
  534. NickName string `description:"作者昵称"`
  535. Pv int `description:"PV"`
  536. CollectNum int `description:"收藏人数"`
  537. FllowNum int `description:"关注数量"`
  538. MyCollectNum int `description:"本人是否收藏"`
  539. IsCollect bool `description:"本人是否收藏"`
  540. }
  541. type GetThemeAericleListBuSubjectResp struct {
  542. SubjectName string `description:"标的名称"`
  543. List []*GetThemeAericleListResp
  544. }
  545. //主题详情start
  546. type GetThemeDetailResp struct {
  547. IndustrialManagementId int `description:"产业Id"`
  548. IndustryName string `description:"产业名称"`
  549. IsFollw bool `description:"是否关注"`
  550. ListSubject []*IndustrialSubject `description:"标的列表"`
  551. List []*GetThemeAericleListResp
  552. }
  553. //列表
  554. func GetThemeDetail(userId, industrialManagementId int, condition string) (items []*GetThemeDetailListResp, err error) {
  555. o := orm.NewOrm()
  556. sql := `SELECT
  557. a.article_id,
  558. a.title,
  559. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  560. m.industry_name,
  561. m.industrial_management_id,
  562. d.nick_name,
  563. d.department_id,
  564. s.industrial_subject_id,
  565. s.subject_name,
  566. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  567. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  568. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num,
  569. ( 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
  570. FROM
  571. cygx_article AS a
  572. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  573. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  574. LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
  575. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
  576. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  577. WHERE
  578. 1 = 1
  579. AND m.industrial_management_id = ?
  580. AND publish_status = 1 ` + condition + `
  581. ORDER BY
  582. publish_date DESC`
  583. _, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)
  584. return
  585. } //end
  586. //用户收藏榜start
  587. type DepartmentDetailResp struct {
  588. DepartmentId int `description:"作者Id"`
  589. NickName string `description:"作者昵称"`
  590. ImgUrl string `description:"图片链接"`
  591. FllowNum int `description:"多少人关注"`
  592. ArticleNum int `description:"文章数量"`
  593. CollectNum int `description:"收藏人数"`
  594. IsFllow bool `description:"是否关注"`
  595. List []*ArticleCollectionResp
  596. ListIndustrial []*IndustrialManagementNewResp
  597. }
  598. type DepartmentDetail struct {
  599. DepartmentId int `description:"作者Id"`
  600. NickName string `description:"作者昵称"`
  601. ImgUrl string `description:"图片链接"`
  602. FllowNum int `description:"多少人关注"`
  603. ArticleNum int `description:"文章数量"`
  604. CollectNum int `description:"收藏人数"`
  605. IsFllow bool `description:"是否关注"`
  606. MyFllowNum int `description:"本人是否关注"`
  607. }
  608. //列表
  609. func GetDepartmentDetail(userId, departmentId int) (item DepartmentDetail, err error) {
  610. o := orm.NewOrm()
  611. sql := `SELECT
  612. d.department_id,
  613. d.nick_name,
  614. d.img_url,
  615. ( 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,
  616. ( 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,
  617. ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ) AS article_num,
  618. ( 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
  619. FROM
  620. cygx_article_department AS d
  621. WHERE
  622. d.department_id = ?`
  623. err = o.Raw(sql, userId, departmentId).QueryRow(&item)
  624. return
  625. } //end
  626. //报告搜索start
  627. type ReoprtSearchResp struct {
  628. ListYx []*ArticleCollectionResp `description:"研选报告"`
  629. ListHz []*ArticleCollectionResp `description:"弘则报告"`
  630. }
  631. //列表
  632. func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  633. o := orm.NewOrm()
  634. sql := `SELECT
  635. a.article_id,
  636. a.title,
  637. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  638. m.industry_name,
  639. m.industrial_management_id,
  640. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  641. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  642. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  643. FROM
  644. cygx_article AS a
  645. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  646. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  647. WHERE
  648. 1 = 1 `
  649. if condition != "" {
  650. sql += condition
  651. }
  652. _, err = o.Raw(sql, userId).QueryRows(&items)
  653. return
  654. } //end
  655. //搜索资源包 start
  656. type SearchResourceResp struct {
  657. ListHz []*IndustrialManagementHotResp `description:"弘则"`
  658. ListYx []*IndustrialManagementHotResp `description:"研选"`
  659. }
  660. //搜索资源包 start
  661. type SearchReportAndResourceResp struct {
  662. ListHzResource []*IndustrialManagementHotResp `description:"弘则资源包"`
  663. ListYxResource []*IndustrialManagementHotResp `description:"研选资源包"`
  664. ListYxReport []*ArticleCollectionResp `description:"研选报告"`
  665. ListHzReport []*ArticleCollectionResp `description:"弘则报告"`
  666. }
  667. //产业列表
  668. func GetSearchResourceList(condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  669. o := orm.NewOrm()
  670. sql := `SELECT
  671. m.industry_name,
  672. m.industrial_management_id,
  673. MAX( a.publish_date ) as publish_date_order,
  674. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
  675. FROM
  676. cygx_industrial_management AS m
  677. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  678. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  679. WHERE
  680. 1 = 1
  681. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  682. if startSize > 0 || pageSize > 0 {
  683. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  684. }
  685. _, err = o.Raw(sql).QueryRows(&items)
  686. return
  687. }
  688. //切换列表
  689. type ReportBillboardTableResp struct {
  690. Name string `description:"名称"`
  691. Source int `description:"类型"`
  692. List []*ChartPermission
  693. }
  694. //切换列表
  695. type ReportBillboardTableListResp struct {
  696. List []*ReportBillboardTableResp
  697. }
  698. //报告榜单start
  699. type ArticleReportBillboardResp struct {
  700. ArticleId int `description:"文章id"`
  701. Title string `description:"标题"`
  702. PublishDate string `description:"发布时间"`
  703. PermissionName string `description:"行业名称"`
  704. DepartmentId int `description:"作者Id"`
  705. NickName string `description:"作者昵称"`
  706. IsCollect bool `description:"本人是否收藏"`
  707. Pv int `description:"PV"`
  708. CollectNum int `description:"收藏人数"`
  709. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  710. List []*IndustrialManagementIdInt
  711. }
  712. type ArticleReportBillboardLIstResp struct {
  713. List []*ArticleReportBillboardResp
  714. }
  715. type ArticleReportBillboardLIstPageResp struct {
  716. List []*ArticleReportBillboardResp
  717. Paging *paging.PagingItem
  718. }
  719. //报告收藏榜单列表
  720. func GetReportCollectionBillboardList(limit int, pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  721. o := orm.NewOrm()
  722. sql := `SELECT
  723. ac.id,
  724. a.article_id,
  725. a.title,
  726. date_format(a.publish_date, '%Y-%m-%d') AS publish_date,
  727. m.chart_permission_name AS permission_name,
  728. COUNT(ac.id) AS collection_num
  729. FROM
  730. cygx_article AS a
  731. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  732. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  733. WHERE
  734. 1 = 1
  735. AND a.publish_status = 1 `
  736. if condition != "" {
  737. sql += condition
  738. }
  739. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, ac.id DESC, a.publish_date DESC`
  740. sql += ` LIMIT ?`
  741. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  742. return
  743. }
  744. //报告阅读榜单列表
  745. func GetReportPvBillboardList(pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  746. o := orm.NewOrm()
  747. sql := `SELECT
  748. a.article_id,
  749. a.title,
  750. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date
  751. FROM
  752. cygx_article AS a
  753. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  754. WHERE
  755. 1 = 1
  756. AND a.publish_status = 1 `
  757. if condition != "" {
  758. sql += condition
  759. }
  760. _, err = o.Raw(sql, pars).QueryRows(&items)
  761. return
  762. }
  763. //获取产业报告+晨会点评数量
  764. func GetTimeLineReportIndustrialCount(industrialManagementId int) (count int, err error) {
  765. o := orm.NewOrm()
  766. sql := `SELECT SUM(count) AS count FROM (
  767. SELECT
  768. COUNT( 1 ) count
  769. FROM
  770. cygx_article AS a
  771. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  772. WHERE
  773. a.publish_status = 1
  774. AND a.is_class = 1
  775. AND man_g.industrial_management_id = ?
  776. UNION ALL
  777. SELECT
  778. COUNT( 1 ) count
  779. FROM
  780. cygx_morning_meeting_review_chapter AS mmc
  781. INNER JOIN cygx_morning_meeting_reviews AS mm
  782. WHERE
  783. mm.id = mmc.meeting_id
  784. AND mm.status = 1
  785. AND mmc.industry_id = ? ) AS t `
  786. err = o.Raw(sql, industrialManagementId, industrialManagementId).QueryRow(&count)
  787. return
  788. }
  789. type TimeLineReportItem struct {
  790. Id int `description:"文章或晨报点评id"`
  791. Title string `description:"标题"`
  792. PublishTime string `description:"发布时间"`
  793. Content string `description:"内容"`
  794. VideoUrl string `description:"视频链接"`
  795. IsHaveVideo bool `description:"是否包含视频"`
  796. ImgUrlPc string `description:"pc图片"`
  797. SubCategoryName string `description:"二级分类"`
  798. }
  799. //获取产业报告+晨会点评列表
  800. func GetTimeLineReportIndustrialList(industrialManagementId, startSize, pageSize int) (items []*TimeLineReportItem, err error) {
  801. o := orm.NewOrm()
  802. sql := `SELECT
  803. *
  804. FROM
  805. (
  806. SELECT
  807. a.article_id AS id,
  808. a.title,
  809. a.publish_date AS publish_time,
  810. a.video_url,
  811. a.sub_category_name,
  812. '' AS content
  813. FROM
  814. cygx_article AS a
  815. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  816. WHERE
  817. a.publish_status = 1
  818. AND a.is_class = 1
  819. AND man_g.industrial_management_id = ? GROUP BY id UNION ALL
  820. SELECT
  821. mmc.id,
  822. '' AS title,
  823. mm.meeting_time AS publish_time,
  824. '' AS video_url,
  825. '时间线' AS sub_category_name,
  826. mmc.content
  827. FROM
  828. cygx_morning_meeting_review_chapter AS mmc
  829. INNER JOIN cygx_morning_meeting_reviews AS mm
  830. WHERE
  831. mm.id = mmc.meeting_id
  832. AND mm.STATUS = 1
  833. AND mmc.industry_id = ?
  834. ) AS t
  835. `
  836. sql += ` ORDER BY
  837. t.publish_time DESC LIMIT ?,? `
  838. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  839. return
  840. }