report.go 31 KB

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