report.go 47 KB

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