report.go 47 KB

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