report.go 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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. Resource int `description:"来源类型,1:文章、2:产品内测、3:FICC研报"`
  824. ReportId int `description:"FICC研报ID"`
  825. }
  826. // 获取数量
  827. func GetArticleResearchCount(condition string, pars []interface{}, needYanxuanSpecial bool) (count int, err error) {
  828. o := orm.NewOrm()
  829. sqlCount := `SELECT COUNT( 1 ) AS count FROM
  830. cygx_article AS a
  831. WHERE
  832. 1 = 1 AND a.publish_status = 1` + condition
  833. if needYanxuanSpecial {
  834. sqlCount = `SELECT SUM(count) AS count FROM (` + sqlCount + `
  835. UNION ALL
  836. SELECT COUNT( 1 ) AS count FROM
  837. cygx_yanxuan_special AS a WHERE
  838. 1 = 1 AND a.status = 3) AS c`
  839. }
  840. err = o.Raw(sqlCount, pars).QueryRow(&count)
  841. return
  842. }
  843. func GetArticleResearchList(condition string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (items []*ArticleListResp, err error) {
  844. o := orm.NewOrm()
  845. sql := `SELECT
  846. a.article_id,
  847. a.title,
  848. a.body,
  849. a.annotation,
  850. a.abstract,
  851. a.publish_date,
  852. a.article_type_id,
  853. d.nick_name,
  854. d.department_id,
  855. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  856. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  857. ( 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,
  858. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num,
  859. 0 AS is_special,
  860. 0 AS special_type,
  861. 0 AS special_column_id,
  862. '' AS company_tags,
  863. '' AS industry_tags,
  864. a.top_time
  865. FROM
  866. cygx_article AS a
  867. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  868. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  869. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  870. WHERE
  871. 1 = 1 AND a.publish_status = 1 `
  872. if condition != "" {
  873. sql += condition
  874. }
  875. if needYanxuanSpecial {
  876. sql += `UNION ALL
  877. SELECT
  878. a.id AS article_id,
  879. a.title AS title,
  880. '' AS body,
  881. a.content AS annotation,
  882. '' AS abstract,
  883. a.publish_time AS publish_date,
  884. -1 AS article_type_id,
  885. b.nick_name AS nick_name,
  886. 0 AS department_id,
  887. ( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
  888. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  889. 0 AS collect_num_order,
  890. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num,
  891. 1 AS is_special,
  892. a.type AS special_type,
  893. b.id AS special_column_id,
  894. a.company_tags AS company_tags,
  895. a.industry_tags AS industry_tags,
  896. 0 as top_time
  897. FROM
  898. cygx_yanxuan_special AS a
  899. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  900. WHERE
  901. 1 = 1 AND a.status = 3 `
  902. sql += ` GROUP BY article_id ORDER BY top_time DESC , publish_date DESC LIMIT ?,? `
  903. _, err = o.Raw(sql, userId, userId, pars, startSize, pageSize).QueryRows(&items)
  904. } else {
  905. sql += ` GROUP BY a.article_id ORDER BY top_time DESC , a.publish_date DESC LIMIT ?,? `
  906. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  907. }
  908. return
  909. }
  910. func GetArticleResearchListYx(condition string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (items []*ArticleListResp, err error) {
  911. o := orm.NewOrm()
  912. sql := `SELECT
  913. a.article_id,
  914. a.title,
  915. a.body,
  916. a.annotation,
  917. a.abstract,
  918. a.publish_date,
  919. a.article_type_id,
  920. d.nick_name,
  921. d.department_id,
  922. 0 AS is_special,
  923. 0 as pv,
  924. 0 as collect_num,
  925. 0 AS special_type,
  926. 0 AS special_column_id,
  927. '' AS company_tags,
  928. '' AS industry_tags,
  929. a.top_time
  930. FROM
  931. cygx_article AS a
  932. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  933. WHERE
  934. 1 = 1 AND a.publish_status = 1 `
  935. if condition != "" {
  936. sql += condition
  937. }
  938. if needYanxuanSpecial {
  939. sql += `UNION ALL
  940. SELECT
  941. a.id AS article_id,
  942. a.title AS title,
  943. '' AS body,
  944. a.content AS annotation,
  945. '' AS abstract,
  946. a.publish_time AS publish_date,
  947. -1 AS article_type_id,
  948. b.nick_name AS nick_name,
  949. 0 AS department_id,
  950. 1 AS is_special,
  951. a.pv,
  952. a.article_collect_num as collect_num,
  953. a.type AS special_type,
  954. b.id AS special_column_id,
  955. a.company_tags AS company_tags,
  956. a.industry_tags AS industry_tags,
  957. 0 as top_time
  958. FROM
  959. cygx_yanxuan_special AS a
  960. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  961. WHERE
  962. 1 = 1 AND a.status = 3 `
  963. }
  964. sql += ` GROUP BY article_id ORDER BY top_time DESC , publish_date DESC LIMIT ?,? `
  965. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  966. return
  967. }
  968. func GetArticleResearchAndYxSpecialList(condition, conditionYxSpecial string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (total int, items []*ArticleListResp, err error) {
  969. o := orm.NewOrm()
  970. sql := `SELECT
  971. a.article_id,
  972. a.title,
  973. a.body,
  974. a.annotation,
  975. a.abstract,
  976. a.publish_date,
  977. a.article_type_id,
  978. d.nick_name,
  979. d.department_id,
  980. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  981. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  982. ( 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,
  983. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num,
  984. 0 AS is_special,
  985. 0 AS special_type,
  986. 0 AS special_column_id,
  987. '' AS company_tags,
  988. '' AS industry_tags
  989. FROM
  990. cygx_article AS a
  991. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  992. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  993. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  994. WHERE
  995. 1 = 1 AND a.publish_status = 1 `
  996. if condition != "" {
  997. sql += condition
  998. }
  999. if needYanxuanSpecial {
  1000. sql += `UNION ALL
  1001. SELECT
  1002. a.id AS article_id,
  1003. a.title AS title,
  1004. '' AS body,
  1005. a.content AS annotation,
  1006. '' AS abstract,
  1007. a.publish_time AS publish_date,
  1008. -1 AS article_type_id,
  1009. b.nick_name AS nick_name,
  1010. 0 AS department_id,
  1011. ( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
  1012. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  1013. 0 AS collect_num_order,
  1014. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num,
  1015. 1 AS is_special,
  1016. a.type AS special_type,
  1017. b.id AS special_column_id,
  1018. a.company_tags AS company_tags,
  1019. a.industry_tags AS industry_tags
  1020. FROM
  1021. cygx_yanxuan_special AS a
  1022. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  1023. WHERE
  1024. 1 = 1 AND a.status = 3 ` + conditionYxSpecial
  1025. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1026. err = o.Raw(totalSql, userId, userId, pars).QueryRow(&total)
  1027. sql += ` GROUP BY article_id ORDER BY publish_date DESC LIMIT ?,? `
  1028. _, err = o.Raw(sql, userId, userId, pars, startSize, pageSize).QueryRows(&items)
  1029. } else {
  1030. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  1031. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  1032. }
  1033. return
  1034. }
  1035. func GetArticleResearchListHz(condition string, pars []interface{}, startSize, pageSize, userId int) (items []*ArticleListResp, err error) {
  1036. o := orm.NewOrm()
  1037. sql := `SELECT
  1038. a.article_id,
  1039. a.report_id,
  1040. a.title,
  1041. a.body,
  1042. a.annotation,
  1043. a.abstract,
  1044. a.publish_date,
  1045. a.category_id,
  1046. a.article_type_id,
  1047. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  1048. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  1049. ( 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,
  1050. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  1051. FROM
  1052. cygx_article AS a
  1053. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  1054. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  1055. WHERE
  1056. 1 = 1 AND a.publish_status = 1 `
  1057. if condition != "" {
  1058. sql += condition
  1059. }
  1060. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  1061. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  1062. return
  1063. }
  1064. type IndustrialManagementHotListResp struct {
  1065. Paging *paging.PagingItem `description:"分页数据"`
  1066. List []*IndustrialManagementHotResp
  1067. }
  1068. // 获取数量
  1069. func GetThemeHeatListCount(condition string) (count int, err error) {
  1070. o := orm.NewOrm()
  1071. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  1072. cygx_industrial_management AS m
  1073. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  1074. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  1075. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  1076. WHERE
  1077. 1 = 1 AND a.publish_status = 1 ` + condition
  1078. err = o.Raw(sql).QueryRow(&count)
  1079. return
  1080. }
  1081. // 产业列表
  1082. func GetThemeHeatList(userId int, condition, conditionOrder string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  1083. o := orm.NewOrm()
  1084. sql := `SELECT
  1085. m.industry_name,
  1086. m.industrial_management_id,
  1087. m.article_read_num,
  1088. MAX( a.publish_date ) AS publish_date,
  1089. MIN(a.publish_date) AS min_report_time,
  1090. ( 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,
  1091. m.yanxuan_article_read_num + m.activity_num AS sum_num
  1092. FROM
  1093. cygx_industrial_management AS m
  1094. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  1095. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  1096. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  1097. WHERE
  1098. 1 = 1
  1099. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  1100. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  1101. return
  1102. }
  1103. type GetThemeAericleListResp struct {
  1104. ArticleId int `description:"文章id"`
  1105. Title string `description:"标题"`
  1106. PublishDate string `description:"发布时间"`
  1107. SubjectName string `description:"标的名称"`
  1108. IndustrialSubjectId int `description:"标的ID"`
  1109. DepartmentId int `description:"作者Id"`
  1110. NickName string `description:"作者昵称"`
  1111. Pv int `description:"PV"`
  1112. CollectNum int `description:"收藏人数"`
  1113. FllowNum int `description:"关注数量"`
  1114. MyCollectNum int `description:"本人是否收藏"`
  1115. IsCollect bool `description:"本人是否收藏"`
  1116. }
  1117. // 主题详情start
  1118. type GetThemeDetailResp struct {
  1119. IndustrialManagementId int `description:"产业Id"`
  1120. IndustryName string `description:"产业名称"`
  1121. IsFollow bool `description:"是否关注"`
  1122. ListSubject []*IndustrialSubject `description:"标的列表"`
  1123. List []*ArticleResearchResp
  1124. }
  1125. // 主题详情start
  1126. type GetThemeDetailListResp struct {
  1127. ArticleId int `description:"文章id"`
  1128. Title string `description:"标题"`
  1129. PublishDate string `description:"发布时间"`
  1130. SubjectName string `description:"标的名称"`
  1131. IndustrialSubjectId int `description:"标的id"`
  1132. DepartmentId int `description:"作者Id"`
  1133. NickName string `description:"作者昵称"`
  1134. Pv int `description:"PV"`
  1135. CollectNum int `description:"收藏人数"`
  1136. IndustrialManagementId int `description:"产业Id"`
  1137. IndustryName string `description:"产业名称"`
  1138. FllowNum int `description:"关注数量"`
  1139. MyCollectNum int `description:"本人是否收藏"`
  1140. IsCollect bool `description:"本人是否收藏"`
  1141. }
  1142. type GetThemeAericleListBuSubjectResp struct {
  1143. SubjectName string `description:"标的名称"`
  1144. List []*GetThemeAericleListResp
  1145. }
  1146. // 列表
  1147. func GetThemeDetail(userId, industrialManagementId int, condition string) (items []*ArticleListResp, err error) {
  1148. o := orm.NewOrm()
  1149. sql := `SELECT
  1150. a.article_id,
  1151. a.title,
  1152. a.body,
  1153. a.annotation,
  1154. a.abstract,
  1155. a.publish_date,
  1156. a.article_type_id,
  1157. d.nick_name,
  1158. d.department_id,
  1159. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  1160. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  1161. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num
  1162. FROM
  1163. cygx_article AS a
  1164. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  1165. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  1166. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  1167. WHERE
  1168. 1 = 1
  1169. AND m.industrial_management_id = ?
  1170. AND publish_status = 1 ` + condition + `
  1171. ORDER BY
  1172. publish_date DESC`
  1173. _, err = o.Raw(sql, userId, industrialManagementId).QueryRows(&items)
  1174. return
  1175. } //end
  1176. func GetDepartmentlistCount(condition string) (count int, err error) {
  1177. o := orm.NewOrm()
  1178. sql := `SELECT
  1179. count(*) AS count
  1180. FROM
  1181. (
  1182. SELECT
  1183. COUNT( 1 ) AS count
  1184. FROM
  1185. cygx_article_department AS d
  1186. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  1187. WHERE
  1188. 1 = 1
  1189. AND a.article_type_id > 0
  1190. AND publish_status = 1
  1191. GROUP BY
  1192. d.department_id
  1193. ) c `
  1194. err = o.Raw(sql).QueryRow(&count)
  1195. return
  1196. }
  1197. type IndustrialReadNum struct {
  1198. IndustrialManagementId int `description:"产业id"`
  1199. Readnum int `description:"阅读次数"`
  1200. }
  1201. // 获取该产业下文章的用户阅读次数-小红点用
  1202. func GetReportIndustrialReadNumList(userId int, industrialIds string, createtime time.Time) (items []*IndustrialReadNum, err error) {
  1203. o := orm.NewOrm()
  1204. sql := `SELECT a.industrial_management_id, MIN(a.readnum) AS readnum FROM (
  1205. 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
  1206. FROM
  1207. cygx_article AS a
  1208. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  1209. WHERE
  1210. a.publish_status = 1
  1211. AND a.is_class = 1
  1212. AND man_g.industrial_management_id IN (` + industrialIds + `)
  1213. AND a.publish_date > ?
  1214. GROUP BY a.article_id ORDER BY publish_date DESC
  1215. ) AS a GROUP BY industrial_management_id`
  1216. _, err = o.Raw(sql, createtime).QueryRows(&items)
  1217. return
  1218. }
  1219. // 获取行业报告列表
  1220. func GetReportAndproductIndustrylListimgZhouqi(condition string, startSize, pageSize int) (items []*ArticleListResp, total int, err error) {
  1221. o := orm.NewOrm()
  1222. sql := `SELECT
  1223. art.article_id,
  1224. art.report_id,
  1225. art.body,
  1226. art.annotation,
  1227. art.abstract,
  1228. art.category_id,
  1229. art.title,
  1230. art.publish_date,
  1231. 1 AS resource
  1232. FROM
  1233. cygx_article AS art
  1234. WHERE
  1235. art.publish_status = 1 AND category_name = '周期' ` + condition
  1236. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1237. err = o.Raw(totalSql).QueryRow(&total)
  1238. sql += ` ORDER BY publish_date DESC LIMIT ?,? `
  1239. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  1240. return
  1241. }