report.go 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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. PublishDate string `description:"发布时间"`
  20. UpdateTime string `description:"更新时间"`
  21. IsRed bool `description:"是否标记红点"`
  22. IsHot bool `description:"是否是热门"`
  23. IsFollow bool `description:"是否关注"`
  24. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  25. IsNew bool `description:"是否展示 NEW 标签"`
  26. IsShowRoadshow bool `description:"是否展示 微路演 标签"`
  27. ArticleReadNum int `description:"文章阅读数量"`
  28. ArticleId int `description:"文章id"`
  29. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  30. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  31. MinReportTime string `description:"报告最早发布时间"`
  32. TimeLineData string `description:"时间线所关联最新三篇文章的json数据"`
  33. ListTimeLine []TimeLineReportResp `description:"时间线所关联最新三篇文章列表"`
  34. IndustryVideo *MicroVideoSimpleInfo
  35. AuthInfo *UserPermissionAuthInfo
  36. }
  37. type TimeLineReportResp struct {
  38. Title string `description:"标题"`
  39. PublishDate string `description:"发布时间"`
  40. }
  41. type MicroVideoSimpleInfo struct {
  42. Id int `description:"视频ID"`
  43. Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频 、 4-系列问答视频"`
  44. Title string `description:"标题"`
  45. ResourceUrl string `description:"链接"`
  46. BackgroundImg string `description:"背景图"`
  47. PlaySeconds int `description:"音视频时长"`
  48. DetailImgUrl string `description:"产业详情页背景图"`
  49. ChartPermissionId int `description:"行业ID"`
  50. ChartPermissionName string `description:"行业名称"`
  51. }
  52. type TacticsListResp struct {
  53. Paging *paging.PagingItem
  54. MatchTypeName string `description:"匹配类型"`
  55. CategoryImgUrlPc string `description:"图片"`
  56. List []*HomeArticle
  57. }
  58. type TacticsListTimeResp struct {
  59. Paging *paging.PagingItem
  60. MatchTypeName string `description:"匹配类型"`
  61. CategoryImgUrlPc string `description:"图片"`
  62. List []*TimeLineReportItem
  63. }
  64. // 报告搜索start
  65. type ReoprtSearchResp struct {
  66. Paging *paging.PagingItem
  67. ListHz []*ArticleResearchResp `description:"弘则报告"`
  68. ListYx []*ArticleResearchResp `description:"研选报告"`
  69. }
  70. // 搜索资源包 start
  71. type SearchResourceResp struct {
  72. ListHz []*IndustrialManagement `description:"弘则"`
  73. ListYx []*IndustrialManagement `description:"研选"`
  74. }
  75. type ArticleIdReq struct {
  76. ArticleId int `description:"文章id"`
  77. PlaySeconds int `description:"播放时长"`
  78. PageRouter string `description:"页面路径"`
  79. ReportType int `description:"2本周研究汇总、3上周纪要汇总"`
  80. }
  81. // 获取列表数量
  82. func GetReoprtSearchCount(condition string) (count int, err error) {
  83. o := orm.NewOrm()
  84. sql := `SELECT
  85. COUNT( 1 ) AS count
  86. FROM
  87. cygx_article AS a
  88. WHERE
  89. 1 = 1
  90. AND a.article_id < 1000000 `
  91. if condition != "" {
  92. sql += condition
  93. }
  94. err = o.Raw(sql).QueryRow(&count)
  95. return
  96. }
  97. func GetReoprtSearchCountYx(condition string) (count int, err error) {
  98. o := orm.NewOrm()
  99. sql := `SELECT
  100. COUNT( 1 ) AS count
  101. FROM
  102. cygx_article AS a
  103. WHERE
  104. 1 = 1`
  105. if condition != "" {
  106. sql += condition
  107. }
  108. err = o.Raw(sql).QueryRow(&count)
  109. return
  110. }
  111. func GetReoprtSearchCountHz(condition string) (count int, err error) {
  112. o := orm.NewOrm()
  113. sql := `SELECT
  114. COUNT( 1 ) AS count
  115. FROM
  116. cygx_article AS a
  117. WHERE
  118. 1 = 1`
  119. if condition != "" {
  120. sql += condition
  121. }
  122. err = o.Raw(sql).QueryRow(&count)
  123. return
  124. }
  125. // 列表
  126. func GetReoprtSearchList(condition string, userId, startSize, pageSize int) (items []*ArticleCollectionResp, err error) {
  127. o := orm.NewOrm()
  128. sql := `SELECT
  129. a.article_id,
  130. a.title,
  131. a.body,
  132. a.abstract,
  133. a.annotation,
  134. a.category_id,
  135. a.category_name,
  136. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  137. m.industry_name,
  138. m.industrial_management_id,
  139. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  140. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  141. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  142. FROM
  143. cygx_article AS a
  144. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  145. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  146. WHERE
  147. 1 = 1 `
  148. if condition != "" {
  149. sql += condition
  150. }
  151. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  152. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  153. return
  154. } //end
  155. // 获取行业报告列表
  156. func GetReportAndproductIndustrylList(categoryId, startSize, pageSize int) (items []*HomeArticle, total int, err error) {
  157. o := orm.NewOrm()
  158. sql := `SELECT
  159. art.article_id,
  160. art.title,
  161. art.publish_date,
  162. 1 AS resource
  163. FROM
  164. cygx_article AS art
  165. WHERE
  166. art.publish_status = 1
  167. AND art.article_id IN ( SELECT article_id FROM cygx_report_mapping_category_group WHERE id_cygx = ` + strconv.Itoa(categoryId) + ` ) UNION ALL
  168. SELECT
  169. art.product_interior_id AS article_id,
  170. art.title,
  171. art.publish_time AS publish_date,
  172. 2 AS resource
  173. FROM
  174. cygx_product_interior AS art
  175. WHERE
  176. art.STATUS = 1
  177. AND art.visible_range = 1
  178. AND art.match_type_id = ` + strconv.Itoa(categoryId)
  179. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  180. err = o.Raw(totalSql).QueryRow(&total)
  181. sql += ` ORDER BY publish_date DESC LIMIT ?,? `
  182. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  183. return
  184. }
  185. // 获取行业报告列表
  186. func GetReportAndproductIndustrylListimg(categoryId, userId, startSize, pageSize int) (items []*ArticleListResp, total int, err error) {
  187. o := orm.NewOrm()
  188. sql := `SELECT
  189. art.article_id,
  190. art.report_id,
  191. art.body,
  192. art.annotation,
  193. art.abstract,
  194. art.category_id,
  195. art.title,
  196. art.publish_date,
  197. 1 AS resource ,
  198. ( SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id = art.article_id ) AS readnum
  199. FROM
  200. cygx_article AS art
  201. WHERE
  202. art.publish_status = 1
  203. AND art.article_id IN ( SELECT article_id FROM cygx_report_mapping_category_group WHERE id_cygx = ` + strconv.Itoa(categoryId) + ` )
  204. UNION ALL
  205. SELECT
  206. art.product_interior_id AS article_id,
  207. 0 AS report_id,
  208. art.body,
  209. "",
  210. art.abstract,
  211. 0 as category_id,
  212. art.title,
  213. art.publish_time AS publish_date,
  214. 2 AS resource ,
  215. ( SELECT COUNT( 1 ) FROM cygx_product_interior_history AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.product_interior_id = art.product_interior_id ) AS readnum
  216. FROM
  217. cygx_product_interior AS art
  218. WHERE
  219. art.STATUS = 1
  220. AND art.visible_range = 1
  221. AND art.match_type_id = ` + strconv.Itoa(categoryId)
  222. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  223. err = o.Raw(totalSql).QueryRow(&total)
  224. sql += ` ORDER BY publish_date DESC LIMIT ?,? `
  225. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  226. return
  227. }
  228. // 列表
  229. func GetSearchResourceList(condition string) (items []*IndustrialManagement, err error) {
  230. o := orm.NewOrm()
  231. sql := `SELECT
  232. m.time_line_data,
  233. m.industry_name,
  234. m.chart_permission_id,
  235. m.industrial_management_id,
  236. MAX( a.publish_date ) as publish_date_order,
  237. MIN( a.publish_date ) AS min_report_time,
  238. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
  239. FROM
  240. cygx_industrial_management AS m
  241. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  242. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  243. WHERE
  244. 1 = 1
  245. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  246. _, err = o.Raw(sql).QueryRows(&items)
  247. return
  248. }
  249. // 标的列表
  250. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  251. o := orm.NewOrm()
  252. sql := `SELECT
  253. m.subject_name,
  254. m.industrial_management_id,
  255. m.industrial_subject_id
  256. FROM
  257. cygx_article AS a
  258. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  259. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  260. WHERE
  261. 1 = 1`
  262. if condition != "" {
  263. sql += condition
  264. }
  265. sql += ` AND publish_status = 1
  266. GROUP BY
  267. m.industrial_subject_id
  268. ORDER BY
  269. publish_date DESC`
  270. _, err = o.Raw(sql).QueryRows(&items)
  271. return
  272. } //end
  273. // 产业下所关联的文章分类列表
  274. func IndustrialToArticleCategory(industrialManagementId, chartPermissionId int) (items []*IndustrialToArticleCategoryRep, err error) {
  275. o := orm.NewOrm()
  276. sql := `SELECT map.match_type_name,map.category_id
  277. FROM cygx_report_mapping AS map
  278. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  279. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  280. WHERE map.report_type = 2
  281. AND map.is_report = 1
  282. AND art.is_report = 1
  283. AND art.publish_status = 1
  284. AND man_g.industrial_management_id =?
  285. AND map.chart_permission_id = ?
  286. GROUP BY map.match_type_name`
  287. _, err = o.Raw(sql, industrialManagementId, chartPermissionId).QueryRows(&items)
  288. return
  289. }
  290. // 产业下所关联的文章、产品内测分类列表 2023-04-14
  291. func IndustrialToArticleAndProductInteriorCategoryNew(industrialManagementId int) (items []*IndustrialToArticleCategoryRep, err error) {
  292. o := orm.NewOrm()
  293. sql := `SELECT
  294. map.match_type_name,
  295. map.sort,
  296. map.id,
  297. map.id AS category_id
  298. FROM
  299. cygx_report_mapping_cygx AS map
  300. INNER JOIN cygx_report_mapping_group AS g ON g.id_cygx = map.id
  301. INNER JOIN cygx_report_mapping_celue AS cl ON cl.category_id = g.category_id_celue
  302. INNER JOIN cygx_article AS art ON art.category_id = cl.category_id
  303. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  304. WHERE
  305. 1 = 1
  306. AND map.report_type = 2
  307. AND map.is_report = 1
  308. AND art.is_report = 1
  309. AND art.publish_status = 1
  310. AND man_g.industrial_management_id = ?
  311. GROUP BY
  312. map.match_type_name UNION ALL
  313. SELECT
  314. map.match_type_name,
  315. map.sort,
  316. map.id,
  317. map.id AS category_id
  318. FROM
  319. cygx_report_mapping_cygx AS map
  320. INNER JOIN cygx_industrial_management AS im ON im.chart_permission_id = map.chart_permission_id
  321. INNER JOIN cygx_product_interior AS art ON art.match_type_id = map.id
  322. INNER JOIN cygx_product_interior_industrial_group_management AS man_g ON man_g.product_interior_id = art.product_interior_id
  323. WHERE
  324. 1 = 1
  325. AND art.STATUS = 1
  326. AND art.visible_range = 1
  327. AND man_g.industrial_management_id = ?
  328. GROUP BY
  329. map.match_type_name ORDER BY id ASC , sort DESC `
  330. _, err = o.Raw(sql, industrialManagementId, industrialManagementId).QueryRows(&items)
  331. return
  332. }
  333. // 获取产业报告列表
  334. func GetReportAndproductInteriorIndustrialList(pars []interface{}, categoryId, industrialManagementId, userId, startSize, pageSize int) (items []*ArticleListResp, total int, err error) {
  335. o := orm.NewOrm()
  336. sql := `SELECT
  337. art.article_id,
  338. art.body,
  339. art.annotation,
  340. art.abstract,
  341. art.category_id,
  342. art.title,
  343. art.publish_date,
  344. ( SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id = art.article_id ) AS readnum ,
  345. 1 AS resource
  346. FROM
  347. cygx_article AS art
  348. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  349. WHERE
  350. art.publish_status = 1
  351. AND art.article_id IN ( SELECT article_id FROM cygx_report_mapping_category_group WHERE id_cygx = ` + strconv.Itoa(categoryId) + ` )
  352. AND art.is_class = 1
  353. AND man_g.industrial_management_id =` + strconv.Itoa(industrialManagementId) + `
  354. GROUP BY
  355. art.article_id UNION ALL
  356. SELECT
  357. art.product_interior_id AS article_id,
  358. art.body,
  359. "",
  360. art.abstract,
  361. 0 as category_id,
  362. art.title,
  363. art.publish_time AS publish_date,
  364. ( SELECT COUNT( 1 ) FROM cygx_product_interior_history AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.product_interior_id = art.product_interior_id ) AS readnum ,
  365. 2 AS resource
  366. FROM
  367. cygx_product_interior AS art
  368. INNER JOIN cygx_product_interior_industrial_group_management AS man_g ON man_g.product_interior_id = art.product_interior_id
  369. WHERE
  370. art.STATUS = 1
  371. AND art.visible_range = 1
  372. AND art.match_type_id = ` + strconv.Itoa(categoryId) + `
  373. AND man_g.industrial_management_id = ` + strconv.Itoa(industrialManagementId) + `
  374. GROUP BY
  375. art.product_interior_id `
  376. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  377. err = o.Raw(totalSql, pars).QueryRow(&total)
  378. sql += ` ORDER BY publish_date DESC LIMIT ?,? `
  379. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  380. return
  381. }
  382. // 判断用户是否阅读该产业下,某一分类的文章
  383. func IndustrialUserRecordArticleCount(userId, industrialManagementId, categoryId int) (count int, err error) {
  384. o := orm.NewOrm()
  385. sql := `SELECT
  386. COUNT(1) count
  387. FROM
  388. cygx_article_history_record
  389. WHERE
  390. article_id = ( SELECT article_id FROM cygx_article WHERE article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id = ? ) AND article_id < 1000000 AND category_id IN (SELECT
  391. category_id
  392. FROM
  393. cygx_report_mapping
  394. WHERE
  395. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ? )
  396. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ? ) ) ORDER BY publish_date DESC LIMIT 0, 1 )
  397. AND user_id = ? `
  398. err = o.Raw(sql, industrialManagementId, categoryId, categoryId, userId).QueryRow(&count)
  399. return
  400. }
  401. // 获取最新文章
  402. func GetNewIndustrialUserRecordArticle(industrialManagementId, categoryId int) (item *ArticleDetail, err error) {
  403. o := orm.NewOrm()
  404. 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
  405. category_id
  406. FROM
  407. cygx_report_mapping
  408. WHERE
  409. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ? )
  410. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ? ) ) ORDER BY publish_date DESC LIMIT 0, 1`
  411. err = o.Raw(sql, industrialManagementId, categoryId, categoryId).QueryRow(&item)
  412. return
  413. }
  414. // 列表
  415. func GetReoprtSearchListHz(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  416. o := orm.NewOrm()
  417. sql := `SELECT
  418. a.article_id,
  419. a.title,
  420. a.annotation,
  421. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  422. m.industry_name,
  423. m.industrial_management_id,
  424. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  425. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  426. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  427. FROM
  428. cygx_article AS a
  429. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  430. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  431. WHERE
  432. 1 = 1 `
  433. if condition != "" {
  434. sql += condition
  435. }
  436. _, err = o.Raw(sql, userId).QueryRows(&items)
  437. return
  438. } //end
  439. // 产业列表
  440. func GetSearchResourceListHz(condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  441. o := orm.NewOrm()
  442. sql := `SELECT
  443. m.industry_name,
  444. m.industrial_management_id,
  445. MAX( a.publish_date ) as publish_date_order,
  446. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
  447. FROM
  448. cygx_industrial_management AS m
  449. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  450. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  451. WHERE
  452. 1 = 1
  453. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  454. if startSize > 0 || pageSize > 0 {
  455. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  456. }
  457. _, err = o.Raw(sql).QueryRows(&items)
  458. return
  459. }
  460. // 用户收藏榜start
  461. type IndustrialManagementHotResp struct {
  462. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  463. IndustryName string `description:"产业名称"`
  464. IsFollow bool `description:"是否关注"`
  465. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  466. FllowNum int `description:"关注数量"`
  467. IsNew bool `description:"是否新标签"`
  468. IsHot bool `description:"是否新标签"`
  469. PublishDate string `description:"发布时间"`
  470. ArticleReadNum int `description:"文章阅读数量"`
  471. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  472. MinReportTime string `description:"报告最早发布时间"`
  473. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  474. }
  475. // 搜索资源包 start
  476. type SearchReportAndResourceResp struct {
  477. ListHzResource []*IndustrialManagement `description:"弘则资源包"`
  478. ListHzReport []*ArticleCollectionResp `description:"弘则报告"`
  479. Paging *paging.PagingItem `description:"弘则报告分页"`
  480. }
  481. // 报告收藏榜单列表
  482. func GetReportCollectionBillboardList(limit int, pars []interface{}, condition string) (items []*ArticleListResp, err error) {
  483. o := orm.NewOrm()
  484. sql := `SELECT
  485. ac.id,
  486. a.article_id,
  487. a.category_id,
  488. a.title,
  489. a.annotation,
  490. a.publish_date,
  491. a.article_type_id,
  492. m.chart_permission_name,
  493. COUNT(ac.id) AS collection_num
  494. FROM
  495. cygx_article AS a
  496. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id_two
  497. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  498. WHERE
  499. 1 = 1
  500. AND a.publish_status = 1 `
  501. if condition != "" {
  502. sql += condition
  503. }
  504. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, ac.id DESC, a.publish_date DESC`
  505. sql += ` LIMIT ?`
  506. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  507. return
  508. }
  509. // 研选报告收藏榜单列表
  510. func GetReportCollectionBillboardListYx(limit int, pars []interface{}, condition string) (items []*ArticleListResp, err error) {
  511. o := orm.NewOrm()
  512. sql := `SELECT
  513. ac.id,
  514. a.category_id,
  515. '买方研选' as chart_permission_name,
  516. a.article_id,
  517. a.title,
  518. a.body,
  519. a.annotation,
  520. a.abstract,
  521. a.publish_date,
  522. a.article_type_id,
  523. d.nick_name,
  524. d.department_id,
  525. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  526. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  527. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collection_num
  528. FROM
  529. cygx_article AS a
  530. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  531. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  532. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  533. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  534. WHERE
  535. 1 = 1
  536. AND a.publish_status = 1 `
  537. if condition != "" {
  538. sql += condition
  539. }
  540. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, a.publish_date DESC`
  541. sql += ` LIMIT ?`
  542. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  543. return
  544. }
  545. // 获取产业报告+晨会点评列表
  546. func GetTimeLineReportIndustrialList(industrialManagementId, startSize, pageSize int) (items []*ArticleListResp, total int, err error) {
  547. o := orm.NewOrm()
  548. sql := `SELECT
  549. a.id,
  550. a.article_id,
  551. a.title,
  552. a.publish_date
  553. FROM
  554. cygx_article AS a
  555. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  556. WHERE
  557. a.publish_status = 1
  558. AND a.is_class = 1
  559. AND man_g.industrial_management_id = ? GROUP BY a.article_id UNION ALL
  560. SELECT
  561. mmc.id,
  562. 0,
  563. mmc.content AS title,
  564. mm.meeting_time AS publish_data
  565. FROM
  566. cygx_morning_meeting_review_chapter AS mmc
  567. INNER JOIN cygx_morning_meeting_reviews AS mm
  568. WHERE
  569. mm.id = mmc.meeting_id
  570. AND mm.STATUS = 1
  571. AND mmc.industry_id = ? `
  572. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  573. err = o.Raw(totalSql, industrialManagementId, industrialManagementId).QueryRow(&total)
  574. sql += ` ORDER BY publish_date DESC LIMIT ?,? `
  575. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  576. return
  577. }
  578. type TimeLineReportItem struct {
  579. Id int `description:"文章或晨报点评id"`
  580. ArticleId int `description:"文章id"`
  581. Title string `description:"标题"`
  582. //PublishTime string `description:"发布时间"`
  583. PublishDate string `description:"发布时间"`
  584. Content string `description:"内容"`
  585. VideoUrl string `description:"视频链接"`
  586. VoiceUrl string `description:"音频链接"`
  587. IsHaveVideo bool `description:"是否包含视频"`
  588. ImgUrlPc string `description:"pc图片"`
  589. SubCategoryName string `description:"二级分类"`
  590. IsRed bool `description:"是否标红"`
  591. Readnum int `description:"阅读数量"`
  592. Resource int `description:"来源类型,1:文章、2:产品内测、3:晨报点评 4:活动回放视频 5:活动回放音频 "`
  593. Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频 、 4-系列问答视频"`
  594. LinkArticleId int `description:"晨会精华报告ID链接"`
  595. ListSubject []*CygxIndustrialSubject `description:"标的列表"`
  596. }
  597. // 获取产业报告+晨会点评列表
  598. func GetTimeLineReportIndustrialListTime(userId, industrialManagementId, startSize, pageSize int) (items []*TimeLineReportItem, total int, err error) {
  599. o := orm.NewOrm()
  600. sql := `SELECT
  601. *
  602. FROM
  603. (
  604. SELECT
  605. a.article_id AS id,
  606. a.article_id,
  607. a.title,
  608. a.publish_date,
  609. a.video_url,
  610. '' AS mi,
  611. a.sub_category_name,
  612. '' AS content,
  613. 1 AS resource,
  614. 0 AS type,
  615. ( 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
  616. FROM
  617. cygx_article AS a
  618. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  619. WHERE
  620. a.publish_status = 1
  621. AND a.is_class = 1
  622. AND man_g.industrial_management_id = ? GROUP BY id UNION ALL
  623. SELECT
  624. mmc.id,
  625. 0 as article_id,
  626. mmc.title,
  627. mm.publish_time AS publish_date,
  628. '' AS video_url,
  629. '' AS voice_url,
  630. '时间线' AS sub_category_name,
  631. mmc.content,
  632. 3 AS resource,
  633. 0 AS type,
  634. 0 AS readnum
  635. FROM
  636. cygx_morning_meeting_review_chapter AS mmc
  637. INNER JOIN cygx_morning_meeting_reviews AS mm
  638. WHERE
  639. mm.id = mmc.meeting_id
  640. AND mm.STATUS = 1
  641. AND mmc.industry_id = ? UNION ALL
  642. SELECT
  643. p.product_interior_id AS id,
  644. p.product_interior_id as article_id,
  645. p.title,
  646. p.publish_time AS publish_date,
  647. '' AS video_url,
  648. '' AS voice_url,
  649. '' AS sub_category_name,
  650. '' AS content,
  651. 2 AS resource,
  652. 0 AS type,
  653. 0 AS readnum
  654. FROM
  655. cygx_product_interior AS p
  656. INNER JOIN cygx_product_interior_industrial_group_management AS pm
  657. WHERE
  658. p.product_interior_id = pm.product_interior_id
  659. AND p.visible_range = 1
  660. AND pm.industrial_management_id = ? UNION ALL
  661. SELECT
  662. cav.video_id AS id,
  663. 0 as article_id,
  664. cav.video_name AS title,
  665. ca.activity_time AS publish_time,
  666. cav.video_url AS video_url,
  667. '' AS voice_url,
  668. '' AS sub_category_name,
  669. '' AS content,
  670. 4 AS resource,
  671. 2 AS type,
  672. ( SELECT COUNT( 1 ) FROM cygx_activity_video_history AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.activity_id = ca.activity_id ) AS readnum
  673. FROM
  674. cygx_activity AS ca
  675. INNER JOIN cygx_activity_video AS cav ON ca.activity_id = cav.activity_id
  676. INNER JOIN cygx_industrial_activity_group_management AS cam ON ca.activity_id=cam.activity_id
  677. WHERE
  678. cam.industrial_management_id = ? AND cam.source = 1 UNION ALL
  679. SELECT
  680. ca.activity_id AS id,
  681. 0 as article_id,
  682. cavo.voice_name AS title,
  683. ca.activity_time AS publish_time,
  684. '' AS video_url,
  685. cavo.voice_url AS voice_url,
  686. '' AS sub_category_name,
  687. '' AS content,
  688. 5 AS resource,
  689. 1 AS type,
  690. ( SELECT COUNT( 1 ) FROM cygx_activity_voice_history AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.activity_id = ca.activity_id ) AS readnum
  691. FROM
  692. cygx_activity AS ca
  693. INNER JOIN cygx_activity_voice AS cavo ON ca.activity_id = cavo.activity_id
  694. INNER JOIN cygx_industrial_activity_group_management AS cam ON ca.activity_id=cam.activity_id
  695. WHERE
  696. cam.industrial_management_id = ? AND cam.source = 1
  697. ) AS t`
  698. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  699. err = o.Raw(totalSql, industrialManagementId, industrialManagementId, industrialManagementId, industrialManagementId, industrialManagementId).QueryRow(&total)
  700. sql += ` ORDER BY
  701. t.publish_date DESC LIMIT ?,? `
  702. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, industrialManagementId, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  703. return
  704. }
  705. // 获取产业报告+晨会点评列表
  706. func GetTimeLineReportIndustrialListRed(userId, industrialManagementId, startSize, pageSize int) (items []*TimeLineReportItem, err error) {
  707. o := orm.NewOrm()
  708. sql := `SELECT
  709. *
  710. FROM
  711. (
  712. SELECT
  713. a.article_id AS id,
  714. a.title,
  715. a.publish_date ,
  716. a.video_url,
  717. a.sub_category_name,
  718. '' AS content,
  719. ( 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
  720. FROM
  721. cygx_article AS a
  722. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  723. WHERE
  724. a.publish_status = 1
  725. AND a.is_class = 1
  726. AND man_g.industrial_management_id = ? GROUP BY id UNION ALL
  727. SELECT
  728. mmc.id,
  729. '' AS title,
  730. mm.publish_time AS publish_date,
  731. '' AS video_url,
  732. '时间线' AS sub_category_name,
  733. mmc.content,
  734. 0 AS readnum
  735. FROM
  736. cygx_morning_meeting_review_chapter AS mmc
  737. INNER JOIN cygx_morning_meeting_reviews AS mm
  738. WHERE
  739. mm.id = mmc.meeting_id
  740. AND mm.STATUS = 1
  741. AND mmc.industry_id = ?
  742. ) AS t
  743. `
  744. sql += ` ORDER BY
  745. t.publish_date DESC LIMIT ?,? `
  746. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  747. return
  748. }
  749. type IndustrialPublishdate struct {
  750. PublishDate string `description:"发布时间"`
  751. IndustrialManagementId int `description:"产业D"`
  752. }
  753. // 标的列表
  754. func GetTimeLineReportIndustrialPublishdateList(industrialIdArr []int) (items []*IndustrialPublishdate, err error) {
  755. o := orm.NewOrm()
  756. sql := `SELECT
  757. mmc.id,
  758. 0,
  759. mmc.industry_id AS industrial_management_id,
  760. mmc.content AS title,
  761. MAX( mm.meeting_time ) AS publish_date
  762. FROM
  763. cygx_morning_meeting_review_chapter AS mmc
  764. INNER JOIN cygx_morning_meeting_reviews AS mm
  765. WHERE
  766. mm.id = mmc.meeting_id
  767. AND mm.STATUS = 1
  768. AND mmc.industry_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)
  769. GROUP BY industrial_management_id ORDER BY publish_date DESC `
  770. _, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
  771. return
  772. }
  773. // 报告榜单start
  774. type ArticleReportBillboardResp struct {
  775. ArticleId int `description:"文章id"`
  776. Title string `description:"标题"`
  777. PublishDate string `description:"发布时间"`
  778. PermissionName string `description:"行业名称"`
  779. DepartmentId int `description:"作者Id"`
  780. NickName string `description:"作者昵称"`
  781. IsCollect bool `description:"本人是否收藏"`
  782. Pv int `description:"PV"`
  783. CollectNum int `description:"收藏人数"`
  784. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  785. ArticleTypeId int `description:"文章类型ID判断是否是研选使用"`
  786. IsResearch bool `description:"是否属于研选"`
  787. ArticleTypeName string `description:"文章类型名称"`
  788. IsSpecial bool `description:"是否为研选专栏"`
  789. IsSpecialInt int `description:"是否为研选专栏"`
  790. SpecialTags string `description:"研选专栏标签"`
  791. MyCollectNum int `description:"本人是否收藏"`
  792. SpecialType int `description:"专栏类型 1:笔记,2:观点"`
  793. UserId int `description:"作者id"`
  794. IndustryTagStr string `description:"研选专栏行业标签"`
  795. CompanyTagsStr string `description:"研选专栏公司标签"`
  796. IndustryTags []string `description:"研选专栏行业标签"`
  797. CompanyTags []string `description:"研选专栏公司标签"`
  798. SpecialColumnId int `description:"专栏栏目id"`
  799. List []*IndustrialManagementIdInt
  800. }
  801. type ArticleReportBillboardLIstPageResp struct {
  802. List []*ArticleReportBillboardResp
  803. Paging *paging.PagingItem
  804. }
  805. type ArticleResearchListResp struct {
  806. Paging *paging.PagingItem
  807. List []*ArticleResearchResp
  808. }
  809. type ArticleResearchResp struct {
  810. ArticleId int `description:"文章id"`
  811. Title string `description:"标题"`
  812. Annotation string `description:"核心观点"`
  813. Abstract string `description:"摘要"`
  814. PublishDate string `description:"发布时间"`
  815. DepartmentId int `description:"作者Id"`
  816. NickName string `description:"作者昵称"`
  817. IsCollect bool `description:"本人是否收藏"`
  818. Pv int `description:"PV"`
  819. CollectNum int `description:"收藏人数"`
  820. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  821. ArticleTypeId int `description:"文章类型ID"`
  822. ArticleTypeName string `description:"类型名称"`
  823. ButtonStyle string `description:"按钮展示样式"`
  824. ImgUrlPc string `description:"图片链接"`
  825. List []*IndustrialManagementIdInt `description:"产业列表"`
  826. ListSubject []*IndustrialSubject `description:"标的列表"`
  827. IsSpecial bool `description:"是否为研选专栏"`
  828. IndustryTags []string `description:"研选专栏行业标签"`
  829. CompanyTags []string `description:"研选专栏公司标签"`
  830. SpecialColumnId int `description:"专栏栏目id"`
  831. TopTime int `description:"置顶时间"`
  832. Resource int `description:"来源类型,1:文章、2:产品内测、3:FICC研报"`
  833. ResourceObj string `description:"articleficc:FICC研报、articlevmp:上海策略平台报告、articleyx:研选报告、articlespecial:研选专栏"`
  834. ReportId int `description:"FICC研报ID"`
  835. }
  836. // 获取数量
  837. func GetArticleResearchCount(condition string, pars []interface{}, needYanxuanSpecial bool) (count int, err error) {
  838. o := orm.NewOrm()
  839. sqlCount := `SELECT COUNT( 1 ) AS count FROM
  840. cygx_article AS a
  841. WHERE
  842. 1 = 1 AND a.publish_status = 1` + condition
  843. if needYanxuanSpecial {
  844. sqlCount = `SELECT SUM(count) AS count FROM (` + sqlCount + `
  845. UNION ALL
  846. SELECT COUNT( 1 ) AS count FROM
  847. cygx_yanxuan_special AS a WHERE
  848. 1 = 1 AND a.status = 3) AS c`
  849. }
  850. err = o.Raw(sqlCount, pars).QueryRow(&count)
  851. return
  852. }
  853. func GetArticleResearchList(condition string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (items []*ArticleListResp, err error) {
  854. o := orm.NewOrm()
  855. sql := `SELECT
  856. a.article_id,
  857. a.title,
  858. a.body,
  859. a.annotation,
  860. a.abstract,
  861. a.publish_date,
  862. a.article_type_id,
  863. d.nick_name,
  864. d.department_id,
  865. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  866. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  867. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  868. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num,
  869. 0 AS is_special,
  870. 0 AS special_type,
  871. 0 AS special_column_id,
  872. '' AS company_tags,
  873. '' AS industry_tags,
  874. a.top_time
  875. FROM
  876. cygx_article AS a
  877. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  878. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  879. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  880. WHERE
  881. 1 = 1 AND a.publish_status = 1 `
  882. if condition != "" {
  883. sql += condition
  884. }
  885. if needYanxuanSpecial {
  886. sql += `UNION ALL
  887. SELECT
  888. a.id AS article_id,
  889. a.title AS title,
  890. '' AS body,
  891. a.content AS annotation,
  892. '' AS abstract,
  893. a.publish_time AS publish_date,
  894. -1 AS article_type_id,
  895. b.nick_name AS nick_name,
  896. 0 AS department_id,
  897. ( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
  898. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  899. 0 AS collect_num_order,
  900. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num,
  901. 1 AS is_special,
  902. a.type AS special_type,
  903. b.id AS special_column_id,
  904. a.company_tags AS company_tags,
  905. a.industry_tags AS industry_tags,
  906. 0 as top_time
  907. FROM
  908. cygx_yanxuan_special AS a
  909. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  910. WHERE
  911. 1 = 1 AND a.status = 3 `
  912. sql += ` GROUP BY article_id ORDER BY top_time DESC , publish_date DESC LIMIT ?,? `
  913. _, err = o.Raw(sql, userId, userId, pars, startSize, pageSize).QueryRows(&items)
  914. } else {
  915. sql += ` GROUP BY a.article_id ORDER BY top_time DESC , a.publish_date DESC LIMIT ?,? `
  916. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  917. }
  918. return
  919. }
  920. func GetArticleResearchListYx(condition string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (items []*ArticleListResp, err error) {
  921. o := orm.NewOrm()
  922. sql := `SELECT
  923. a.article_id,
  924. a.title,
  925. a.body,
  926. a.annotation,
  927. a.abstract,
  928. a.publish_date,
  929. a.article_type_id,
  930. d.nick_name,
  931. d.department_id,
  932. 0 AS is_special,
  933. 0 as pv,
  934. 0 as collect_num,
  935. 0 AS special_type,
  936. 0 AS special_column_id,
  937. '' AS company_tags,
  938. '' AS industry_tags,
  939. a.top_time
  940. FROM
  941. cygx_article AS a
  942. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  943. WHERE
  944. 1 = 1 AND a.publish_status = 1 `
  945. if condition != "" {
  946. sql += condition
  947. }
  948. if needYanxuanSpecial {
  949. sql += `UNION ALL
  950. SELECT
  951. a.id AS article_id,
  952. a.title AS title,
  953. '' AS body,
  954. a.content AS annotation,
  955. '' AS abstract,
  956. a.publish_time AS publish_date,
  957. -1 AS article_type_id,
  958. b.nick_name AS nick_name,
  959. 0 AS department_id,
  960. 1 AS is_special,
  961. a.pv,
  962. a.article_collect_num as collect_num,
  963. a.type AS special_type,
  964. b.id AS special_column_id,
  965. a.company_tags AS company_tags,
  966. a.industry_tags AS industry_tags,
  967. 0 as top_time
  968. FROM
  969. cygx_yanxuan_special AS a
  970. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  971. WHERE
  972. 1 = 1 AND a.status = 3 `
  973. }
  974. sql += ` GROUP BY article_id ORDER BY top_time DESC , publish_date DESC LIMIT ?,? `
  975. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  976. return
  977. }
  978. func GetArticleResearchAndYxSpecialList(condition, conditionYxSpecial string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (total int, items []*ArticleListResp, err error) {
  979. o := orm.NewOrm()
  980. sql := `SELECT
  981. a.category_id,
  982. a.article_id,
  983. a.title,
  984. a.body,
  985. a.annotation,
  986. a.abstract,
  987. a.publish_date,
  988. a.article_type_id,
  989. d.nick_name,
  990. d.department_id,
  991. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  992. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  993. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  994. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num,
  995. 0 AS is_special,
  996. 0 AS special_type,
  997. 0 AS special_column_id,
  998. '' AS company_tags,
  999. '' AS industry_tags
  1000. FROM
  1001. cygx_article AS a
  1002. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  1003. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  1004. LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
  1005. WHERE
  1006. 1 = 1 AND a.publish_status = 1 `
  1007. if condition != "" {
  1008. sql += condition + " GROUP BY article_id "
  1009. }
  1010. if needYanxuanSpecial {
  1011. sql += `UNION ALL
  1012. SELECT
  1013. 0 as category_id,
  1014. a.id AS article_id,
  1015. a.title AS title,
  1016. '' AS body,
  1017. a.content AS annotation,
  1018. '' AS abstract,
  1019. a.publish_time AS publish_date,
  1020. -1 AS article_type_id,
  1021. b.nick_name AS nick_name,
  1022. 0 AS department_id,
  1023. ( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
  1024. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  1025. 0 AS collect_num_order,
  1026. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num,
  1027. 1 AS is_special,
  1028. a.type AS special_type,
  1029. b.id AS special_column_id,
  1030. a.company_tags AS company_tags,
  1031. a.industry_tags AS industry_tags
  1032. FROM
  1033. cygx_yanxuan_special AS a
  1034. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  1035. WHERE
  1036. 1 = 1 AND a.status = 3 ` + conditionYxSpecial
  1037. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1038. err = o.Raw(totalSql, userId, userId, pars).QueryRow(&total)
  1039. sql += ` GROUP BY article_id ORDER BY publish_date DESC LIMIT ?,? `
  1040. _, err = o.Raw(sql, userId, userId, pars, startSize, pageSize).QueryRows(&items)
  1041. } else {
  1042. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  1043. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  1044. }
  1045. return
  1046. }
  1047. func GetArticleResearchListHz(condition string, pars []interface{}, startSize, pageSize, userId int) (items []*ArticleListResp, err error) {
  1048. o := orm.NewOrm()
  1049. sql := `SELECT
  1050. a.article_id,
  1051. a.report_id,
  1052. a.title,
  1053. a.body,
  1054. a.annotation,
  1055. a.abstract,
  1056. a.publish_date,
  1057. a.category_id,
  1058. a.article_type_id,
  1059. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  1060. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  1061. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  1062. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  1063. FROM
  1064. cygx_article AS a
  1065. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  1066. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  1067. WHERE
  1068. 1 = 1 AND a.publish_status = 1 `
  1069. if condition != "" {
  1070. sql += condition
  1071. }
  1072. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  1073. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  1074. return
  1075. }
  1076. type IndustrialManagementHotListResp struct {
  1077. Paging *paging.PagingItem `description:"分页数据"`
  1078. List []*IndustrialManagementHotResp
  1079. }
  1080. // 获取数量
  1081. func GetThemeHeatListCount(condition string) (count int, err error) {
  1082. o := orm.NewOrm()
  1083. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  1084. cygx_industrial_management AS m
  1085. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  1086. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  1087. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  1088. WHERE
  1089. 1 = 1 AND a.publish_status = 1 ` + condition
  1090. err = o.Raw(sql).QueryRow(&count)
  1091. return
  1092. }
  1093. // 产业列表
  1094. func GetThemeHeatList(userId int, condition, conditionOrder string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  1095. o := orm.NewOrm()
  1096. sql := `SELECT
  1097. m.industry_name,
  1098. m.industrial_management_id,
  1099. m.article_read_num,
  1100. MAX( a.publish_date ) AS publish_date,
  1101. MIN(a.publish_date) AS min_report_time,
  1102. IFNULL( f.follow_type_order, 0 ) AS follow_type_order,
  1103. ( 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,
  1104. m.yanxuan_article_read_num + m.activity_num AS sum_num
  1105. FROM
  1106. cygx_industrial_management AS m
  1107. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  1108. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  1109. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  1110. LEFT JOIN cygx_industry_fllow AS f ON f.industrial_management_id = m.industrial_management_id AND f.user_id = ?
  1111. WHERE
  1112. 1 = 1
  1113. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  1114. _, err = o.Raw(sql, userId, userId, startSize, pageSize).QueryRows(&items)
  1115. return
  1116. }
  1117. type GetThemeAericleListResp struct {
  1118. ArticleId int `description:"文章id"`
  1119. Title string `description:"标题"`
  1120. PublishDate string `description:"发布时间"`
  1121. SubjectName string `description:"标的名称"`
  1122. IndustrialSubjectId int `description:"标的ID"`
  1123. DepartmentId int `description:"作者Id"`
  1124. NickName string `description:"作者昵称"`
  1125. Pv int `description:"PV"`
  1126. CollectNum int `description:"收藏人数"`
  1127. FllowNum int `description:"关注数量"`
  1128. MyCollectNum int `description:"本人是否收藏"`
  1129. IsCollect bool `description:"本人是否收藏"`
  1130. }
  1131. // 主题详情start
  1132. type GetThemeDetailResp struct {
  1133. IndustrialManagementId int `description:"产业Id"`
  1134. IndustryName string `description:"产业名称"`
  1135. IsFollow bool `description:"是否关注"`
  1136. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  1137. ListSubject []*IndustrialSubject `description:"标的列表"`
  1138. List []*ArticleResearchResp
  1139. }
  1140. // 主题详情start
  1141. type GetThemeDetailListResp struct {
  1142. ArticleId int `description:"文章id"`
  1143. Title string `description:"标题"`
  1144. PublishDate string `description:"发布时间"`
  1145. SubjectName string `description:"标的名称"`
  1146. IndustrialSubjectId int `description:"标的id"`
  1147. DepartmentId int `description:"作者Id"`
  1148. NickName string `description:"作者昵称"`
  1149. Pv int `description:"PV"`
  1150. CollectNum int `description:"收藏人数"`
  1151. IndustrialManagementId int `description:"产业Id"`
  1152. IndustryName string `description:"产业名称"`
  1153. FllowNum int `description:"关注数量"`
  1154. MyCollectNum int `description:"本人是否收藏"`
  1155. IsCollect bool `description:"本人是否收藏"`
  1156. }
  1157. type GetThemeAericleListBuSubjectResp struct {
  1158. SubjectName string `description:"标的名称"`
  1159. List []*GetThemeAericleListResp
  1160. }
  1161. // 列表
  1162. func GetThemeDetail(userId, industrialManagementId int, condition string) (items []*ArticleListResp, err error) {
  1163. o := orm.NewOrm()
  1164. sql := `SELECT
  1165. a.article_id,
  1166. a.title,
  1167. a.body,
  1168. a.annotation,
  1169. a.abstract,
  1170. a.publish_date,
  1171. a.article_type_id,
  1172. d.nick_name,
  1173. d.department_id,
  1174. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  1175. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  1176. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num
  1177. FROM
  1178. cygx_article AS a
  1179. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  1180. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  1181. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  1182. WHERE
  1183. 1 = 1
  1184. AND m.industrial_management_id = ?
  1185. AND publish_status = 1 ` + condition + `
  1186. ORDER BY
  1187. publish_date DESC`
  1188. _, err = o.Raw(sql, userId, industrialManagementId).QueryRows(&items)
  1189. return
  1190. } //end
  1191. func GetDepartmentlistCount(condition string) (count int, err error) {
  1192. o := orm.NewOrm()
  1193. sql := `SELECT
  1194. count(*) AS count
  1195. FROM
  1196. (
  1197. SELECT
  1198. COUNT( 1 ) AS count
  1199. FROM
  1200. cygx_article_department AS d
  1201. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  1202. WHERE
  1203. 1 = 1
  1204. AND a.article_type_id > 0
  1205. AND publish_status = 1
  1206. GROUP BY
  1207. d.department_id
  1208. ) c `
  1209. err = o.Raw(sql).QueryRow(&count)
  1210. return
  1211. }
  1212. type IndustrialReadNum struct {
  1213. IndustrialManagementId int `description:"产业id"`
  1214. Readnum int `description:"阅读次数"`
  1215. }
  1216. // 获取该产业下文章的用户阅读次数-小红点用
  1217. func GetReportIndustrialReadNumList(userId int, industrialIds string, createtime time.Time) (items []*IndustrialReadNum, err error) {
  1218. o := orm.NewOrm()
  1219. sql := `SELECT a.industrial_management_id, MIN(a.readnum) AS readnum FROM (
  1220. 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
  1221. FROM
  1222. cygx_article AS a
  1223. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  1224. WHERE
  1225. a.publish_status = 1
  1226. AND a.is_class = 1
  1227. AND man_g.industrial_management_id IN (` + industrialIds + `)
  1228. AND a.publish_date > ?
  1229. GROUP BY a.article_id ORDER BY publish_date DESC
  1230. ) AS a GROUP BY industrial_management_id`
  1231. _, err = o.Raw(sql, createtime).QueryRows(&items)
  1232. return
  1233. }
  1234. // 获取行业报告列表
  1235. func GetReportAndproductIndustrylListimgZhouqi(condition string, startSize, pageSize int) (items []*ArticleListResp, total int, err error) {
  1236. o := orm.NewOrm()
  1237. sql := `SELECT
  1238. art.article_id,
  1239. art.report_id,
  1240. art.body,
  1241. art.annotation,
  1242. art.abstract,
  1243. art.category_id,
  1244. art.title,
  1245. art.publish_date,
  1246. 1 AS resource
  1247. FROM
  1248. cygx_article AS art
  1249. WHERE
  1250. art.publish_status = 1 AND category_name = '周期' ` + condition
  1251. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1252. err = o.Raw(totalSql).QueryRow(&total)
  1253. sql += ` ORDER BY publish_date DESC LIMIT ?,? `
  1254. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  1255. return
  1256. }