report.go 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "strconv"
  6. "time"
  7. //"github.com/rdlucklib/rdluck_tools/paging"
  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. RecommendedIndex int `description:"推荐指数"`
  17. CategoryId int `description:"文章分类ID"`
  18. LayoutTime string `description:"布局时间"`
  19. UpdateTime string `description:"更新时间"`
  20. MinReportTime string `description:"报告最早发布时间"`
  21. IsRed bool `description:"是否标记红点"`
  22. IsTop bool `description:"是否置顶"`
  23. IsHot bool `description:"是否是热门-近一个月内,产业下关联的报告阅读次数最多的"`
  24. IsFollow int `description:"是否关注"`
  25. IsNew bool `description:"是否为新-关联报告的发布时间,均在3个月以内的"`
  26. Analyst string `description:"分析师"`
  27. ArticleReadNum int `description:"文章阅读数量"`
  28. OneMonFollowNum int `description:"近一个月关注增量"`
  29. AnalystList []*IndustrialAnalyst `description:"分析师列表"`
  30. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  31. ChartPermissionId int `description:"行业ID"`
  32. PermissionName string `description:"行业名称"`
  33. IndustryVideo *MicroVideoSimpleInfo
  34. AuthInfo *UserPermissionAuthInfo
  35. ArticleId int `description:"文章id"`
  36. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  37. }
  38. type MicroVideoSimpleInfo struct {
  39. Id int `description:"视频ID"`
  40. Title string `description:"标题"`
  41. ResourceUrl string `description:"链接"`
  42. BackgroundImg string `description:"背景图"`
  43. PlaySeconds int `description:"音视频时长"`
  44. DetailImgUrl string `description:"产业详情页背景图"`
  45. ChartPermissionId int `description:"行业ID"`
  46. ChartPermissionName string `description:"行业名称"`
  47. }
  48. type IndustrialAnalyst struct {
  49. AnalystName string `description:"分析师名称"`
  50. IndustrialManagementId int `description:"产业id"`
  51. }
  52. type IndustrialSubject struct {
  53. IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"`
  54. IndustrialManagementId int `description:"产业id"`
  55. SubjectName string `description:"标的名称"`
  56. IndustryName string `description:"产业名称"`
  57. LayoutTime string `description:"产业布局时间"`
  58. }
  59. // 获取产业报告数量
  60. func GetReportIndustrialCount(categoryId, industrialManagementId int) (count int, err error) {
  61. o := orm.NewOrm()
  62. sql := `SELECT COUNT(1) count
  63. FROM
  64. cygx_article AS a
  65. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  66. WHERE
  67. a.publish_status = 1
  68. AND category_id IN (SELECT
  69. category_id
  70. FROM
  71. cygx_report_mapping
  72. WHERE
  73. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` )
  74. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` ) )
  75. AND a.is_class = 1
  76. AND man_g.industrial_management_id = ? `
  77. err = o.Raw(sql, industrialManagementId).QueryRow(&count)
  78. return
  79. }
  80. // 获取产业报告列表
  81. func GetReportIndustrialList(pars []interface{}, categoryId, industrialManagementId, userId, startSize, pageSize int) (items []*ReportArticle, err error) {
  82. o := orm.NewOrm()
  83. sql := `SELECT *,( 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
  84. FROM
  85. cygx_article AS a
  86. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  87. WHERE
  88. a.publish_status = 1
  89. AND category_id IN (SELECT
  90. category_id
  91. FROM
  92. cygx_report_mapping
  93. WHERE
  94. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` )
  95. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` ) )
  96. AND a.is_class = 1
  97. AND man_g.industrial_management_id = ?`
  98. sql += ` GROUP BY a.article_id ORDER BY publish_date DESC LIMIT ?,? `
  99. _, err = o.Raw(sql, pars, industrialManagementId, startSize, pageSize).QueryRows(&items)
  100. return
  101. }
  102. // 产业下所关联的文章分类列表
  103. func IndustrialToArticleCategory(industrialManagementId, chartPermissionId int) (items []*IndustrialToArticleCategoryRep, err error) {
  104. o := orm.NewOrm()
  105. sql := `SELECT map.match_type_name,map.category_id
  106. FROM cygx_report_mapping AS map
  107. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  108. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  109. WHERE map.report_type = 2
  110. AND map.is_report = 1
  111. AND art.is_report = 1
  112. AND art.publish_status = 1
  113. AND man_g.industrial_management_id =?
  114. AND map.chart_permission_id = ?
  115. GROUP BY map.match_type_name`
  116. _, err = o.Raw(sql, industrialManagementId, chartPermissionId).QueryRows(&items)
  117. return
  118. }
  119. // 产业下所关联的文章分类列表 2022-10-13
  120. func IndustrialToArticleCategoryNew(industrialManagementId int) (items []*IndustrialToArticleCategoryRep, err error) {
  121. o := orm.NewOrm()
  122. sql := `SELECT map.match_type_name,map.category_id
  123. FROM cygx_report_mapping AS map
  124. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  125. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  126. WHERE map.report_type = 2
  127. AND map.is_report = 1
  128. AND art.is_report = 1
  129. AND art.publish_status = 1
  130. AND man_g.industrial_management_id =?
  131. GROUP BY map.match_type_name`
  132. _, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
  133. return
  134. }
  135. // 判断用户是否阅读该产业下,某一分类的文章
  136. func IndustrialUserRecordArticleCount(userId, industrialManagementId, categoryId int) (count int, err error) {
  137. o := orm.NewOrm()
  138. sql := `SELECT
  139. COUNT(1) count
  140. FROM
  141. cygx_article_history_record
  142. WHERE
  143. 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 category_id IN (SELECT
  144. category_id
  145. FROM
  146. cygx_report_mapping
  147. WHERE
  148. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ? )
  149. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ? ) ) ORDER BY publish_date DESC LIMIT 0, 1 )
  150. AND user_id = ? `
  151. err = o.Raw(sql, industrialManagementId, categoryId, categoryId, userId).QueryRow(&count)
  152. return
  153. }
  154. // 获取最新文章
  155. func GetNewIndustrialUserRecordArticle(industrialManagementId, categoryId int) (item *ArticleDetail, err error) {
  156. o := orm.NewOrm()
  157. //sql := ` SELECT * FROM cygx_article WHERE article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id = ? ) AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ? ) ORDER BY publish_date DESC LIMIT 0, 1`
  158. 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
  159. category_id
  160. FROM
  161. cygx_report_mapping
  162. WHERE
  163. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ? )
  164. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ? ) ) ORDER BY publish_date DESC LIMIT 0, 1`
  165. err = o.Raw(sql, industrialManagementId, categoryId, categoryId).QueryRow(&item)
  166. return
  167. }
  168. // 获取最新文章
  169. func GetNewArticleByCategoryId(categoryId int) (item *ArticleDetail, err error) {
  170. o := orm.NewOrm()
  171. sql := ` SELECT * FROM cygx_article WHERE category_id = ? ORDER BY publish_date DESC LIMIT 0, 1`
  172. err = o.Raw(sql, categoryId).QueryRow(&item)
  173. return
  174. }
  175. func GetIndustrialManagementIdsBykeyWord(condition string) (industrialManagementIds string, err error) {
  176. sql := `SELECT GROUP_CONCAT(DISTINCT industrial_management_id SEPARATOR ',') AS industrial_management_ids FROM cygx_industrial_management WHERE` + condition
  177. o := orm.NewOrm()
  178. err = o.Raw(sql).QueryRow(&industrialManagementIds)
  179. return
  180. }
  181. type ReportArticleWhichIndustrial struct {
  182. ArticleId int `description:"文章id"`
  183. Title string `description:"标题"`
  184. PublishDate string `description:"发布时间"`
  185. IndustryName string `description:"产业名称"`
  186. SubjectName string `description:"标的名称"`
  187. NickName string `description:"作者昵称"`
  188. IsRed bool `description:"是否标记红点"`
  189. Readnum int `description:"阅读数量"`
  190. IsResearch bool `description:"是否属于研选"`
  191. Pv int `description:"PV"`
  192. ImgUrlPc string `description:"图片链接"`
  193. }
  194. type ReportArticleWhichIndustrialRepList struct {
  195. HaveResearch bool `description:"是否有研选权限"`
  196. Paging *paging.PagingItem `description:"分页数据"`
  197. NickName string `description:"作者昵称"`
  198. IndustryName string `description:"产业名称"`
  199. List []*ReportArticleWhichIndustrial
  200. }
  201. // 列表
  202. func IndustrialToArticleWhichDepartment(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*ReportArticleWhichIndustrial, err error) {
  203. o := orm.NewOrm()
  204. sql := `SELECT
  205. art.* ,m.industry_name,d.nick_name,
  206. (SELECT count(1) FROM cygx_article_history_record_newpv as h WHERE h.article_id = art.article_id ) as pv,
  207. ( SELECT COUNT( 1 ) FROM cygx_article_history_record_newpv AS rec WHERE rec.user_id = ` + strconv.Itoa(uid) + ` AND rec.article_id = art.article_id ) AS readnum
  208. FROM
  209. cygx_article AS art
  210. INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  211. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  212. INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
  213. WHERE 1 = 1
  214. AND art.publish_status = 1`
  215. if condition != "" {
  216. sql += condition
  217. }
  218. sql += ` LIMIT ?,?`
  219. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  220. return
  221. }
  222. func GetWhichDepartmentCount(condition string) (count int, err error) {
  223. o := orm.NewOrm()
  224. sql := `SELECT COUNT(1) count
  225. FROM
  226. cygx_article AS art
  227. INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  228. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  229. INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
  230. WHERE 1 = 1
  231. AND art.publish_status = 1`
  232. if condition != "" {
  233. sql += condition
  234. }
  235. err = o.Raw(sql).QueryRow(&count)
  236. return
  237. }
  238. type IsShow struct {
  239. IsShow bool `description:"绝密内参按钮是否展示"`
  240. IsShowFreeButton bool `description:"免费送月卡按钮是否展示"`
  241. IsShowResearch bool `description:"研选是否展示限免"`
  242. IsShowChart bool `description:"图表是否展示限免"`
  243. IsShowList bool `description:"榜单是否展示"`
  244. LinkWxExplain string `description:"关注微信公众号链接说明地址"`
  245. YanXuan_Explain bool `description:"研选说明"`
  246. ActivitySpecialExplain string `description:"专项调研活动"`
  247. SearchTxtList SearchTxt `description:"搜索栏回显内容说明"`
  248. }
  249. type SearchTxt struct {
  250. SummarySearch string `description:"素材库搜索说明"`
  251. ReportSearch string `description:"报告搜索说明"`
  252. YanXuanSearch string `description:"研选搜索说明"`
  253. ActivitySearch string `description:"活动搜索说明"`
  254. TabSearch string `description:"素材库搜索说明"`
  255. }
  256. // 获取用户是否有查看权限
  257. func GetUserIsAdminCount(mobile string) (count int, err error) {
  258. o := orm.NewOrm()
  259. sql := `SELECT COUNT(1) count FROM admin
  260. WHERE
  261. mobile = ?
  262. AND (group_id IN (11, 13, 14, 15, 16, 17) OR department_id = 3 ) AND enabled = 1`
  263. err = o.Raw(sql, mobile).QueryRow(&count)
  264. return
  265. }
  266. type ReportDetailRoadshow struct {
  267. ArticleId int `description:"报告Id"`
  268. Title string `description:"标题"`
  269. Department string `orm:"column(seller_and_mobile)"description:"作者"`
  270. PublishDate string `description:"发布时间"`
  271. VideoUrl string `description:"链接"`
  272. VideoPlaySeconds string `description:"时长"`
  273. VideoName string `description:"音频名称"`
  274. Abstract string `description:"摘要"`
  275. Body string `description:"内容"`
  276. CategoryName string `description:"行业名称"`
  277. ReportLink string `orm:"column(link_article_id)"description:"报告链接"`
  278. IsCollect bool `description:"是否收藏:true,已收藏,false:未收藏"`
  279. IsRoadShow bool `description:"是否是路演精华"`
  280. CategoryId int `description:"文章分类ID"`
  281. }
  282. type RoadshowDetailResp struct {
  283. Detail *ReportDetailRoadshow
  284. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  285. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  286. }
  287. func GetReportRoadshowDetailById(articleId int) (item *ReportDetailRoadshow, err error) {
  288. o := orm.NewOrm()
  289. sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
  290. err = o.Raw(sql, articleId).QueryRow(&item)
  291. return
  292. }
  293. type CygxIndustryAndArticleList struct {
  294. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  295. Title string `description:"标题"`
  296. PublishDate string `description:"发布时间"`
  297. IndustryName string `description:"产业名称"`
  298. SubjectName string `description:"标的名称"`
  299. }
  300. type CygxIndustrySearchList struct {
  301. ArtList []*CygxIndustryAndArticleList `description:"文章列表"`
  302. IndList []*IndustrialManagement `description:"产业列表"`
  303. }
  304. type CygxIndustrySearchListPc struct {
  305. DepartmentList []*CygxArticleDepartmentRepPc
  306. IndList []*IndustrialManagement `description:"产业列表"`
  307. }
  308. // 列表
  309. func GetCygxIndustryAndArticleList(keyWord string) (items []*CygxIndustryAndArticleList, err error) {
  310. o := orm.NewOrm()
  311. sql := `SELECT
  312. art.title,
  313. art.article_id,
  314. art.publish_date
  315. FROM
  316. cygx_article AS art
  317. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
  318. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = mg.article_id
  319. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  320. WHERE
  321. category_name LIKE '%研选%'
  322. AND art.article_id IN ( SELECT article_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_subject WHERE subject_name LIKE '%` + keyWord + `%' ) GROUP BY sg.article_id )
  323. OR ( art.article_id IN ( SELECT article_id FROM cygx_industrial_article_group_management AS mg WHERE mg.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_management WHERE industry_name LIKE '%` + keyWord + `%' ) GROUP BY mg.article_id ) AND category_name LIKE '%研选%' )
  324. GROUP BY
  325. art.article_id`
  326. _, err = o.Raw(sql).QueryRows(&items)
  327. return
  328. }
  329. func GetArticleIdsBySubId(subjectId string) (articleIds string, err error) {
  330. o := orm.NewOrm()
  331. sql := `SELECT GROUP_CONCAT( DISTINCT a.article_id SEPARATOR ',' ) AS articleIds
  332. FROM cygx_article AS a
  333. WHERE subject_ids LIKE '%` + subjectId + `%'`
  334. err = o.Raw(sql).QueryRow(&articleIds)
  335. return
  336. } //end
  337. // 用户收藏榜start
  338. type ArticleCollectionResp struct {
  339. ArticleId int `description:"文章id"`
  340. Title string `description:"标题"`
  341. PublishDate string `description:"发布时间"`
  342. IndustrialManagementId int `description:"产业Id"`
  343. IndustryName string `description:"产业名称"`
  344. DepartmentId int `description:"作者Id"`
  345. NickName string `description:"作者昵称"`
  346. MyCollectNum int `description:"本人是否收藏"`
  347. IsCollect bool `description:"本人是否收藏"`
  348. Pv int `description:"PV"`
  349. CollectNum int `description:"收藏人数"`
  350. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  351. ArticleTypeId int `description:"文章类型ID"`
  352. List []*IndustrialManagementResp `description:"产业列表"`
  353. }
  354. type IndustrialManagementResp struct {
  355. IndustrialManagementId int `description:"产业Id"`
  356. IndustryName string `description:"产业名称"`
  357. ChartPermissionId int `description:"权限id"`
  358. }
  359. type ArticleCollectionLIstResp struct {
  360. List []*ArticleCollectionResp
  361. }
  362. // 研选报告收藏榜单列表
  363. func GetReportCollectionBillboardListYx(limit int, pars []interface{}, condition string) (items []*ArticleCollectionResp, err error) {
  364. o := orm.NewOrm()
  365. sql := `SELECT
  366. ac.id,
  367. a.category_id,
  368. a.article_id,
  369. a.title,
  370. a.body,
  371. a.annotation,
  372. a.abstract,
  373. a.publish_date,
  374. a.article_type_id,
  375. d.nick_name,
  376. d.department_id,
  377. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  378. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id ) AS collect_num,
  379. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collection_num
  380. FROM
  381. cygx_article AS a
  382. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  383. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  384. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  385. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  386. WHERE
  387. 1 = 1
  388. AND a.publish_status = 1 `
  389. if condition != "" {
  390. sql += condition
  391. }
  392. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, a.publish_date DESC`
  393. sql += ` LIMIT ?`
  394. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  395. return
  396. }
  397. // 列表
  398. func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  399. o := orm.NewOrm()
  400. sql := `SELECT
  401. a.article_id,
  402. a.title,
  403. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  404. m.industry_name,
  405. m.industrial_management_id,
  406. d.nick_name,
  407. d.department_id,
  408. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  409. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id ) AS collect_num,
  410. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  411. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  412. FROM
  413. cygx_article AS a
  414. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  415. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  416. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  417. WHERE
  418. 1 = 1 AND a.publish_status = 1 `
  419. if condition != "" {
  420. sql += condition
  421. }
  422. _, err = o.Raw(sql, userId).QueryRows(&items)
  423. return
  424. } //end
  425. type ArticleResearchListResp struct {
  426. Paging *paging.PagingItem
  427. List []*ArticleResearchResp
  428. }
  429. type ArticleResearchResp struct {
  430. ArticleId int `description:"文章id"`
  431. Title string `description:"标题"`
  432. PublishDate string `description:"发布时间"`
  433. DepartmentId int `description:"作者Id"`
  434. NickName string `description:"作者昵称"`
  435. IsCollect bool `description:"本人是否收藏"`
  436. Pv int `description:"PV"`
  437. CollectNum int `description:"收藏人数"`
  438. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  439. ArticleTypeId int `description:"文章类型ID"`
  440. ArticleTypeName string `description:"类型名称"`
  441. ButtonStyle string `description:"按钮展示样式"`
  442. List []*IndustrialManagementResp `description:"产业列表"`
  443. }
  444. // 获取我的日程数量
  445. func GetArticleResearchCount(condition string, pars []interface{}) (count int, err error) {
  446. o := orm.NewOrm()
  447. sqlCount := `SELECT COUNT( 1 ) AS count FROM
  448. cygx_article AS a
  449. WHERE
  450. 1 = 1 AND a.publish_status = 1` + condition
  451. err = o.Raw(sqlCount, pars).QueryRow(&count)
  452. return
  453. }
  454. func GetArticleResearchList(condition string, pars []interface{}, startSize, pageSize, userId int) (items []*ArticleCollectionResp, err error) {
  455. o := orm.NewOrm()
  456. sql := `SELECT
  457. a.article_id,
  458. a.title,
  459. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  460. a.article_type_id,
  461. d.nick_name,
  462. d.department_id,
  463. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  464. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id ) AS collect_num,
  465. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  466. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  467. FROM
  468. cygx_article AS a
  469. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  470. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  471. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  472. WHERE
  473. 1 = 1 AND a.publish_status = 1 `
  474. if condition != "" {
  475. sql += condition
  476. }
  477. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  478. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  479. return
  480. }
  481. // 用户收藏榜start
  482. type IndustrialManagementHotResp struct {
  483. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  484. IndustryName string `description:"产业名称"`
  485. IsFollw bool `description:"是否关注"`
  486. FllowNum int `description:"关注数量"`
  487. IsNew bool `description:"是否新标签"`
  488. IsHot bool `description:"是否新标签"`
  489. IsRed bool `description:"是否标记红点"`
  490. Readnum int `description:"阅读数量"`
  491. PublishDate string `description:"发布时间"`
  492. MinReportTime string `description:"报告最早发布时间"`
  493. ArticleReadNum int `description:"文章阅读数量"`
  494. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  495. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  496. IndustryVideo *MicroVideoSimpleInfo `description:"产业视频"`
  497. AuthInfo *UserPermissionAuthInfo
  498. }
  499. type IndustrialManagementHotListResp struct {
  500. Paging *paging.PagingItem `description:"分页数据"`
  501. List []*IndustrialManagementHotResp
  502. }
  503. // 产业列表
  504. func GetThemeHeatList(userId int, condition, conditionOrder string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  505. o := orm.NewOrm()
  506. sql := `SELECT
  507. m.industry_name,
  508. m.industrial_management_id,
  509. m.article_read_num,
  510. MAX( a.publish_date ) AS publish_date,
  511. MIN(a.publish_date) AS min_report_time,
  512. ( 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,
  513. m.yanxuan_article_read_num + m.activity_num AS sum_num
  514. FROM
  515. cygx_industrial_management AS m
  516. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  517. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  518. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  519. WHERE
  520. 1 = 1
  521. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  522. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  523. return
  524. }
  525. // 获取数量
  526. func GetThemeHeatListCount(condition string) (count int, err error) {
  527. o := orm.NewOrm()
  528. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  529. cygx_industrial_management AS m
  530. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  531. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  532. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  533. WHERE
  534. 1 = 1
  535. AND a.publish_status = 1 ` + condition
  536. err = o.Raw(sql).QueryRow(&count)
  537. return
  538. }
  539. // 标的列表
  540. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  541. o := orm.NewOrm()
  542. sql := `SELECT
  543. m.subject_name,
  544. m.industrial_management_id,
  545. m.industrial_subject_id
  546. FROM
  547. cygx_article AS a
  548. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  549. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  550. WHERE
  551. 1 = 1`
  552. if condition != "" {
  553. sql += condition
  554. }
  555. sql += ` AND publish_status = 1
  556. GROUP BY
  557. m.industrial_subject_id
  558. ORDER BY
  559. publish_date DESC`
  560. _, err = o.Raw(sql).QueryRows(&items)
  561. return
  562. } //end
  563. // Kol sratr
  564. type DepartmentResp struct {
  565. DepartmentId int `description:"作者Id"`
  566. NickName string `description:"作者昵称"`
  567. ImgUrl string `description:"图片链接"`
  568. IsFollw bool `description:"是否关注"`
  569. IsHot bool `description:"是否关注"`
  570. FllowNum int `description:"关注数量"`
  571. List []*IndustrialDepartmentListResp
  572. }
  573. type DepartmentListResp struct {
  574. Paging *paging.PagingItem `description:"分页数据"`
  575. List []*DepartmentResp
  576. }
  577. type IndustrialDepartmentListResp struct {
  578. IndustrialManagementId int `description:"产业Id"`
  579. IndustryName string `description:"产业名称"`
  580. DepartmentId int `description:"作者Id"`
  581. }
  582. // 作者列表
  583. func GetDepartmentList(condition, conditionOrder string, userId, startSize, pageSize int) (items []*DepartmentResp, err error) {
  584. o := orm.NewOrm()
  585. sql := `SELECT
  586. d.nick_name,
  587. d.department_id,
  588. d.img_url,
  589. MAX( a.publish_date ) AS publish_date,
  590. ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND user_id =? AND f.type= 1 ) AS fllow_num,
  591. ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.type= 1 ) AS sum_num
  592. FROM
  593. cygx_article_department AS d
  594. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  595. WHERE
  596. 1 = 1
  597. AND publish_status = 1 ` + condition + `
  598. GROUP BY
  599. d.department_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  600. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  601. return
  602. }
  603. // 获取数量
  604. func GetDepartmentlistCount(condition string) (count int, err error) {
  605. o := orm.NewOrm()
  606. sql := `SELECT
  607. count(*) AS count
  608. FROM
  609. (
  610. SELECT
  611. COUNT( 1 ) AS count
  612. FROM
  613. cygx_article_department AS d
  614. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  615. WHERE
  616. 1 = 1
  617. AND a.article_type_id > 0
  618. AND publish_status = 1
  619. GROUP BY
  620. d.department_id
  621. ) c `
  622. err = o.Raw(sql).QueryRow(&count)
  623. return
  624. }
  625. // 作者文章所关联的产业列表
  626. func GetIndustrialDepartmentList() (items []*IndustrialDepartmentListResp, err error) {
  627. o := orm.NewOrm()
  628. sql := `SELECT
  629. m.industrial_management_id,
  630. m.industry_name,
  631. d.department_id
  632. FROM
  633. cygx_article_department AS d
  634. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  635. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  636. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  637. WHERE
  638. 1 = 1
  639. AND a.article_type_id > 0
  640. AND publish_status = 1
  641. ORDER BY
  642. a.publish_date DESC`
  643. _, err = o.Raw(sql).QueryRows(&items)
  644. return
  645. }
  646. // 主题详情start
  647. type GetThemeDetailListResp struct {
  648. ArticleId int `description:"文章id"`
  649. Title string `description:"标题"`
  650. PublishDate string `description:"发布时间"`
  651. SubjectName string `description:"标的名称"`
  652. IndustrialSubjectId int `description:"标的id"`
  653. DepartmentId int `description:"作者Id"`
  654. NickName string `description:"作者昵称"`
  655. Pv int `description:"PV"`
  656. CollectNum int `description:"收藏人数"`
  657. IndustrialManagementId int `description:"产业Id"`
  658. IndustryName string `description:"产业名称"`
  659. FllowNum int `description:"关注数量"`
  660. MyCollectNum int `description:"本人是否收藏"`
  661. IsCollect bool `description:"本人是否收藏"`
  662. }
  663. type GetThemeAericleListResp struct {
  664. ArticleId int `description:"文章id"`
  665. Title string `description:"标题"`
  666. PublishDate string `description:"发布时间"`
  667. SubjectName string `description:"标的名称"`
  668. IndustrialSubjectId int `description:"标的ID"`
  669. DepartmentId int `description:"作者Id"`
  670. NickName string `description:"作者昵称"`
  671. Pv int `description:"PV"`
  672. CollectNum int `description:"收藏人数"`
  673. FllowNum int `description:"关注数量"`
  674. MyCollectNum int `description:"本人是否收藏"`
  675. IsCollect bool `description:"本人是否收藏"`
  676. }
  677. type GetThemeAericleListBuSubjectResp struct {
  678. SubjectName string `description:"标的名称"`
  679. List []*GetThemeAericleListResp
  680. }
  681. // 主题详情start
  682. type GetThemeDetailResp struct {
  683. IndustrialManagementId int `description:"产业Id"`
  684. IndustryName string `description:"产业名称"`
  685. IsFollw bool `description:"是否关注"`
  686. ListSubject []*IndustrialSubject `description:"标的列表"`
  687. List []*GetThemeAericleListResp
  688. }
  689. // 列表
  690. func GetThemeDetail(userId, industrialManagementId int, condition string) (items []*GetThemeDetailListResp, err error) {
  691. o := orm.NewOrm()
  692. sql := `SELECT
  693. a.article_id,
  694. a.title,
  695. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  696. m.industry_name,
  697. m.industrial_management_id,
  698. d.nick_name,
  699. d.department_id,
  700. s.industrial_subject_id,
  701. s.subject_name,
  702. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  703. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  704. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num,
  705. ( SELECT count( 1 ) FROM cygx_industry_fllow AS ac WHERE user_id = ? AND ac.industrial_management_id = m.industrial_management_id AND ac.type= 1) AS fllow_num
  706. FROM
  707. cygx_article AS a
  708. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  709. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  710. LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
  711. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
  712. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  713. WHERE
  714. 1 = 1
  715. AND m.industrial_management_id = ?
  716. AND publish_status = 1 ` + condition + ` GROUP BY article_id
  717. ORDER BY
  718. publish_date DESC`
  719. _, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)
  720. return
  721. } //end
  722. // 用户收藏榜start
  723. type DepartmentDetailResp struct {
  724. DepartmentId int `description:"作者Id"`
  725. NickName string `description:"作者昵称"`
  726. ImgUrl string `description:"图片链接"`
  727. FllowNum int `description:"多少人关注"`
  728. ArticleNum int `description:"文章数量"`
  729. CollectNum int `description:"收藏人数"`
  730. IsFllow bool `description:"是否关注"`
  731. List []*ArticleCollectionResp
  732. ListIndustrial []*IndustrialManagementNewResp
  733. }
  734. type DepartmentDetail struct {
  735. DepartmentId int `description:"作者Id"`
  736. NickName string `description:"作者昵称"`
  737. ImgUrl string `description:"图片链接"`
  738. FllowNum int `description:"多少人关注"`
  739. ArticleNum int `description:"文章数量"`
  740. CollectNum int `description:"收藏人数"`
  741. IsFllow bool `description:"是否关注"`
  742. MyFllowNum int `description:"本人是否关注"`
  743. }
  744. // 列表
  745. func GetDepartmentDetail(userId, departmentId int, condition string) (item DepartmentDetail, err error) {
  746. o := orm.NewOrm()
  747. sql := `SELECT
  748. d.department_id,
  749. d.nick_name,
  750. d.img_url,
  751. ( SELECT count( 1 ) FROM cygx_article_department_follow AS af WHERE af.user_id = ? AND af.department_id = d.department_id AND af.type= 1 ) AS my_fllow_num,
  752. ( SELECT count( 1 ) FROM cygx_article_department_follow AS f INNER JOIN wx_user as u ON u.user_id = f.user_id WHERE f.department_id = d.department_id AND f.type= 1 ) AS fllow_num,
  753. ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ` + condition + ` ) AS article_num,
  754. ( SELECT count( 1 ) FROM cygx_article_collect AS c INNER JOIN wx_user as u ON u.user_id = c.user_id WHERE c.article_id IN (SELECT article_id FROM cygx_article AS a WHERE a.department_id = d.department_id ` + condition + ` )) AS collect_num
  755. FROM
  756. cygx_article_department AS d
  757. WHERE
  758. d.department_id = ?`
  759. err = o.Raw(sql, userId, departmentId).QueryRow(&item)
  760. return
  761. } //end
  762. // 报告搜索start
  763. type ReoprtSearchResp struct {
  764. ListYx []*ArticleCollectionResp `description:"研选报告"`
  765. ListHz []*ArticleCollectionResp `description:"弘则报告"`
  766. }
  767. // 列表
  768. func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  769. o := orm.NewOrm()
  770. sql := `SELECT
  771. a.article_id,
  772. a.title,
  773. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  774. m.industry_name,
  775. m.industrial_management_id,
  776. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  777. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  778. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  779. FROM
  780. cygx_article AS a
  781. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  782. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  783. WHERE
  784. 1 = 1 `
  785. if condition != "" {
  786. sql += condition
  787. }
  788. _, err = o.Raw(sql, userId).QueryRows(&items)
  789. return
  790. } //end
  791. // 搜索资源包 start
  792. type SearchResourceResp struct {
  793. ListHz []*IndustrialManagementHotResp `description:"弘则"`
  794. ListYx []*IndustrialManagementHotResp `description:"研选"`
  795. }
  796. // 搜索资源包 start
  797. type SearchReportAndResourceResp struct {
  798. ListHzResource []*IndustrialManagementHotResp `description:"弘则资源包"`
  799. ListYxResource []*IndustrialManagementHotResp `description:"研选资源包"`
  800. ListYxReport []*ArticleCollectionResp `description:"研选报告"`
  801. ListHzReport []*ArticleCollectionResp `description:"弘则报告"`
  802. }
  803. // 产业列表
  804. func GetSearchResourceList(userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  805. o := orm.NewOrm()
  806. sql := `SELECT
  807. m.industry_name,
  808. m.industrial_management_id,
  809. MAX( a.publish_date ) as publish_date_order,
  810. MIN(a.publish_date) AS min_report_time,
  811. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date,
  812. (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
  813. FROM
  814. cygx_industrial_management AS m
  815. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  816. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  817. WHERE
  818. 1 = 1
  819. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  820. if startSize > 0 || pageSize > 0 {
  821. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  822. }
  823. _, err = o.Raw(sql).QueryRows(&items)
  824. return
  825. }
  826. // 切换列表
  827. type ReportBillboardTableResp struct {
  828. Name string `description:"名称"`
  829. Source int `description:"类型"`
  830. List []*ChartPermission
  831. }
  832. // 切换列表
  833. type ReportBillboardTableListResp struct {
  834. List []*ReportBillboardTableResp
  835. }
  836. // 报告榜单start
  837. type ArticleReportBillboardResp struct {
  838. ArticleId int `description:"文章id"`
  839. Title string `description:"标题"`
  840. PublishDate string `description:"发布时间"`
  841. PermissionName string `description:"行业名称"`
  842. DepartmentId int `description:"作者Id"`
  843. NickName string `description:"作者昵称"`
  844. IsCollect bool `description:"本人是否收藏"`
  845. Pv int `description:"PV"`
  846. CollectNum int `description:"收藏人数"`
  847. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  848. IsRoadShow bool `description:"是否是路演精华"`
  849. CategoryId int `description:"分类ID"`
  850. List []*IndustrialManagementIdInt
  851. }
  852. type ArticleReportBillboardLIstResp struct {
  853. List []*ArticleReportBillboardResp
  854. }
  855. type ArticleReportBillboardLIstPageResp struct {
  856. List []*ArticleReportBillboardResp
  857. Paging *paging.PagingItem
  858. }
  859. // 报告收藏榜单列表
  860. func GetReportCollectionBillboardList(limit int, pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  861. o := orm.NewOrm()
  862. sql := `SELECT
  863. ac.id,
  864. a.article_id,
  865. a.title,
  866. date_format(a.publish_date, '%Y-%m-%d') AS publish_date,
  867. m.chart_permission_name AS permission_name,
  868. COUNT(ac.id) AS collection_num
  869. FROM
  870. cygx_article AS a
  871. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  872. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  873. WHERE
  874. 1 = 1
  875. AND a.publish_status = 1 `
  876. if condition != "" {
  877. sql += condition
  878. }
  879. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, ac.id DESC, a.publish_date DESC`
  880. sql += ` LIMIT ?`
  881. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  882. return
  883. }
  884. // 报告阅读榜单列表
  885. func GetReportPvBillboardList(pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  886. o := orm.NewOrm()
  887. sql := `SELECT
  888. a.article_id,
  889. a.title,
  890. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date
  891. FROM
  892. cygx_article AS a
  893. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  894. WHERE
  895. 1 = 1
  896. AND a.publish_status = 1 `
  897. if condition != "" {
  898. sql += condition
  899. }
  900. _, err = o.Raw(sql, pars).QueryRows(&items)
  901. return
  902. }
  903. // 获取产业报告+晨会点评数量
  904. func GetTimeLineReportIndustrialCount(industrialManagementId int) (count int, err error) {
  905. o := orm.NewOrm()
  906. sql := `SELECT SUM(count) AS count FROM (
  907. SELECT
  908. COUNT( 1 ) count
  909. FROM
  910. cygx_article AS a
  911. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  912. WHERE
  913. a.publish_status = 1
  914. AND a.is_class = 1
  915. AND man_g.industrial_management_id = ?
  916. UNION ALL
  917. SELECT
  918. COUNT( 1 ) count
  919. FROM
  920. cygx_morning_meeting_review_chapter AS mmc
  921. INNER JOIN cygx_morning_meeting_reviews AS mm
  922. WHERE
  923. mm.id = mmc.meeting_id
  924. AND mm.status = 1
  925. AND mmc.industry_id = ? ) AS t `
  926. err = o.Raw(sql, industrialManagementId, industrialManagementId).QueryRow(&count)
  927. return
  928. }
  929. type TimeLineReportItem struct {
  930. Id int `description:"文章或晨报点评id"`
  931. Title string `description:"标题"`
  932. PublishTime string `description:"发布时间"`
  933. Content string `description:"内容"`
  934. VideoUrl string `description:"视频链接"`
  935. IsHaveVideo bool `description:"是否包含视频"`
  936. ImgUrlPc string `description:"pc图片"`
  937. SubCategoryName string `description:"二级分类"`
  938. IsRed bool `description:"是否标红"`
  939. Readnum int `description:"阅读数量"`
  940. }
  941. // 获取产业报告+晨会点评列表
  942. func GetTimeLineReportIndustrialList(userId, industrialManagementId, startSize, pageSize int) (items []*TimeLineReportItem, err error) {
  943. o := orm.NewOrm()
  944. sql := `SELECT
  945. *
  946. FROM
  947. (
  948. SELECT
  949. a.article_id AS id,
  950. a.title,
  951. a.publish_date AS publish_time,
  952. a.video_url,
  953. a.sub_category_name,
  954. '' AS content,
  955. ( 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
  956. FROM
  957. cygx_article AS a
  958. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  959. WHERE
  960. a.publish_status = 1
  961. AND a.is_class = 1
  962. AND man_g.industrial_management_id = ? GROUP BY id UNION ALL
  963. SELECT
  964. mmc.id,
  965. '' AS title,
  966. mm.publish_time AS publish_time,
  967. '' AS video_url,
  968. '时间线' AS sub_category_name,
  969. mmc.content,
  970. 0 AS readnum
  971. FROM
  972. cygx_morning_meeting_review_chapter AS mmc
  973. INNER JOIN cygx_morning_meeting_reviews AS mm
  974. WHERE
  975. mm.id = mmc.meeting_id
  976. AND mm.STATUS = 1
  977. AND mmc.industry_id = ?
  978. ) AS t
  979. `
  980. sql += ` ORDER BY
  981. t.publish_time DESC LIMIT ?,? `
  982. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  983. return
  984. }
  985. type ArticleIdReq struct {
  986. ArticleId int `description:"文章id"`
  987. PlaySeconds int `description:"播放时长"`
  988. PageRouter string `description:"页面路径"`
  989. }
  990. type IndustrialReadNum struct {
  991. IndustrialManagementId int `description:"产业id"`
  992. Readnum int `description:"阅读次数"`
  993. }
  994. // 获取该产业下文章的用户阅读次数-小红点用
  995. func GetReportIndustrialReadNumList(userId int, industrialIds string, createtime time.Time) (items []*IndustrialReadNum, err error) {
  996. o := orm.NewOrm()
  997. sql := `SELECT a.industrial_management_id, MIN(a.readnum) AS readnum FROM (
  998. 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
  999. FROM
  1000. cygx_article AS a
  1001. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  1002. WHERE
  1003. a.publish_status = 1
  1004. AND a.is_class = 1
  1005. AND man_g.industrial_management_id IN (` + industrialIds + `)
  1006. AND a.publish_date > ?
  1007. GROUP BY a.article_id ORDER BY publish_date DESC
  1008. ) AS a GROUP BY industrial_management_id`
  1009. _, err = o.Raw(sql, createtime).QueryRows(&items)
  1010. return
  1011. }