report.go 27 KB

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