report.go 49 KB

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