report.go 48 KB

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