report.go 47 KB

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