report.go 32 KB

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