report.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_clpt/utils"
  6. "strconv"
  7. "time"
  8. )
  9. type IndustrialManagementList struct {
  10. Paging *paging.PagingItem
  11. List []*IndustrialManagement
  12. }
  13. type IndustrialManagement struct {
  14. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  15. IndustryName string `description:"产业名称"`
  16. ChartPermissionId int `description:"权限id"`
  17. ChartPermissionName string `description:"权限名称"`
  18. LayoutTime string `description:"布局时间"`
  19. UpdateTime string `description:"更新时间"`
  20. IsRed bool `description:"是否标记红点"`
  21. IsHot bool `description:"是否是热门"`
  22. IsFollow bool `description:"是否关注"`
  23. IsNew bool `description:"是否展示 NEW 标签"`
  24. IsShowRoadshow bool `description:"是否展示 微路演 标签"`
  25. ArticleReadNum int `description:"文章阅读数量"`
  26. ArticleId int `description:"文章id"`
  27. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  28. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  29. MinReportTime string `description:"报告最早发布时间"`
  30. IndustryVideo *MicroVideoSimpleInfo
  31. AuthInfo *UserPermissionAuthInfo
  32. }
  33. type MicroVideoSimpleInfo struct {
  34. Id int `description:"视频ID"`
  35. Title string `description:"标题"`
  36. ResourceUrl string `description:"链接"`
  37. BackgroundImg string `description:"背景图"`
  38. PlaySeconds int `description:"音视频时长"`
  39. DetailImgUrl string `description:"产业详情页背景图"`
  40. ChartPermissionId int `description:"行业ID"`
  41. ChartPermissionName string `description:"行业名称"`
  42. }
  43. type TacticsListResp struct {
  44. Paging *paging.PagingItem
  45. MatchTypeName string `description:"匹配类型"`
  46. CategoryImgUrlPc string `description:"图片"`
  47. List []*HomeArticle
  48. }
  49. type TacticsListTimeResp struct {
  50. Paging *paging.PagingItem
  51. MatchTypeName string `description:"匹配类型"`
  52. CategoryImgUrlPc string `description:"图片"`
  53. List []*TimeLineReportItem
  54. }
  55. // 报告搜索start
  56. type ReoprtSearchResp struct {
  57. Paging *paging.PagingItem
  58. ListHz []*ArticleResearchResp `description:"弘则报告"`
  59. ListYx []*ArticleResearchResp `description:"研选报告"`
  60. }
  61. // 搜索资源包 start
  62. type SearchResourceResp struct {
  63. ListHz []*IndustrialManagement `description:"弘则"`
  64. ListYx []*IndustrialManagement `description:"研选"`
  65. }
  66. type ArticleIdReq struct {
  67. ArticleId int `description:"文章id"`
  68. PlaySeconds int `description:"播放时长"`
  69. PageRouter string `description:"页面路径"`
  70. ReportType int `description:"2本周研究汇总、3上周纪要汇总"`
  71. }
  72. // 获取列表数量
  73. func GetReoprtSearchCount(condition string) (count int, err error) {
  74. o := orm.NewOrm()
  75. sql := `SELECT
  76. COUNT( 1 ) AS count
  77. FROM
  78. cygx_article AS a
  79. WHERE
  80. 1 = 1
  81. AND a.article_id < 1000000 `
  82. if condition != "" {
  83. sql += condition
  84. }
  85. err = o.Raw(sql).QueryRow(&count)
  86. return
  87. }
  88. func GetReoprtSearchCountYx(condition string) (count int, err error) {
  89. o := orm.NewOrm()
  90. sql := `SELECT
  91. COUNT( 1 ) AS count
  92. FROM
  93. cygx_article AS a
  94. WHERE
  95. 1 = 1`
  96. if condition != "" {
  97. sql += condition
  98. }
  99. err = o.Raw(sql).QueryRow(&count)
  100. return
  101. }
  102. func GetReoprtSearchCountHz(condition string) (count int, err error) {
  103. o := orm.NewOrm()
  104. sql := `SELECT
  105. COUNT( 1 ) AS count
  106. FROM
  107. cygx_article AS a
  108. WHERE
  109. 1 = 1`
  110. if condition != "" {
  111. sql += condition
  112. }
  113. err = o.Raw(sql).QueryRow(&count)
  114. return
  115. }
  116. // 列表
  117. func GetReoprtSearchList(condition string, userId, startSize, pageSize int) (items []*ArticleCollectionResp, err error) {
  118. o := orm.NewOrm()
  119. sql := `SELECT
  120. a.article_id,
  121. a.title,
  122. a.body,
  123. a.abstract,
  124. a.annotation,
  125. a.category_id,
  126. a.category_name,
  127. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  128. m.industry_name,
  129. m.industrial_management_id,
  130. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  131. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  132. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  133. FROM
  134. cygx_article AS a
  135. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  136. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  137. WHERE
  138. 1 = 1 `
  139. if condition != "" {
  140. sql += condition
  141. }
  142. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  143. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  144. return
  145. } //end
  146. // 列表
  147. func GetSearchResourceList(condition string) (items []*IndustrialManagement, err error) {
  148. o := orm.NewOrm()
  149. sql := `SELECT
  150. m.industry_name,
  151. m.chart_permission_id,
  152. m.industrial_management_id,
  153. MAX( a.publish_date ) as publish_date_order,
  154. MIN( a.publish_date ) AS min_report_time,
  155. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
  156. FROM
  157. cygx_industrial_management AS m
  158. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  159. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  160. WHERE
  161. 1 = 1
  162. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  163. _, err = o.Raw(sql).QueryRows(&items)
  164. return
  165. }
  166. // 标的列表
  167. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  168. o := orm.NewOrm()
  169. sql := `SELECT
  170. m.subject_name,
  171. m.industrial_management_id,
  172. m.industrial_subject_id
  173. FROM
  174. cygx_article AS a
  175. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  176. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  177. WHERE
  178. 1 = 1`
  179. if condition != "" {
  180. sql += condition
  181. }
  182. sql += ` AND publish_status = 1
  183. GROUP BY
  184. m.industrial_subject_id
  185. ORDER BY
  186. publish_date DESC`
  187. _, err = o.Raw(sql).QueryRows(&items)
  188. return
  189. } //end
  190. // 产业下所关联的文章分类列表
  191. func IndustrialToArticleCategory(industrialManagementId, chartPermissionId int) (items []*IndustrialToArticleCategoryRep, err error) {
  192. o := orm.NewOrm()
  193. sql := `SELECT map.match_type_name,map.category_id
  194. FROM cygx_report_mapping AS map
  195. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  196. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  197. WHERE map.report_type = 2
  198. AND map.is_report = 1
  199. AND art.is_report = 1
  200. AND art.publish_status = 1
  201. AND man_g.industrial_management_id =?
  202. AND map.chart_permission_id = ?
  203. GROUP BY map.match_type_name`
  204. _, err = o.Raw(sql, industrialManagementId, chartPermissionId).QueryRows(&items)
  205. return
  206. }
  207. // 判断用户是否阅读该产业下,某一分类的文章
  208. func IndustrialUserRecordArticleCount(userId, industrialManagementId, categoryId int) (count int, err error) {
  209. o := orm.NewOrm()
  210. sql := `SELECT
  211. COUNT(1) count
  212. FROM
  213. cygx_article_history_record
  214. WHERE
  215. 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 article_id < 1000000 AND category_id IN (SELECT
  216. category_id
  217. FROM
  218. cygx_report_mapping
  219. WHERE
  220. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ? )
  221. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ? ) ) ORDER BY publish_date DESC LIMIT 0, 1 )
  222. AND user_id = ? `
  223. err = o.Raw(sql, industrialManagementId, categoryId, categoryId, userId).QueryRow(&count)
  224. return
  225. }
  226. // 获取最新文章
  227. func GetNewIndustrialUserRecordArticle(industrialManagementId, categoryId int) (item *ArticleDetail, err error) {
  228. o := orm.NewOrm()
  229. 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 IN (SELECT
  230. category_id
  231. FROM
  232. cygx_report_mapping
  233. WHERE
  234. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ? )
  235. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ? ) ) ORDER BY publish_date DESC LIMIT 0, 1`
  236. err = o.Raw(sql, industrialManagementId, categoryId, categoryId).QueryRow(&item)
  237. return
  238. }
  239. // 列表
  240. func GetReoprtSearchListHz(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  241. o := orm.NewOrm()
  242. sql := `SELECT
  243. a.article_id,
  244. a.title,
  245. a.annotation,
  246. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  247. m.industry_name,
  248. m.industrial_management_id,
  249. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  250. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  251. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  252. FROM
  253. cygx_article AS a
  254. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  255. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  256. WHERE
  257. 1 = 1 `
  258. if condition != "" {
  259. sql += condition
  260. }
  261. _, err = o.Raw(sql, userId).QueryRows(&items)
  262. return
  263. } //end
  264. // 产业列表
  265. func GetSearchResourceListHz(condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  266. o := orm.NewOrm()
  267. sql := `SELECT
  268. m.industry_name,
  269. m.industrial_management_id,
  270. MAX( a.publish_date ) as publish_date_order,
  271. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
  272. FROM
  273. cygx_industrial_management AS m
  274. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  275. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  276. WHERE
  277. 1 = 1
  278. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  279. if startSize > 0 || pageSize > 0 {
  280. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  281. }
  282. _, err = o.Raw(sql).QueryRows(&items)
  283. return
  284. }
  285. // 用户收藏榜start
  286. type IndustrialManagementHotResp struct {
  287. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  288. IndustryName string `description:"产业名称"`
  289. IsFollow bool `description:"是否关注"`
  290. FllowNum int `description:"关注数量"`
  291. IsNew bool `description:"是否新标签"`
  292. IsHot bool `description:"是否新标签"`
  293. PublishDate string `description:"发布时间"`
  294. ArticleReadNum int `description:"文章阅读数量"`
  295. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  296. MinReportTime string `description:"报告最早发布时间"`
  297. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  298. }
  299. // 搜索资源包 start
  300. type SearchReportAndResourceResp struct {
  301. ListHzResource []*IndustrialManagement `description:"弘则资源包"`
  302. ListHzReport []*ArticleCollectionResp `description:"弘则报告"`
  303. Paging *paging.PagingItem `description:"弘则报告分页"`
  304. }
  305. // 报告收藏榜单列表
  306. func GetReportCollectionBillboardList(limit int, pars []interface{}, condition string) (items []*ArticleListResp, err error) {
  307. o := orm.NewOrm()
  308. sql := `SELECT
  309. ac.id,
  310. a.article_id,
  311. a.category_id,
  312. a.title,
  313. a.annotation,
  314. a.publish_date,
  315. m.chart_permission_name,
  316. COUNT(ac.id) AS collection_num
  317. FROM
  318. cygx_article AS a
  319. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id_two
  320. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  321. WHERE
  322. 1 = 1
  323. AND a.publish_status = 1 `
  324. if condition != "" {
  325. sql += condition
  326. }
  327. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, ac.id DESC, a.publish_date DESC`
  328. sql += ` LIMIT ?`
  329. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  330. return
  331. }
  332. // 研选报告收藏榜单列表
  333. func GetReportCollectionBillboardListYx(limit int, pars []interface{}, condition string) (items []*ArticleListResp, err error) {
  334. o := orm.NewOrm()
  335. sql := `SELECT
  336. ac.id,
  337. a.category_id,
  338. '买方研选' as chart_permission_name,
  339. a.article_id,
  340. a.title,
  341. a.body,
  342. a.annotation,
  343. a.abstract,
  344. a.publish_date,
  345. a.article_type_id,
  346. d.nick_name,
  347. d.department_id,
  348. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  349. ( 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,
  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 AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collection_num
  351. FROM
  352. cygx_article AS a
  353. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  354. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  355. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  356. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  357. WHERE
  358. 1 = 1
  359. AND a.publish_status = 1 `
  360. if condition != "" {
  361. sql += condition
  362. }
  363. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, a.publish_date DESC`
  364. sql += ` LIMIT ?`
  365. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  366. return
  367. }
  368. // 获取产业报告+晨会点评列表
  369. func GetTimeLineReportIndustrialList(industrialManagementId, startSize, pageSize int) (items []*ArticleListResp, total int, err error) {
  370. o := orm.NewOrm()
  371. sql := `SELECT
  372. a.id,
  373. a.article_id,
  374. a.title,
  375. a.publish_date
  376. FROM
  377. cygx_article AS a
  378. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  379. WHERE
  380. a.publish_status = 1
  381. AND a.is_class = 1
  382. AND man_g.industrial_management_id = ? GROUP BY a.article_id UNION ALL
  383. SELECT
  384. mmc.id,
  385. 0,
  386. mmc.content AS title,
  387. mm.meeting_time AS publish_data
  388. FROM
  389. cygx_morning_meeting_review_chapter AS mmc
  390. INNER JOIN cygx_morning_meeting_reviews AS mm
  391. WHERE
  392. mm.id = mmc.meeting_id
  393. AND mm.STATUS = 1
  394. AND mmc.industry_id = ? `
  395. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  396. err = o.Raw(totalSql, industrialManagementId, industrialManagementId).QueryRow(&total)
  397. sql += ` ORDER BY publish_date DESC LIMIT ?,? `
  398. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  399. return
  400. }
  401. type TimeLineReportItem struct {
  402. Id int `description:"文章或晨报点评id"`
  403. ArticleId int `description:"文章id"`
  404. Title string `description:"标题"`
  405. //PublishTime string `description:"发布时间"`
  406. PublishDate string `description:"发布时间"`
  407. Content string `description:"内容"`
  408. VideoUrl string `description:"视频链接"`
  409. IsHaveVideo bool `description:"是否包含视频"`
  410. ImgUrlPc string `description:"pc图片"`
  411. SubCategoryName string `description:"二级分类"`
  412. IsRed bool `description:"是否标红"`
  413. Readnum int `description:"阅读数量"`
  414. }
  415. // 获取产业报告+晨会点评列表
  416. func GetTimeLineReportIndustrialListTime(userId, industrialManagementId, startSize, pageSize int) (items []*TimeLineReportItem, total int, err error) {
  417. o := orm.NewOrm()
  418. sql := `SELECT
  419. *
  420. FROM
  421. (
  422. SELECT
  423. a.article_id AS id,
  424. a.article_id,
  425. a.title,
  426. a.publish_date,
  427. a.video_url,
  428. a.sub_category_name,
  429. '' AS content,
  430. ( 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
  431. FROM
  432. cygx_article AS a
  433. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  434. WHERE
  435. a.publish_status = 1
  436. AND a.is_class = 1
  437. AND man_g.industrial_management_id = ? GROUP BY id UNION ALL
  438. SELECT
  439. mmc.id,
  440. 0 as article_id,
  441. mmc.content AS title,
  442. mm.publish_time AS publish_date,
  443. '' AS video_url,
  444. '时间线' AS sub_category_name,
  445. '' AS content,
  446. 0 AS readnum
  447. FROM
  448. cygx_morning_meeting_review_chapter AS mmc
  449. INNER JOIN cygx_morning_meeting_reviews AS mm
  450. WHERE
  451. mm.id = mmc.meeting_id
  452. AND mm.STATUS = 1
  453. AND mmc.industry_id = ?
  454. ) AS t`
  455. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  456. err = o.Raw(totalSql, industrialManagementId, industrialManagementId).QueryRow(&total)
  457. sql += ` ORDER BY
  458. t.publish_date DESC LIMIT ?,? `
  459. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  460. return
  461. }
  462. // 获取产业报告+晨会点评列表
  463. func GetTimeLineReportIndustrialListRed(userId, industrialManagementId, startSize, pageSize int) (items []*TimeLineReportItem, err error) {
  464. o := orm.NewOrm()
  465. sql := `SELECT
  466. *
  467. FROM
  468. (
  469. SELECT
  470. a.article_id AS id,
  471. a.title,
  472. a.publish_date ,
  473. a.video_url,
  474. a.sub_category_name,
  475. '' AS content,
  476. ( 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
  477. FROM
  478. cygx_article AS a
  479. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  480. WHERE
  481. a.publish_status = 1
  482. AND a.is_class = 1
  483. AND man_g.industrial_management_id = ? GROUP BY id UNION ALL
  484. SELECT
  485. mmc.id,
  486. '' AS title,
  487. mm.publish_time AS publish_date,
  488. '' AS video_url,
  489. '时间线' AS sub_category_name,
  490. mmc.content,
  491. 0 AS readnum
  492. FROM
  493. cygx_morning_meeting_review_chapter AS mmc
  494. INNER JOIN cygx_morning_meeting_reviews AS mm
  495. WHERE
  496. mm.id = mmc.meeting_id
  497. AND mm.STATUS = 1
  498. AND mmc.industry_id = ?
  499. ) AS t
  500. `
  501. sql += ` ORDER BY
  502. t.publish_date DESC LIMIT ?,? `
  503. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  504. return
  505. }
  506. type IndustrialPublishdate struct {
  507. PublishDate string `description:"发布时间"`
  508. IndustrialManagementId int `description:"产业D"`
  509. }
  510. // 标的列表
  511. func GetTimeLineReportIndustrialPublishdateList(industrialIdArr []int) (items []*IndustrialPublishdate, err error) {
  512. o := orm.NewOrm()
  513. sql := `SELECT
  514. mmc.id,
  515. 0,
  516. mmc.industry_id AS industrial_management_id,
  517. mmc.content AS title,
  518. MAX( mm.meeting_time ) AS publish_date
  519. FROM
  520. cygx_morning_meeting_review_chapter AS mmc
  521. INNER JOIN cygx_morning_meeting_reviews AS mm
  522. WHERE
  523. mm.id = mmc.meeting_id
  524. AND mm.STATUS = 1
  525. AND mmc.industry_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)
  526. GROUP BY industrial_management_id ORDER BY publish_date DESC `
  527. _, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
  528. return
  529. }
  530. // 报告榜单start
  531. type ArticleReportBillboardResp struct {
  532. ArticleId int `description:"文章id"`
  533. Title string `description:"标题"`
  534. PublishDate string `description:"发布时间"`
  535. PermissionName string `description:"行业名称"`
  536. DepartmentId int `description:"作者Id"`
  537. NickName string `description:"作者昵称"`
  538. IsCollect bool `description:"本人是否收藏"`
  539. Pv int `description:"PV"`
  540. CollectNum int `description:"收藏人数"`
  541. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  542. List []*IndustrialManagementIdInt
  543. }
  544. type ArticleReportBillboardLIstPageResp struct {
  545. List []*ArticleReportBillboardResp
  546. Paging *paging.PagingItem
  547. }
  548. type ArticleResearchListResp struct {
  549. Paging *paging.PagingItem
  550. List []*ArticleResearchResp
  551. }
  552. type ArticleResearchResp struct {
  553. ArticleId int `description:"文章id"`
  554. Title string `description:"标题"`
  555. Annotation string `description:"核心观点"`
  556. Abstract string `description:"摘要"`
  557. PublishDate string `description:"发布时间"`
  558. DepartmentId int `description:"作者Id"`
  559. NickName string `description:"作者昵称"`
  560. IsCollect bool `description:"本人是否收藏"`
  561. Pv int `description:"PV"`
  562. CollectNum int `description:"收藏人数"`
  563. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  564. ArticleTypeId int `description:"文章类型ID"`
  565. ArticleTypeName string `description:"类型名称"`
  566. ButtonStyle string `description:"按钮展示样式"`
  567. ImgUrlPc string `description:"图片链接"`
  568. List []*IndustrialManagementIdInt `description:"产业列表"`
  569. ListSubject []*IndustrialSubject `description:"标的列表"`
  570. }
  571. // 获取数量
  572. func GetArticleResearchCount(condition string, pars []interface{}) (count int, err error) {
  573. o := orm.NewOrm()
  574. sqlCount := `SELECT COUNT( 1 ) AS count FROM
  575. cygx_article AS a
  576. WHERE
  577. 1 = 1 AND a.publish_status = 1` + condition
  578. err = o.Raw(sqlCount, pars).QueryRow(&count)
  579. return
  580. }
  581. func GetArticleResearchList(condition string, pars []interface{}, startSize, pageSize, userId int) (items []*ArticleListResp, err error) {
  582. o := orm.NewOrm()
  583. sql := `SELECT
  584. a.article_id,
  585. a.title,
  586. a.body,
  587. a.annotation,
  588. a.abstract,
  589. a.publish_date,
  590. a.article_type_id,
  591. d.nick_name,
  592. d.department_id,
  593. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  594. ( 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,
  595. ( 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,
  596. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  597. FROM
  598. cygx_article AS a
  599. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  600. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  601. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  602. WHERE
  603. 1 = 1 AND a.publish_status = 1 `
  604. if condition != "" {
  605. sql += condition
  606. }
  607. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  608. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  609. return
  610. }
  611. func GetArticleResearchListHz(condition string, pars []interface{}, startSize, pageSize, userId int) (items []*ArticleListResp, err error) {
  612. o := orm.NewOrm()
  613. sql := `SELECT
  614. a.article_id,
  615. a.title,
  616. a.body,
  617. a.annotation,
  618. a.abstract,
  619. a.publish_date,
  620. a.category_id,
  621. a.article_type_id,
  622. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  623. ( 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,
  624. ( 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,
  625. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  626. FROM
  627. cygx_article AS a
  628. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  629. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  630. WHERE
  631. 1 = 1 AND a.publish_status = 1 `
  632. if condition != "" {
  633. sql += condition
  634. }
  635. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  636. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  637. return
  638. }
  639. type IndustrialManagementHotListResp struct {
  640. Paging *paging.PagingItem `description:"分页数据"`
  641. List []*IndustrialManagementHotResp
  642. }
  643. // 获取数量
  644. func GetThemeHeatListCount(condition string) (count int, err error) {
  645. o := orm.NewOrm()
  646. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  647. cygx_industrial_management AS m
  648. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  649. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  650. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  651. WHERE
  652. 1 = 1 AND a.publish_status = 1 ` + condition
  653. err = o.Raw(sql).QueryRow(&count)
  654. return
  655. }
  656. // 产业列表
  657. func GetThemeHeatList(userId int, condition, conditionOrder string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  658. o := orm.NewOrm()
  659. sql := `SELECT
  660. m.industry_name,
  661. m.industrial_management_id,
  662. m.article_read_num,
  663. MAX( a.publish_date ) AS publish_date,
  664. MIN(a.publish_date) AS min_report_time,
  665. ( 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,
  666. m.yanxuan_article_read_num + m.activity_num AS sum_num
  667. FROM
  668. cygx_industrial_management AS m
  669. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  670. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  671. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  672. WHERE
  673. 1 = 1
  674. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  675. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  676. return
  677. }
  678. type GetThemeAericleListResp struct {
  679. ArticleId int `description:"文章id"`
  680. Title string `description:"标题"`
  681. PublishDate string `description:"发布时间"`
  682. SubjectName string `description:"标的名称"`
  683. IndustrialSubjectId int `description:"标的ID"`
  684. DepartmentId int `description:"作者Id"`
  685. NickName string `description:"作者昵称"`
  686. Pv int `description:"PV"`
  687. CollectNum int `description:"收藏人数"`
  688. FllowNum int `description:"关注数量"`
  689. MyCollectNum int `description:"本人是否收藏"`
  690. IsCollect bool `description:"本人是否收藏"`
  691. }
  692. // 主题详情start
  693. type GetThemeDetailResp struct {
  694. IndustrialManagementId int `description:"产业Id"`
  695. IndustryName string `description:"产业名称"`
  696. IsFollow bool `description:"是否关注"`
  697. ListSubject []*IndustrialSubject `description:"标的列表"`
  698. List []*ArticleResearchResp
  699. }
  700. // 主题详情start
  701. type GetThemeDetailListResp struct {
  702. ArticleId int `description:"文章id"`
  703. Title string `description:"标题"`
  704. PublishDate string `description:"发布时间"`
  705. SubjectName string `description:"标的名称"`
  706. IndustrialSubjectId int `description:"标的id"`
  707. DepartmentId int `description:"作者Id"`
  708. NickName string `description:"作者昵称"`
  709. Pv int `description:"PV"`
  710. CollectNum int `description:"收藏人数"`
  711. IndustrialManagementId int `description:"产业Id"`
  712. IndustryName string `description:"产业名称"`
  713. FllowNum int `description:"关注数量"`
  714. MyCollectNum int `description:"本人是否收藏"`
  715. IsCollect bool `description:"本人是否收藏"`
  716. }
  717. type GetThemeAericleListBuSubjectResp struct {
  718. SubjectName string `description:"标的名称"`
  719. List []*GetThemeAericleListResp
  720. }
  721. // 列表
  722. func GetThemeDetail(userId, industrialManagementId int, condition string) (items []*ArticleListResp, err error) {
  723. o := orm.NewOrm()
  724. sql := `SELECT
  725. a.article_id,
  726. a.title,
  727. a.body,
  728. a.annotation,
  729. a.abstract,
  730. a.publish_date,
  731. a.article_type_id,
  732. d.nick_name,
  733. d.department_id,
  734. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  735. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  736. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num
  737. FROM
  738. cygx_article AS a
  739. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  740. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  741. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  742. WHERE
  743. 1 = 1
  744. AND m.industrial_management_id = ?
  745. AND publish_status = 1 ` + condition + `
  746. ORDER BY
  747. publish_date DESC`
  748. _, err = o.Raw(sql, userId, industrialManagementId).QueryRows(&items)
  749. return
  750. } //end
  751. func GetDepartmentlistCount(condition string) (count int, err error) {
  752. o := orm.NewOrm()
  753. sql := `SELECT
  754. count(*) AS count
  755. FROM
  756. (
  757. SELECT
  758. COUNT( 1 ) AS count
  759. FROM
  760. cygx_article_department AS d
  761. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  762. WHERE
  763. 1 = 1
  764. AND a.article_type_id > 0
  765. AND publish_status = 1
  766. GROUP BY
  767. d.department_id
  768. ) c `
  769. err = o.Raw(sql).QueryRow(&count)
  770. return
  771. }
  772. type IndustrialReadNum struct {
  773. IndustrialManagementId int `description:"产业id"`
  774. Readnum int `description:"阅读次数"`
  775. }
  776. // 获取该产业下文章的用户阅读次数-小红点用
  777. func GetReportIndustrialReadNumList(userId int, industrialIds string, createtime time.Time) (items []*IndustrialReadNum, err error) {
  778. o := orm.NewOrm()
  779. sql := `SELECT a.industrial_management_id, MIN(a.readnum) AS readnum FROM (
  780. SELECT man_g.industrial_management_id,( 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
  781. FROM
  782. cygx_article AS a
  783. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  784. WHERE
  785. a.publish_status = 1
  786. AND a.is_class = 1
  787. AND man_g.industrial_management_id IN (` + industrialIds + `)
  788. AND a.publish_date > ?
  789. GROUP BY a.article_id ORDER BY publish_date DESC
  790. ) AS a GROUP BY industrial_management_id`
  791. _, err = o.Raw(sql, createtime).QueryRows(&items)
  792. return
  793. }