report.go 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  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. IsBelongRai bool `description:"是否属于权益内部人员"`
  249. }
  250. type SearchTxt struct {
  251. SummarySearch string `description:"素材库搜索说明"`
  252. ReportSearch string `description:"报告搜索说明"`
  253. YanXuanSearch string `description:"研选搜索说明"`
  254. ActivitySearch string `description:"活动搜索说明"`
  255. TabSearch string `description:"素材库搜索说明"`
  256. }
  257. // 获取用户是否有查看权限
  258. func GetUserIsAdminCount(mobile string) (count int, err error) {
  259. o := orm.NewOrm()
  260. sql := `SELECT COUNT(1) count FROM admin
  261. WHERE
  262. mobile = ?
  263. AND (group_id IN (11, 13, 14, 15, 16, 17) OR department_id = 3 ) AND enabled = 1`
  264. err = o.Raw(sql, mobile).QueryRow(&count)
  265. return
  266. }
  267. type ReportDetailRoadshow struct {
  268. ArticleId int `description:"报告Id"`
  269. Title string `description:"标题"`
  270. Department string `orm:"column(seller_and_mobile)"description:"作者"`
  271. PublishDate string `description:"发布时间"`
  272. VideoUrl string `description:"链接"`
  273. VideoPlaySeconds string `description:"时长"`
  274. VideoName string `description:"音频名称"`
  275. Abstract string `description:"摘要"`
  276. Body string `description:"内容"`
  277. CategoryName string `description:"行业名称"`
  278. ReportLink string `orm:"column(link_article_id)"description:"报告链接"`
  279. IsCollect bool `description:"是否收藏:true,已收藏,false:未收藏"`
  280. IsRoadShow bool `description:"是否是路演精华"`
  281. CategoryId int `description:"文章分类ID"`
  282. VisibleRange int `description:"设置可见范围1全部,0内部"`
  283. }
  284. type RoadshowDetailResp struct {
  285. Detail *ReportDetailRoadshow
  286. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  287. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  288. IsShow bool `description:"是否展示"`
  289. }
  290. func GetReportRoadshowDetailById(articleId int) (item *ReportDetailRoadshow, err error) {
  291. o := orm.NewOrm()
  292. sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
  293. err = o.Raw(sql, articleId).QueryRow(&item)
  294. return
  295. }
  296. type CygxIndustryAndArticleList struct {
  297. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  298. Title string `description:"标题"`
  299. PublishDate string `description:"发布时间"`
  300. IndustryName string `description:"产业名称"`
  301. SubjectName string `description:"标的名称"`
  302. }
  303. type CygxIndustrySearchList struct {
  304. ArtList []*CygxIndustryAndArticleList `description:"文章列表"`
  305. IndList []*IndustrialManagement `description:"产业列表"`
  306. }
  307. type CygxIndustrySearchListPc struct {
  308. DepartmentList []*CygxArticleDepartmentRepPc
  309. IndList []*IndustrialManagement `description:"产业列表"`
  310. }
  311. // 列表
  312. func GetCygxIndustryAndArticleList(keyWord string) (items []*CygxIndustryAndArticleList, err error) {
  313. o := orm.NewOrm()
  314. sql := `SELECT
  315. art.title,
  316. art.article_id,
  317. art.publish_date
  318. FROM
  319. cygx_article AS art
  320. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
  321. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = mg.article_id
  322. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  323. WHERE
  324. category_name LIKE '%研选%'
  325. 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 )
  326. 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 '%研选%' )
  327. GROUP BY
  328. art.article_id`
  329. _, err = o.Raw(sql).QueryRows(&items)
  330. return
  331. }
  332. func GetArticleIdsBySubId(subjectId string) (articleIds string, err error) {
  333. o := orm.NewOrm()
  334. sql := `SELECT GROUP_CONCAT( DISTINCT a.article_id SEPARATOR ',' ) AS articleIds
  335. FROM cygx_article AS a
  336. WHERE subject_ids LIKE '%` + subjectId + `%'`
  337. err = o.Raw(sql).QueryRow(&articleIds)
  338. return
  339. } //end
  340. // 用户收藏榜start
  341. type ArticleCollectionResp struct {
  342. ArticleId int `description:"文章id"`
  343. Title string `description:"标题"`
  344. PublishDate string `description:"发布时间"`
  345. IndustrialManagementId int `description:"产业Id"`
  346. IndustryName string `description:"产业名称"`
  347. DepartmentId int `description:"作者Id"`
  348. NickName string `description:"作者昵称"`
  349. MyCollectNum int `description:"本人是否收藏"`
  350. IsCollect bool `description:"本人是否收藏"`
  351. Pv int `description:"PV"`
  352. CollectNum int `description:"收藏人数"`
  353. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  354. ArticleTypeId int `description:"文章类型ID"`
  355. List []*IndustrialManagementResp `description:"产业列表"`
  356. }
  357. type IndustrialManagementResp struct {
  358. IndustrialManagementId int `description:"产业Id"`
  359. IndustryName string `description:"产业名称"`
  360. ChartPermissionId int `description:"权限id"`
  361. }
  362. type ArticleCollectionLIstResp struct {
  363. List []*ArticleCollectionResp
  364. }
  365. // 研选报告收藏榜单列表
  366. func GetReportCollectionBillboardListYx(limit int, pars []interface{}, condition string) (items []*ArticleCollectionResp, err error) {
  367. o := orm.NewOrm()
  368. sql := `SELECT
  369. ac.id,
  370. a.category_id,
  371. a.article_id,
  372. a.title,
  373. a.body,
  374. a.annotation,
  375. a.abstract,
  376. a.publish_date,
  377. a.article_type_id,
  378. d.nick_name,
  379. d.department_id,
  380. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  381. ( 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,
  382. ( 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
  383. FROM
  384. cygx_article AS a
  385. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  386. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  387. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  388. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  389. WHERE
  390. 1 = 1
  391. AND a.publish_status = 1 `
  392. if condition != "" {
  393. sql += condition
  394. }
  395. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, a.publish_date DESC`
  396. sql += ` LIMIT ?`
  397. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  398. return
  399. }
  400. // 列表
  401. func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  402. o := orm.NewOrm()
  403. sql := `SELECT
  404. a.article_id,
  405. a.title,
  406. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  407. m.industry_name,
  408. m.industrial_management_id,
  409. d.nick_name,
  410. d.department_id,
  411. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  412. ( 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,
  413. ( 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,
  414. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  415. FROM
  416. cygx_article AS a
  417. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  418. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  419. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  420. WHERE
  421. 1 = 1 AND a.publish_status = 1 `
  422. if condition != "" {
  423. sql += condition
  424. }
  425. _, err = o.Raw(sql, userId).QueryRows(&items)
  426. return
  427. } //end
  428. type ArticleResearchListResp struct {
  429. Paging *paging.PagingItem
  430. List []*ArticleResearchResp
  431. }
  432. type ArticleResearchResp struct {
  433. ArticleId int `description:"文章id"`
  434. Title string `description:"标题"`
  435. PublishDate string `description:"发布时间"`
  436. DepartmentId int `description:"作者Id"`
  437. NickName string `description:"作者昵称"`
  438. IsCollect bool `description:"本人是否收藏"`
  439. Pv int `description:"PV"`
  440. CollectNum int `description:"收藏人数"`
  441. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  442. ArticleTypeId int `description:"文章类型ID"`
  443. ArticleTypeName string `description:"类型名称"`
  444. ButtonStyle string `description:"按钮展示样式"`
  445. List []*IndustrialManagementResp `description:"产业列表"`
  446. }
  447. // 获取我的日程数量
  448. func GetArticleResearchCount(condition string, pars []interface{}) (count int, err error) {
  449. o := orm.NewOrm()
  450. sqlCount := `SELECT COUNT( 1 ) AS count FROM
  451. cygx_article AS a
  452. WHERE
  453. 1 = 1 AND a.publish_status = 1` + condition
  454. err = o.Raw(sqlCount, pars).QueryRow(&count)
  455. return
  456. }
  457. func GetArticleResearchList(condition string, pars []interface{}, startSize, pageSize, userId int) (items []*ArticleCollectionResp, err error) {
  458. o := orm.NewOrm()
  459. sql := `SELECT
  460. a.article_id,
  461. a.title,
  462. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  463. a.article_type_id,
  464. d.nick_name,
  465. d.department_id,
  466. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  467. ( 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,
  468. ( 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,
  469. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  470. FROM
  471. cygx_article AS a
  472. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  473. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  474. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  475. WHERE
  476. 1 = 1 AND a.publish_status = 1 `
  477. if condition != "" {
  478. sql += condition
  479. }
  480. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  481. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  482. return
  483. }
  484. // 用户收藏榜start
  485. type IndustrialManagementHotResp struct {
  486. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  487. IndustryName string `description:"产业名称"`
  488. IsFollw bool `description:"是否关注"`
  489. FllowNum int `description:"关注数量"`
  490. IsNew bool `description:"是否新标签"`
  491. IsHot bool `description:"是否新标签"`
  492. IsRed bool `description:"是否标记红点"`
  493. Readnum int `description:"阅读数量"`
  494. PublishDate string `description:"发布时间"`
  495. MinReportTime string `description:"报告最早发布时间"`
  496. ArticleReadNum int `description:"文章阅读数量"`
  497. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  498. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  499. IndustryVideo *MicroVideoSimpleInfo `description:"产业视频"`
  500. AuthInfo *UserPermissionAuthInfo
  501. }
  502. type IndustrialManagementHotListResp struct {
  503. Paging *paging.PagingItem `description:"分页数据"`
  504. List []*IndustrialManagementHotResp
  505. }
  506. // 产业列表
  507. func GetThemeHeatList(userId int, condition, conditionOrder string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  508. o := orm.NewOrm()
  509. sql := `SELECT
  510. m.industry_name,
  511. m.industrial_management_id,
  512. m.article_read_num,
  513. MAX( a.publish_date ) AS publish_date,
  514. MIN(a.publish_date) AS min_report_time,
  515. ( 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,
  516. m.yanxuan_article_read_num + m.activity_num AS sum_num
  517. FROM
  518. cygx_industrial_management AS m
  519. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  520. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  521. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  522. WHERE
  523. 1 = 1
  524. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  525. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  526. return
  527. }
  528. // 获取数量
  529. func GetThemeHeatListCount(condition string) (count int, err error) {
  530. o := orm.NewOrm()
  531. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  532. cygx_industrial_management AS m
  533. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  534. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  535. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  536. WHERE
  537. 1 = 1
  538. AND a.publish_status = 1 ` + condition
  539. err = o.Raw(sql).QueryRow(&count)
  540. return
  541. }
  542. // 标的列表
  543. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  544. o := orm.NewOrm()
  545. sql := `SELECT
  546. m.subject_name,
  547. m.industrial_management_id,
  548. m.industrial_subject_id
  549. FROM
  550. cygx_article AS a
  551. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  552. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  553. WHERE
  554. 1 = 1`
  555. if condition != "" {
  556. sql += condition
  557. }
  558. sql += ` AND publish_status = 1
  559. GROUP BY
  560. m.industrial_subject_id
  561. ORDER BY
  562. publish_date DESC`
  563. _, err = o.Raw(sql).QueryRows(&items)
  564. return
  565. } //end
  566. // Kol sratr
  567. type DepartmentResp struct {
  568. DepartmentId int `description:"作者Id"`
  569. NickName string `description:"作者昵称"`
  570. ImgUrl string `description:"图片链接"`
  571. IsFollw bool `description:"是否关注"`
  572. IsHot bool `description:"是否关注"`
  573. FllowNum int `description:"关注数量"`
  574. List []*IndustrialDepartmentListResp
  575. }
  576. type DepartmentListResp struct {
  577. Paging *paging.PagingItem `description:"分页数据"`
  578. List []*DepartmentResp
  579. }
  580. type IndustrialDepartmentListResp struct {
  581. IndustrialManagementId int `description:"产业Id"`
  582. IndustryName string `description:"产业名称"`
  583. DepartmentId int `description:"作者Id"`
  584. }
  585. // 作者列表
  586. func GetDepartmentList(condition, conditionOrder string, userId, startSize, pageSize int) (items []*DepartmentResp, err error) {
  587. o := orm.NewOrm()
  588. sql := `SELECT
  589. d.nick_name,
  590. d.department_id,
  591. d.img_url,
  592. MAX( a.publish_date ) AS publish_date,
  593. ( 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,
  594. ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.type= 1 ) AS sum_num
  595. FROM
  596. cygx_article_department AS d
  597. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  598. WHERE
  599. 1 = 1
  600. AND publish_status = 1 ` + condition + `
  601. GROUP BY
  602. d.department_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  603. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  604. return
  605. }
  606. // 获取数量
  607. func GetDepartmentlistCount(condition string) (count int, err error) {
  608. o := orm.NewOrm()
  609. sql := `SELECT
  610. count(*) AS count
  611. FROM
  612. (
  613. SELECT
  614. COUNT( 1 ) AS count
  615. FROM
  616. cygx_article_department AS d
  617. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  618. WHERE
  619. 1 = 1
  620. AND a.article_type_id > 0
  621. AND publish_status = 1
  622. GROUP BY
  623. d.department_id
  624. ) c `
  625. err = o.Raw(sql).QueryRow(&count)
  626. return
  627. }
  628. // 作者文章所关联的产业列表
  629. func GetIndustrialDepartmentList() (items []*IndustrialDepartmentListResp, err error) {
  630. o := orm.NewOrm()
  631. sql := `SELECT
  632. m.industrial_management_id,
  633. m.industry_name,
  634. d.department_id
  635. FROM
  636. cygx_article_department AS d
  637. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  638. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  639. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  640. WHERE
  641. 1 = 1
  642. AND a.article_type_id > 0
  643. AND publish_status = 1
  644. ORDER BY
  645. a.publish_date DESC`
  646. _, err = o.Raw(sql).QueryRows(&items)
  647. return
  648. }
  649. // 主题详情start
  650. type GetThemeDetailListResp struct {
  651. ArticleId int `description:"文章id"`
  652. Title string `description:"标题"`
  653. PublishDate string `description:"发布时间"`
  654. SubjectName string `description:"标的名称"`
  655. IndustrialSubjectId int `description:"标的id"`
  656. DepartmentId int `description:"作者Id"`
  657. NickName string `description:"作者昵称"`
  658. Pv int `description:"PV"`
  659. CollectNum int `description:"收藏人数"`
  660. IndustrialManagementId int `description:"产业Id"`
  661. IndustryName string `description:"产业名称"`
  662. FllowNum int `description:"关注数量"`
  663. MyCollectNum int `description:"本人是否收藏"`
  664. IsCollect bool `description:"本人是否收藏"`
  665. }
  666. type GetThemeAericleListResp struct {
  667. ArticleId int `description:"文章id"`
  668. Title string `description:"标题"`
  669. PublishDate string `description:"发布时间"`
  670. SubjectName string `description:"标的名称"`
  671. IndustrialSubjectId int `description:"标的ID"`
  672. DepartmentId int `description:"作者Id"`
  673. NickName string `description:"作者昵称"`
  674. Pv int `description:"PV"`
  675. CollectNum int `description:"收藏人数"`
  676. FllowNum int `description:"关注数量"`
  677. MyCollectNum int `description:"本人是否收藏"`
  678. IsCollect bool `description:"本人是否收藏"`
  679. }
  680. type GetThemeAericleListBuSubjectResp struct {
  681. SubjectName string `description:"标的名称"`
  682. List []*GetThemeAericleListResp
  683. }
  684. // 主题详情start
  685. type GetThemeDetailResp struct {
  686. IndustrialManagementId int `description:"产业Id"`
  687. IndustryName string `description:"产业名称"`
  688. IsFollw bool `description:"是否关注"`
  689. ListSubject []*IndustrialSubject `description:"标的列表"`
  690. List []*GetThemeAericleListResp
  691. }
  692. // 列表
  693. func GetThemeDetail(userId, industrialManagementId int, condition string) (items []*GetThemeDetailListResp, err error) {
  694. o := orm.NewOrm()
  695. sql := `SELECT
  696. a.article_id,
  697. a.title,
  698. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  699. m.industry_name,
  700. m.industrial_management_id,
  701. d.nick_name,
  702. d.department_id,
  703. s.industrial_subject_id,
  704. s.subject_name,
  705. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  706. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  707. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num,
  708. ( 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
  709. FROM
  710. cygx_article AS a
  711. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  712. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  713. LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
  714. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
  715. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  716. WHERE
  717. 1 = 1
  718. AND m.industrial_management_id = ?
  719. AND publish_status = 1 ` + condition + ` GROUP BY article_id
  720. ORDER BY
  721. publish_date DESC`
  722. _, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)
  723. return
  724. } //end
  725. // 用户收藏榜start
  726. type DepartmentDetailResp struct {
  727. DepartmentId int `description:"作者Id"`
  728. NickName string `description:"作者昵称"`
  729. ImgUrl string `description:"图片链接"`
  730. FllowNum int `description:"多少人关注"`
  731. ArticleNum int `description:"文章数量"`
  732. CollectNum int `description:"收藏人数"`
  733. IsFllow bool `description:"是否关注"`
  734. List []*ArticleCollectionResp
  735. ListIndustrial []*IndustrialManagementNewResp
  736. }
  737. type DepartmentDetail struct {
  738. DepartmentId int `description:"作者Id"`
  739. NickName string `description:"作者昵称"`
  740. ImgUrl string `description:"图片链接"`
  741. FllowNum int `description:"多少人关注"`
  742. ArticleNum int `description:"文章数量"`
  743. CollectNum int `description:"收藏人数"`
  744. IsFllow bool `description:"是否关注"`
  745. MyFllowNum int `description:"本人是否关注"`
  746. }
  747. // 列表
  748. func GetDepartmentDetail(userId, departmentId int, condition string) (item DepartmentDetail, err error) {
  749. o := orm.NewOrm()
  750. sql := `SELECT
  751. d.department_id,
  752. d.nick_name,
  753. d.img_url,
  754. ( 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,
  755. ( 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,
  756. ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ` + condition + ` ) AS article_num,
  757. ( 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
  758. FROM
  759. cygx_article_department AS d
  760. WHERE
  761. d.department_id = ?`
  762. err = o.Raw(sql, userId, departmentId).QueryRow(&item)
  763. return
  764. } //end
  765. // 报告搜索start
  766. type ReoprtSearchResp struct {
  767. ListYx []*ArticleCollectionResp `description:"研选报告"`
  768. ListHz []*ArticleCollectionResp `description:"弘则报告"`
  769. }
  770. // 列表
  771. func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  772. o := orm.NewOrm()
  773. sql := `SELECT
  774. a.article_id,
  775. a.title,
  776. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  777. m.industry_name,
  778. m.industrial_management_id,
  779. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  780. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  781. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  782. FROM
  783. cygx_article AS a
  784. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  785. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  786. WHERE
  787. 1 = 1 `
  788. if condition != "" {
  789. sql += condition
  790. }
  791. _, err = o.Raw(sql, userId).QueryRows(&items)
  792. return
  793. } //end
  794. // 搜索资源包 start
  795. type SearchResourceResp struct {
  796. ListHz []*IndustrialManagementHotResp `description:"弘则"`
  797. ListYx []*IndustrialManagementHotResp `description:"研选"`
  798. }
  799. // 搜索资源包 start
  800. type SearchReportAndResourceResp struct {
  801. ListHzResource []*IndustrialManagementHotResp `description:"弘则资源包"`
  802. ListYxResource []*IndustrialManagementHotResp `description:"研选资源包"`
  803. ListYxReport []*ArticleCollectionResp `description:"研选报告"`
  804. ListHzReport []*ArticleCollectionResp `description:"弘则报告"`
  805. }
  806. // 产业列表
  807. func GetSearchResourceList(userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  808. o := orm.NewOrm()
  809. sql := `SELECT
  810. m.industry_name,
  811. m.industrial_management_id,
  812. MAX( a.publish_date ) as publish_date_order,
  813. MIN(a.publish_date) AS min_report_time,
  814. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date,
  815. (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
  816. FROM
  817. cygx_industrial_management AS m
  818. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  819. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  820. WHERE
  821. 1 = 1
  822. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  823. if startSize > 0 || pageSize > 0 {
  824. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  825. }
  826. _, err = o.Raw(sql).QueryRows(&items)
  827. return
  828. }
  829. // 切换列表
  830. type ReportBillboardTableResp struct {
  831. Name string `description:"名称"`
  832. Source int `description:"类型"`
  833. List []*ChartPermission
  834. }
  835. // 切换列表
  836. type ReportBillboardTableListResp struct {
  837. List []*ReportBillboardTableResp
  838. }
  839. // 报告榜单start
  840. type ArticleReportBillboardResp struct {
  841. ArticleId int `description:"文章id"`
  842. Title string `description:"标题"`
  843. PublishDate string `description:"发布时间"`
  844. PermissionName string `description:"行业名称"`
  845. DepartmentId int `description:"作者Id"`
  846. NickName string `description:"作者昵称"`
  847. IsCollect bool `description:"本人是否收藏"`
  848. Pv int `description:"PV"`
  849. CollectNum int `description:"收藏人数"`
  850. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  851. IsRoadShow bool `description:"是否是路演精华"`
  852. CategoryId int `description:"分类ID"`
  853. List []*IndustrialManagementIdInt
  854. }
  855. type ArticleReportBillboardLIstResp struct {
  856. List []*ArticleReportBillboardResp
  857. }
  858. type ArticleReportBillboardLIstPageResp struct {
  859. List []*ArticleReportBillboardResp
  860. Paging *paging.PagingItem
  861. }
  862. // 报告收藏榜单列表
  863. func GetReportCollectionBillboardList(limit int, pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  864. o := orm.NewOrm()
  865. sql := `SELECT
  866. ac.id,
  867. a.article_id,
  868. a.title,
  869. date_format(a.publish_date, '%Y-%m-%d') AS publish_date,
  870. m.chart_permission_name AS permission_name,
  871. COUNT(ac.id) AS collection_num
  872. FROM
  873. cygx_article AS a
  874. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  875. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  876. WHERE
  877. 1 = 1
  878. AND a.publish_status = 1 `
  879. if condition != "" {
  880. sql += condition
  881. }
  882. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, ac.id DESC, a.publish_date DESC`
  883. sql += ` LIMIT ?`
  884. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  885. return
  886. }
  887. // 报告阅读榜单列表
  888. func GetReportPvBillboardList(pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  889. o := orm.NewOrm()
  890. sql := `SELECT
  891. a.article_id,
  892. a.title,
  893. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date
  894. FROM
  895. cygx_article AS a
  896. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  897. WHERE
  898. 1 = 1
  899. AND a.publish_status = 1 `
  900. if condition != "" {
  901. sql += condition
  902. }
  903. _, err = o.Raw(sql, pars).QueryRows(&items)
  904. return
  905. }
  906. // 获取产业报告+晨会点评数量
  907. func GetTimeLineReportIndustrialCount(industrialManagementId int) (count int, err error) {
  908. o := orm.NewOrm()
  909. sql := `SELECT SUM(count) AS count FROM (
  910. SELECT
  911. COUNT( 1 ) count
  912. FROM
  913. cygx_article AS a
  914. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  915. WHERE
  916. a.publish_status = 1
  917. AND a.is_class = 1
  918. AND man_g.industrial_management_id = ?
  919. UNION ALL
  920. SELECT
  921. COUNT( 1 ) count
  922. FROM
  923. cygx_morning_meeting_review_chapter AS mmc
  924. INNER JOIN cygx_morning_meeting_reviews AS mm
  925. WHERE
  926. mm.id = mmc.meeting_id
  927. AND mm.status = 1
  928. AND mmc.industry_id = ? ) AS t `
  929. err = o.Raw(sql, industrialManagementId, industrialManagementId).QueryRow(&count)
  930. return
  931. }
  932. type TimeLineReportItem struct {
  933. Id int `description:"文章或晨报点评id"`
  934. Title string `description:"标题"`
  935. PublishTime string `description:"发布时间"`
  936. Content string `description:"内容"`
  937. VideoUrl string `description:"视频链接"`
  938. IsHaveVideo bool `description:"是否包含视频"`
  939. ImgUrlPc string `description:"pc图片"`
  940. SubCategoryName string `description:"二级分类"`
  941. IsRed bool `description:"是否标红"`
  942. Readnum int `description:"阅读数量"`
  943. }
  944. // 获取产业报告+晨会点评列表
  945. func GetTimeLineReportIndustrialList(userId, industrialManagementId, startSize, pageSize int) (items []*TimeLineReportItem, err error) {
  946. o := orm.NewOrm()
  947. sql := `SELECT
  948. *
  949. FROM
  950. (
  951. SELECT
  952. a.article_id AS id,
  953. a.title,
  954. a.publish_date AS publish_time,
  955. a.video_url,
  956. a.sub_category_name,
  957. '' AS content,
  958. ( 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
  959. FROM
  960. cygx_article AS a
  961. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  962. WHERE
  963. a.publish_status = 1
  964. AND a.is_class = 1
  965. AND man_g.industrial_management_id = ? GROUP BY id UNION ALL
  966. SELECT
  967. mmc.id,
  968. '' AS title,
  969. mm.publish_time AS publish_time,
  970. '' AS video_url,
  971. '时间线' AS sub_category_name,
  972. mmc.content,
  973. 0 AS readnum
  974. FROM
  975. cygx_morning_meeting_review_chapter AS mmc
  976. INNER JOIN cygx_morning_meeting_reviews AS mm
  977. WHERE
  978. mm.id = mmc.meeting_id
  979. AND mm.STATUS = 1
  980. AND mmc.industry_id = ?
  981. ) AS t
  982. `
  983. sql += ` ORDER BY
  984. t.publish_time DESC LIMIT ?,? `
  985. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  986. return
  987. }
  988. type ArticleIdReq struct {
  989. ArticleId int `description:"文章id"`
  990. PlaySeconds int `description:"播放时长"`
  991. PageRouter string `description:"页面路径"`
  992. }
  993. type IndustrialReadNum struct {
  994. IndustrialManagementId int `description:"产业id"`
  995. Readnum int `description:"阅读次数"`
  996. }
  997. // 获取该产业下文章的用户阅读次数-小红点用
  998. func GetReportIndustrialReadNumList(userId int, industrialIds string, createtime time.Time) (items []*IndustrialReadNum, err error) {
  999. o := orm.NewOrm()
  1000. sql := `SELECT a.industrial_management_id, MIN(a.readnum) AS readnum FROM (
  1001. 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
  1002. FROM
  1003. cygx_article AS a
  1004. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  1005. WHERE
  1006. a.publish_status = 1
  1007. AND a.is_class = 1
  1008. AND man_g.industrial_management_id IN (` + industrialIds + `)
  1009. AND a.publish_date > ?
  1010. GROUP BY a.article_id ORDER BY publish_date DESC
  1011. ) AS a GROUP BY industrial_management_id`
  1012. _, err = o.Raw(sql, createtime).QueryRows(&items)
  1013. return
  1014. }