report.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  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 match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE 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. IsRed bool `description:"是否标记红点"`
  375. Readnum int `description:"阅读数量"`
  376. PublishDate string `description:"发布时间"`
  377. MinReportTime string `description:"报告最早发布时间"`
  378. ArticleReadNum int `description:"文章阅读数量"`
  379. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  380. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  381. IndustryVideo *MicroVideoSimpleInfo `description:"产业视频"`
  382. AuthInfo *UserPermissionAuthInfo
  383. }
  384. type IndustrialManagementHotListResp struct {
  385. Paging *paging.PagingItem `description:"分页数据"`
  386. List []*IndustrialManagementHotResp
  387. }
  388. //产业列表
  389. func GetThemeHeatList(userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  390. o := orm.NewOrm()
  391. sql := `SELECT
  392. m.industry_name,
  393. m.industrial_management_id,
  394. m.article_read_num,
  395. MAX( a.publish_date ) AS publish_date,
  396. MIN(a.publish_date) AS min_report_time,
  397. ( 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,
  398. 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
  399. FROM
  400. cygx_industrial_management AS m
  401. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  402. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  403. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  404. WHERE
  405. 1 = 1
  406. AND a.article_type_id > 0
  407. AND publish_status = 1
  408. GROUP BY m.industrial_management_id ` + condition + ` LIMIT ?,?`
  409. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  410. return
  411. }
  412. //获取数量
  413. func GetThemeHeatListCount(condition string) (count int, err error) {
  414. o := orm.NewOrm()
  415. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  416. cygx_industrial_management AS m
  417. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  418. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  419. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  420. WHERE
  421. 1 = 1
  422. AND a.article_type_id > 0 AND a.publish_status = 1 ` + condition
  423. err = o.Raw(sql).QueryRow(&count)
  424. return
  425. }
  426. //标的列表
  427. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  428. o := orm.NewOrm()
  429. sql := `SELECT
  430. m.subject_name,
  431. m.industrial_management_id,
  432. m.industrial_subject_id
  433. FROM
  434. cygx_article AS a
  435. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  436. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  437. WHERE
  438. 1 = 1`
  439. if condition != "" {
  440. sql += condition
  441. }
  442. sql += ` AND publish_status = 1
  443. GROUP BY
  444. m.industrial_subject_id
  445. ORDER BY
  446. publish_date DESC`
  447. _, err = o.Raw(sql).QueryRows(&items)
  448. return
  449. } //end
  450. //Kol sratr
  451. type DepartmentResp struct {
  452. DepartmentId int `description:"作者Id"`
  453. NickName string `description:"作者昵称"`
  454. ImgUrl string `description:"图片链接"`
  455. IsFollw bool `description:"是否关注"`
  456. FllowNum int `description:"关注数量"`
  457. List []*IndustrialDepartmentListResp
  458. }
  459. type DepartmentListResp struct {
  460. List []*DepartmentResp
  461. }
  462. type IndustrialDepartmentListResp struct {
  463. IndustrialManagementId int `description:"产业Id"`
  464. IndustryName string `description:"产业名称"`
  465. DepartmentId int `description:"作者Id"`
  466. }
  467. //作者列表
  468. func GetDepartmentList(userId int) (items []*DepartmentResp, err error) {
  469. o := orm.NewOrm()
  470. sql := `SELECT
  471. d.nick_name,
  472. d.department_id,
  473. d.img_url,
  474. ( 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,
  475. ( 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
  476. FROM
  477. cygx_article_department AS d
  478. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  479. WHERE
  480. 1 = 1
  481. AND a.article_type_id > 0
  482. AND publish_status = 1
  483. GROUP BY
  484. d.department_id
  485. ORDER BY
  486. sum_num DESC
  487. LIMIT 15`
  488. _, err = o.Raw(sql, userId).QueryRows(&items)
  489. return
  490. }
  491. //作者文章所关联的产业列表
  492. func GetIndustrialDepartmentList() (items []*IndustrialDepartmentListResp, err error) {
  493. o := orm.NewOrm()
  494. sql := `SELECT
  495. m.industrial_management_id,
  496. m.industry_name,
  497. d.department_id
  498. FROM
  499. cygx_article_department AS d
  500. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  501. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  502. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  503. WHERE
  504. 1 = 1
  505. AND a.article_type_id > 0
  506. AND publish_status = 1
  507. GROUP BY
  508. a.article_id
  509. ORDER BY
  510. a.publish_date DESC`
  511. _, err = o.Raw(sql).QueryRows(&items)
  512. return
  513. }
  514. //主题详情start
  515. type GetThemeDetailListResp struct {
  516. ArticleId int `description:"文章id"`
  517. Title string `description:"标题"`
  518. PublishDate string `description:"发布时间"`
  519. SubjectName string `description:"标的名称"`
  520. IndustrialSubjectId int `description:"标的id"`
  521. DepartmentId int `description:"作者Id"`
  522. NickName string `description:"作者昵称"`
  523. Pv int `description:"PV"`
  524. CollectNum int `description:"收藏人数"`
  525. IndustrialManagementId int `description:"产业Id"`
  526. IndustryName string `description:"产业名称"`
  527. FllowNum int `description:"关注数量"`
  528. MyCollectNum int `description:"本人是否收藏"`
  529. IsCollect bool `description:"本人是否收藏"`
  530. }
  531. type GetThemeAericleListResp struct {
  532. ArticleId int `description:"文章id"`
  533. Title string `description:"标题"`
  534. PublishDate string `description:"发布时间"`
  535. SubjectName string `description:"标的名称"`
  536. IndustrialSubjectId int `description:"标的ID"`
  537. DepartmentId int `description:"作者Id"`
  538. NickName string `description:"作者昵称"`
  539. Pv int `description:"PV"`
  540. CollectNum int `description:"收藏人数"`
  541. FllowNum int `description:"关注数量"`
  542. MyCollectNum int `description:"本人是否收藏"`
  543. IsCollect bool `description:"本人是否收藏"`
  544. }
  545. type GetThemeAericleListBuSubjectResp struct {
  546. SubjectName string `description:"标的名称"`
  547. List []*GetThemeAericleListResp
  548. }
  549. //主题详情start
  550. type GetThemeDetailResp struct {
  551. IndustrialManagementId int `description:"产业Id"`
  552. IndustryName string `description:"产业名称"`
  553. IsFollw bool `description:"是否关注"`
  554. ListSubject []*IndustrialSubject `description:"标的列表"`
  555. List []*GetThemeAericleListResp
  556. }
  557. //列表
  558. func GetThemeDetail(userId, industrialManagementId int, condition string) (items []*GetThemeDetailListResp, err error) {
  559. o := orm.NewOrm()
  560. sql := `SELECT
  561. a.article_id,
  562. a.title,
  563. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  564. m.industry_name,
  565. m.industrial_management_id,
  566. d.nick_name,
  567. d.department_id,
  568. s.industrial_subject_id,
  569. s.subject_name,
  570. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  571. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  572. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num,
  573. ( 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
  574. FROM
  575. cygx_article AS a
  576. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  577. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  578. LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
  579. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
  580. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  581. WHERE
  582. 1 = 1
  583. AND m.industrial_management_id = ?
  584. AND publish_status = 1 ` + condition + `
  585. ORDER BY
  586. publish_date DESC`
  587. _, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)
  588. return
  589. } //end
  590. //用户收藏榜start
  591. type DepartmentDetailResp struct {
  592. DepartmentId int `description:"作者Id"`
  593. NickName string `description:"作者昵称"`
  594. ImgUrl string `description:"图片链接"`
  595. FllowNum int `description:"多少人关注"`
  596. ArticleNum int `description:"文章数量"`
  597. CollectNum int `description:"收藏人数"`
  598. IsFllow bool `description:"是否关注"`
  599. List []*ArticleCollectionResp
  600. ListIndustrial []*IndustrialManagementNewResp
  601. }
  602. type DepartmentDetail struct {
  603. DepartmentId int `description:"作者Id"`
  604. NickName string `description:"作者昵称"`
  605. ImgUrl string `description:"图片链接"`
  606. FllowNum int `description:"多少人关注"`
  607. ArticleNum int `description:"文章数量"`
  608. CollectNum int `description:"收藏人数"`
  609. IsFllow bool `description:"是否关注"`
  610. MyFllowNum int `description:"本人是否关注"`
  611. }
  612. //列表
  613. func GetDepartmentDetail(userId, departmentId int) (item DepartmentDetail, err error) {
  614. o := orm.NewOrm()
  615. sql := `SELECT
  616. d.department_id,
  617. d.nick_name,
  618. d.img_url,
  619. ( 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,
  620. ( 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,
  621. ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ) AS article_num,
  622. ( 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
  623. FROM
  624. cygx_article_department AS d
  625. WHERE
  626. d.department_id = ?`
  627. err = o.Raw(sql, userId, departmentId).QueryRow(&item)
  628. return
  629. } //end
  630. //报告搜索start
  631. type ReoprtSearchResp struct {
  632. ListYx []*ArticleCollectionResp `description:"研选报告"`
  633. ListHz []*ArticleCollectionResp `description:"弘则报告"`
  634. }
  635. //列表
  636. func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  637. o := orm.NewOrm()
  638. sql := `SELECT
  639. a.article_id,
  640. a.title,
  641. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  642. m.industry_name,
  643. m.industrial_management_id,
  644. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  645. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  646. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  647. FROM
  648. cygx_article AS a
  649. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  650. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  651. WHERE
  652. 1 = 1 `
  653. if condition != "" {
  654. sql += condition
  655. }
  656. _, err = o.Raw(sql, userId).QueryRows(&items)
  657. return
  658. } //end
  659. //搜索资源包 start
  660. type SearchResourceResp struct {
  661. ListHz []*IndustrialManagementHotResp `description:"弘则"`
  662. ListYx []*IndustrialManagementHotResp `description:"研选"`
  663. }
  664. //搜索资源包 start
  665. type SearchReportAndResourceResp struct {
  666. ListHzResource []*IndustrialManagementHotResp `description:"弘则资源包"`
  667. ListYxResource []*IndustrialManagementHotResp `description:"研选资源包"`
  668. ListYxReport []*ArticleCollectionResp `description:"研选报告"`
  669. ListHzReport []*ArticleCollectionResp `description:"弘则报告"`
  670. }
  671. //产业列表
  672. func GetSearchResourceList(userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  673. o := orm.NewOrm()
  674. sql := `SELECT
  675. m.industry_name,
  676. m.industrial_management_id,
  677. MAX( a.publish_date ) as publish_date_order,
  678. MIN(a.publish_date) AS min_report_time,
  679. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date,
  680. (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
  681. FROM
  682. cygx_industrial_management AS m
  683. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  684. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  685. WHERE
  686. 1 = 1
  687. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  688. if startSize > 0 || pageSize > 0 {
  689. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  690. }
  691. _, err = o.Raw(sql).QueryRows(&items)
  692. return
  693. }
  694. //切换列表
  695. type ReportBillboardTableResp struct {
  696. Name string `description:"名称"`
  697. Source int `description:"类型"`
  698. List []*ChartPermission
  699. }
  700. //切换列表
  701. type ReportBillboardTableListResp struct {
  702. List []*ReportBillboardTableResp
  703. }
  704. //报告榜单start
  705. type ArticleReportBillboardResp struct {
  706. ArticleId int `description:"文章id"`
  707. Title string `description:"标题"`
  708. PublishDate string `description:"发布时间"`
  709. PermissionName string `description:"行业名称"`
  710. DepartmentId int `description:"作者Id"`
  711. NickName string `description:"作者昵称"`
  712. IsCollect bool `description:"本人是否收藏"`
  713. Pv int `description:"PV"`
  714. CollectNum int `description:"收藏人数"`
  715. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  716. List []*IndustrialManagementIdInt
  717. }
  718. type ArticleReportBillboardLIstResp struct {
  719. List []*ArticleReportBillboardResp
  720. }
  721. type ArticleReportBillboardLIstPageResp struct {
  722. List []*ArticleReportBillboardResp
  723. Paging *paging.PagingItem
  724. }
  725. //报告收藏榜单列表
  726. func GetReportCollectionBillboardList(limit int, pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  727. o := orm.NewOrm()
  728. sql := `SELECT
  729. ac.id,
  730. a.article_id,
  731. a.title,
  732. date_format(a.publish_date, '%Y-%m-%d') AS publish_date,
  733. m.chart_permission_name AS permission_name,
  734. COUNT(ac.id) AS collection_num
  735. FROM
  736. cygx_article AS a
  737. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  738. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  739. WHERE
  740. 1 = 1
  741. AND a.publish_status = 1 `
  742. if condition != "" {
  743. sql += condition
  744. }
  745. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, ac.id DESC, a.publish_date DESC`
  746. sql += ` LIMIT ?`
  747. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  748. return
  749. }
  750. //报告阅读榜单列表
  751. func GetReportPvBillboardList(pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  752. o := orm.NewOrm()
  753. sql := `SELECT
  754. a.article_id,
  755. a.title,
  756. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date
  757. FROM
  758. cygx_article AS a
  759. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  760. WHERE
  761. 1 = 1
  762. AND a.publish_status = 1 `
  763. if condition != "" {
  764. sql += condition
  765. }
  766. _, err = o.Raw(sql, pars).QueryRows(&items)
  767. return
  768. }
  769. //获取产业报告+晨会点评数量
  770. func GetTimeLineReportIndustrialCount(industrialManagementId int) (count int, err error) {
  771. o := orm.NewOrm()
  772. sql := `SELECT SUM(count) AS count FROM (
  773. SELECT
  774. COUNT( 1 ) count
  775. FROM
  776. cygx_article AS a
  777. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  778. WHERE
  779. a.publish_status = 1
  780. AND a.is_class = 1
  781. AND man_g.industrial_management_id = ?
  782. UNION ALL
  783. SELECT
  784. COUNT( 1 ) count
  785. FROM
  786. cygx_morning_meeting_review_chapter AS mmc
  787. INNER JOIN cygx_morning_meeting_reviews AS mm
  788. WHERE
  789. mm.id = mmc.meeting_id
  790. AND mm.status = 1
  791. AND mmc.industry_id = ? ) AS t `
  792. err = o.Raw(sql, industrialManagementId, industrialManagementId).QueryRow(&count)
  793. return
  794. }
  795. type TimeLineReportItem struct {
  796. Id int `description:"文章或晨报点评id"`
  797. Title string `description:"标题"`
  798. PublishTime string `description:"发布时间"`
  799. Content string `description:"内容"`
  800. VideoUrl string `description:"视频链接"`
  801. IsHaveVideo bool `description:"是否包含视频"`
  802. ImgUrlPc string `description:"pc图片"`
  803. SubCategoryName string `description:"二级分类"`
  804. IsRed bool `description:"是否标红"`
  805. Readnum int `description:"阅读数量"`
  806. }
  807. //获取产业报告+晨会点评列表
  808. func GetTimeLineReportIndustrialList(userId, industrialManagementId, startSize, pageSize int) (items []*TimeLineReportItem, err error) {
  809. o := orm.NewOrm()
  810. sql := `SELECT
  811. *
  812. FROM
  813. (
  814. SELECT
  815. a.article_id AS id,
  816. a.title,
  817. a.publish_date AS publish_time,
  818. a.video_url,
  819. a.sub_category_name,
  820. '' AS content,
  821. ( 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
  822. FROM
  823. cygx_article AS a
  824. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  825. WHERE
  826. a.publish_status = 1
  827. AND a.is_class = 1
  828. AND man_g.industrial_management_id = ? GROUP BY id UNION ALL
  829. SELECT
  830. mmc.id,
  831. '' AS title,
  832. mm.meeting_time AS publish_time,
  833. '' AS video_url,
  834. '时间线' AS sub_category_name,
  835. mmc.content,
  836. 0 AS readnum
  837. FROM
  838. cygx_morning_meeting_review_chapter AS mmc
  839. INNER JOIN cygx_morning_meeting_reviews AS mm
  840. WHERE
  841. mm.id = mmc.meeting_id
  842. AND mm.STATUS = 1
  843. AND mmc.industry_id = ?
  844. ) AS t
  845. `
  846. sql += ` ORDER BY
  847. t.publish_time DESC LIMIT ?,? `
  848. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  849. return
  850. }
  851. type ArticleIdReq struct {
  852. ArticleId int `description:"文章id"`
  853. PlaySeconds int `description:"播放时长"`
  854. PageRouter string `description:"页面路径"`
  855. }