report.go 30 KB

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