report.go 45 KB

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