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. VisibleRange int `description:"设置可见范围1全部,0内部"`
  279. }
  280. type RoadshowDetailResp struct {
  281. Detail *ReportDetailRoadshow
  282. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  283. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  284. IsShow bool `description:"是否展示"`
  285. }
  286. func GetReportRoadshowDetailById(articleId int) (item *ReportDetailRoadshow, err error) {
  287. o := orm.NewOrm()
  288. sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
  289. err = o.Raw(sql, articleId).QueryRow(&item)
  290. return
  291. }
  292. type CygxIndustryAndArticleList struct {
  293. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  294. Title string `description:"标题"`
  295. PublishDate string `description:"发布时间"`
  296. IndustryName string `description:"产业名称"`
  297. SubjectName string `description:"标的名称"`
  298. }
  299. type CygxIndustrySearchList struct {
  300. ArtList []*CygxIndustryAndArticleList `description:"文章列表"`
  301. IndList []*IndustrialManagement `description:"产业列表"`
  302. }
  303. type CygxIndustrySearchListPc struct {
  304. DepartmentList []*CygxArticleDepartmentRepPc
  305. IndList []*IndustrialManagement `description:"产业列表"`
  306. }
  307. // 列表
  308. func GetCygxIndustryAndArticleList(keyWord string) (items []*CygxIndustryAndArticleList, err error) {
  309. o := orm.NewOrm()
  310. sql := `SELECT
  311. art.title,
  312. art.article_id,
  313. art.publish_date
  314. FROM
  315. cygx_article AS art
  316. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
  317. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = mg.article_id
  318. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  319. WHERE
  320. category_name LIKE '%研选%'
  321. 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 )
  322. 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 '%研选%' )
  323. GROUP BY
  324. art.article_id`
  325. _, err = o.Raw(sql).QueryRows(&items)
  326. return
  327. }
  328. func GetArticleIdsBySubId(subjectId string) (articleIds string, err error) {
  329. o := orm.NewOrm()
  330. sql := `SELECT GROUP_CONCAT( DISTINCT a.article_id SEPARATOR ',' ) AS articleIds
  331. FROM cygx_article AS a
  332. WHERE subject_ids LIKE '%` + subjectId + `%'`
  333. err = o.Raw(sql).QueryRow(&articleIds)
  334. return
  335. } //end
  336. // 用户收藏榜start
  337. type ArticleCollectionResp struct {
  338. ArticleId int `description:"文章id"`
  339. Title string `description:"标题"`
  340. PublishDate string `description:"发布时间"`
  341. IndustrialManagementId int `description:"产业Id"`
  342. IndustryName string `description:"产业名称"`
  343. DepartmentId int `description:"作者Id"`
  344. NickName string `description:"作者昵称"`
  345. MyCollectNum int `description:"本人是否收藏"`
  346. IsCollect bool `description:"本人是否收藏"`
  347. Pv int `description:"PV"`
  348. CollectNum int `description:"收藏人数"`
  349. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  350. ArticleTypeId int `description:"文章类型ID"`
  351. List []*IndustrialManagementResp `description:"产业列表"`
  352. }
  353. type IndustrialManagementResp struct {
  354. IndustrialManagementId int `description:"产业Id"`
  355. IndustryName string `description:"产业名称"`
  356. ChartPermissionId int `description:"权限id"`
  357. }
  358. type ArticleCollectionLIstResp struct {
  359. List []*ArticleCollectionResp
  360. }
  361. // 研选报告收藏榜单列表
  362. func GetReportCollectionBillboardListYx(limit int, pars []interface{}, condition string) (items []*ArticleCollectionResp, err error) {
  363. o := orm.NewOrm()
  364. sql := `SELECT
  365. ac.id,
  366. a.category_id,
  367. a.article_id,
  368. a.title,
  369. a.body,
  370. a.annotation,
  371. a.abstract,
  372. a.publish_date,
  373. a.article_type_id,
  374. d.nick_name,
  375. d.department_id,
  376. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  377. ( 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,
  378. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collection_num
  379. FROM
  380. cygx_article AS a
  381. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  382. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  383. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  384. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  385. WHERE
  386. 1 = 1
  387. AND a.publish_status = 1 `
  388. if condition != "" {
  389. sql += condition
  390. }
  391. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, a.publish_date DESC`
  392. sql += ` LIMIT ?`
  393. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  394. return
  395. }
  396. // 列表
  397. func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  398. o := orm.NewOrm()
  399. sql := `SELECT
  400. a.article_id,
  401. a.title,
  402. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  403. m.industry_name,
  404. m.industrial_management_id,
  405. d.nick_name,
  406. d.department_id,
  407. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  408. ( 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,
  409. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  410. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  411. FROM
  412. cygx_article AS a
  413. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  414. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  415. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  416. WHERE
  417. 1 = 1 AND a.publish_status = 1 `
  418. if condition != "" {
  419. sql += condition
  420. }
  421. _, err = o.Raw(sql, userId).QueryRows(&items)
  422. return
  423. } //end
  424. type ArticleResearchListResp struct {
  425. Paging *paging.PagingItem
  426. List []*ArticleResearchResp
  427. }
  428. type ArticleResearchResp struct {
  429. ArticleId int `description:"文章id"`
  430. Title string `description:"标题"`
  431. PublishDate string `description:"发布时间"`
  432. DepartmentId int `description:"作者Id"`
  433. NickName string `description:"作者昵称"`
  434. IsCollect bool `description:"本人是否收藏"`
  435. Pv int `description:"PV"`
  436. CollectNum int `description:"收藏人数"`
  437. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  438. ArticleTypeId int `description:"文章类型ID"`
  439. ArticleTypeName string `description:"类型名称"`
  440. ButtonStyle string `description:"按钮展示样式"`
  441. List []*IndustrialManagementResp `description:"产业列表"`
  442. }
  443. // 获取我的日程数量
  444. func GetArticleResearchCount(condition string, pars []interface{}) (count int, err error) {
  445. o := orm.NewOrm()
  446. sqlCount := `SELECT COUNT( 1 ) AS count FROM
  447. cygx_article AS a
  448. WHERE
  449. 1 = 1 AND a.publish_status = 1` + condition
  450. err = o.Raw(sqlCount, pars).QueryRow(&count)
  451. return
  452. }
  453. func GetArticleResearchList(condition string, pars []interface{}, startSize, pageSize, userId int) (items []*ArticleCollectionResp, err error) {
  454. o := orm.NewOrm()
  455. sql := `SELECT
  456. a.article_id,
  457. a.title,
  458. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  459. a.article_type_id,
  460. d.nick_name,
  461. d.department_id,
  462. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  463. ( 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,
  464. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  465. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  466. FROM
  467. cygx_article AS a
  468. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  469. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  470. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  471. WHERE
  472. 1 = 1 AND a.publish_status = 1 `
  473. if condition != "" {
  474. sql += condition
  475. }
  476. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  477. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  478. return
  479. }
  480. // 用户收藏榜start
  481. type IndustrialManagementHotResp struct {
  482. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  483. IndustryName string `description:"产业名称"`
  484. IsFollw bool `description:"是否关注"`
  485. FllowNum int `description:"关注数量"`
  486. IsNew bool `description:"是否新标签"`
  487. IsHot bool `description:"是否新标签"`
  488. IsRed bool `description:"是否标记红点"`
  489. Readnum int `description:"阅读数量"`
  490. PublishDate string `description:"发布时间"`
  491. MinReportTime string `description:"报告最早发布时间"`
  492. ArticleReadNum int `description:"文章阅读数量"`
  493. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  494. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  495. IndustryVideo *MicroVideoSimpleInfo `description:"产业视频"`
  496. AuthInfo *UserPermissionAuthInfo
  497. }
  498. type IndustrialManagementHotListResp struct {
  499. Paging *paging.PagingItem `description:"分页数据"`
  500. List []*IndustrialManagementHotResp
  501. }
  502. // 产业列表
  503. func GetThemeHeatList(userId int, condition, conditionOrder string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  504. o := orm.NewOrm()
  505. sql := `SELECT
  506. m.industry_name,
  507. m.industrial_management_id,
  508. m.article_read_num,
  509. MAX( a.publish_date ) AS publish_date,
  510. MIN(a.publish_date) AS min_report_time,
  511. ( 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,
  512. m.yanxuan_article_read_num + m.activity_num AS sum_num
  513. FROM
  514. cygx_industrial_management AS m
  515. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  516. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  517. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  518. WHERE
  519. 1 = 1
  520. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  521. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  522. return
  523. }
  524. // 获取数量
  525. func GetThemeHeatListCount(condition string) (count int, err error) {
  526. o := orm.NewOrm()
  527. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  528. cygx_industrial_management AS m
  529. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  530. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  531. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  532. WHERE
  533. 1 = 1
  534. AND a.publish_status = 1 ` + condition
  535. err = o.Raw(sql).QueryRow(&count)
  536. return
  537. }
  538. // 标的列表
  539. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  540. o := orm.NewOrm()
  541. sql := `SELECT
  542. m.subject_name,
  543. m.industrial_management_id,
  544. m.industrial_subject_id
  545. FROM
  546. cygx_article AS a
  547. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  548. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  549. WHERE
  550. 1 = 1`
  551. if condition != "" {
  552. sql += condition
  553. }
  554. sql += ` AND publish_status = 1
  555. GROUP BY
  556. m.industrial_subject_id
  557. ORDER BY
  558. publish_date DESC`
  559. _, err = o.Raw(sql).QueryRows(&items)
  560. return
  561. } //end
  562. // Kol sratr
  563. type DepartmentResp struct {
  564. DepartmentId int `description:"作者Id"`
  565. NickName string `description:"作者昵称"`
  566. ImgUrl string `description:"图片链接"`
  567. IsFollw bool `description:"是否关注"`
  568. IsHot bool `description:"是否关注"`
  569. FllowNum int `description:"关注数量"`
  570. List []*IndustrialDepartmentListResp
  571. }
  572. type DepartmentListResp struct {
  573. Paging *paging.PagingItem `description:"分页数据"`
  574. List []*DepartmentResp
  575. }
  576. type IndustrialDepartmentListResp struct {
  577. IndustrialManagementId int `description:"产业Id"`
  578. IndustryName string `description:"产业名称"`
  579. DepartmentId int `description:"作者Id"`
  580. }
  581. // 作者列表
  582. func GetDepartmentList(condition, conditionOrder string, userId, startSize, pageSize int) (items []*DepartmentResp, err error) {
  583. o := orm.NewOrm()
  584. sql := `SELECT
  585. d.nick_name,
  586. d.department_id,
  587. d.img_url,
  588. MAX( a.publish_date ) AS publish_date,
  589. ( 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,
  590. ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.type= 1 ) AS sum_num
  591. FROM
  592. cygx_article_department AS d
  593. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  594. WHERE
  595. 1 = 1
  596. AND publish_status = 1 ` + condition + `
  597. GROUP BY
  598. d.department_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  599. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  600. return
  601. }
  602. // 获取数量
  603. func GetDepartmentlistCount(condition string) (count int, err error) {
  604. o := orm.NewOrm()
  605. sql := `SELECT
  606. count(*) AS count
  607. FROM
  608. (
  609. SELECT
  610. COUNT( 1 ) AS count
  611. FROM
  612. cygx_article_department AS d
  613. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  614. WHERE
  615. 1 = 1
  616. AND a.article_type_id > 0
  617. AND publish_status = 1
  618. GROUP BY
  619. d.department_id
  620. ) c `
  621. err = o.Raw(sql).QueryRow(&count)
  622. return
  623. }
  624. // 作者文章所关联的产业列表
  625. func GetIndustrialDepartmentList() (items []*IndustrialDepartmentListResp, err error) {
  626. o := orm.NewOrm()
  627. sql := `SELECT
  628. m.industrial_management_id,
  629. m.industry_name,
  630. d.department_id
  631. FROM
  632. cygx_article_department AS d
  633. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  634. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  635. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  636. WHERE
  637. 1 = 1
  638. AND a.article_type_id > 0
  639. AND publish_status = 1
  640. ORDER BY
  641. a.publish_date DESC`
  642. _, err = o.Raw(sql).QueryRows(&items)
  643. return
  644. }
  645. // 主题详情start
  646. type GetThemeDetailListResp struct {
  647. ArticleId int `description:"文章id"`
  648. Title string `description:"标题"`
  649. PublishDate string `description:"发布时间"`
  650. SubjectName string `description:"标的名称"`
  651. IndustrialSubjectId int `description:"标的id"`
  652. DepartmentId int `description:"作者Id"`
  653. NickName string `description:"作者昵称"`
  654. Pv int `description:"PV"`
  655. CollectNum int `description:"收藏人数"`
  656. IndustrialManagementId int `description:"产业Id"`
  657. IndustryName string `description:"产业名称"`
  658. FllowNum int `description:"关注数量"`
  659. MyCollectNum int `description:"本人是否收藏"`
  660. IsCollect bool `description:"本人是否收藏"`
  661. }
  662. type GetThemeAericleListResp struct {
  663. ArticleId int `description:"文章id"`
  664. Title string `description:"标题"`
  665. PublishDate string `description:"发布时间"`
  666. SubjectName string `description:"标的名称"`
  667. IndustrialSubjectId int `description:"标的ID"`
  668. DepartmentId int `description:"作者Id"`
  669. NickName string `description:"作者昵称"`
  670. Pv int `description:"PV"`
  671. CollectNum int `description:"收藏人数"`
  672. FllowNum int `description:"关注数量"`
  673. MyCollectNum int `description:"本人是否收藏"`
  674. IsCollect bool `description:"本人是否收藏"`
  675. }
  676. type GetThemeAericleListBuSubjectResp struct {
  677. SubjectName string `description:"标的名称"`
  678. List []*GetThemeAericleListResp
  679. }
  680. // 主题详情start
  681. type GetThemeDetailResp struct {
  682. IndustrialManagementId int `description:"产业Id"`
  683. IndustryName string `description:"产业名称"`
  684. IsFollw bool `description:"是否关注"`
  685. ListSubject []*IndustrialSubject `description:"标的列表"`
  686. List []*GetThemeAericleListResp
  687. }
  688. // 列表
  689. func GetThemeDetail(userId, industrialManagementId int, condition string) (items []*GetThemeDetailListResp, err error) {
  690. o := orm.NewOrm()
  691. sql := `SELECT
  692. a.article_id,
  693. a.title,
  694. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  695. m.industry_name,
  696. m.industrial_management_id,
  697. d.nick_name,
  698. d.department_id,
  699. s.industrial_subject_id,
  700. s.subject_name,
  701. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  702. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  703. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num,
  704. ( 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
  705. FROM
  706. cygx_article AS a
  707. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  708. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  709. LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
  710. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
  711. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  712. WHERE
  713. 1 = 1
  714. AND m.industrial_management_id = ?
  715. AND publish_status = 1 ` + condition + ` GROUP BY article_id
  716. ORDER BY
  717. publish_date DESC`
  718. _, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)
  719. return
  720. } //end
  721. // 用户收藏榜start
  722. type DepartmentDetailResp struct {
  723. DepartmentId int `description:"作者Id"`
  724. NickName string `description:"作者昵称"`
  725. ImgUrl string `description:"图片链接"`
  726. FllowNum int `description:"多少人关注"`
  727. ArticleNum int `description:"文章数量"`
  728. CollectNum int `description:"收藏人数"`
  729. IsFllow bool `description:"是否关注"`
  730. List []*ArticleCollectionResp
  731. ListIndustrial []*IndustrialManagementNewResp
  732. }
  733. type DepartmentDetail struct {
  734. DepartmentId int `description:"作者Id"`
  735. NickName string `description:"作者昵称"`
  736. ImgUrl string `description:"图片链接"`
  737. FllowNum int `description:"多少人关注"`
  738. ArticleNum int `description:"文章数量"`
  739. CollectNum int `description:"收藏人数"`
  740. IsFllow bool `description:"是否关注"`
  741. MyFllowNum int `description:"本人是否关注"`
  742. }
  743. // 列表
  744. func GetDepartmentDetail(userId, departmentId int, condition string) (item DepartmentDetail, err error) {
  745. o := orm.NewOrm()
  746. sql := `SELECT
  747. d.department_id,
  748. d.nick_name,
  749. d.img_url,
  750. ( 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,
  751. ( 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,
  752. ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ` + condition + ` ) AS article_num,
  753. ( 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
  754. FROM
  755. cygx_article_department AS d
  756. WHERE
  757. d.department_id = ?`
  758. err = o.Raw(sql, userId, departmentId).QueryRow(&item)
  759. return
  760. } //end
  761. // 报告搜索start
  762. type ReoprtSearchResp struct {
  763. ListYx []*ArticleCollectionResp `description:"研选报告"`
  764. ListHz []*ArticleCollectionResp `description:"弘则报告"`
  765. }
  766. // 列表
  767. func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  768. o := orm.NewOrm()
  769. sql := `SELECT
  770. a.article_id,
  771. a.title,
  772. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  773. m.industry_name,
  774. m.industrial_management_id,
  775. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  776. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  777. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  778. FROM
  779. cygx_article AS a
  780. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  781. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  782. WHERE
  783. 1 = 1 `
  784. if condition != "" {
  785. sql += condition
  786. }
  787. _, err = o.Raw(sql, userId).QueryRows(&items)
  788. return
  789. } //end
  790. // 搜索资源包 start
  791. type SearchResourceResp struct {
  792. ListHz []*IndustrialManagementHotResp `description:"弘则"`
  793. ListYx []*IndustrialManagementHotResp `description:"研选"`
  794. }
  795. // 搜索资源包 start
  796. type SearchReportAndResourceResp struct {
  797. ListHzResource []*IndustrialManagementHotResp `description:"弘则资源包"`
  798. ListYxResource []*IndustrialManagementHotResp `description:"研选资源包"`
  799. ListYxReport []*ArticleCollectionResp `description:"研选报告"`
  800. ListHzReport []*ArticleCollectionResp `description:"弘则报告"`
  801. }
  802. // 产业列表
  803. func GetSearchResourceList(userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  804. o := orm.NewOrm()
  805. sql := `SELECT
  806. m.industry_name,
  807. m.industrial_management_id,
  808. MAX( a.publish_date ) as publish_date_order,
  809. MIN(a.publish_date) AS min_report_time,
  810. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date,
  811. (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
  812. FROM
  813. cygx_industrial_management AS m
  814. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  815. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  816. WHERE
  817. 1 = 1
  818. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  819. if startSize > 0 || pageSize > 0 {
  820. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  821. }
  822. _, err = o.Raw(sql).QueryRows(&items)
  823. return
  824. }
  825. // 切换列表
  826. type ReportBillboardTableResp struct {
  827. Name string `description:"名称"`
  828. Source int `description:"类型"`
  829. List []*ChartPermission
  830. }
  831. // 切换列表
  832. type ReportBillboardTableListResp struct {
  833. List []*ReportBillboardTableResp
  834. }
  835. // 报告榜单start
  836. type ArticleReportBillboardResp struct {
  837. ArticleId int `description:"文章id"`
  838. Title string `description:"标题"`
  839. PublishDate string `description:"发布时间"`
  840. PermissionName string `description:"行业名称"`
  841. DepartmentId int `description:"作者Id"`
  842. NickName string `description:"作者昵称"`
  843. IsCollect bool `description:"本人是否收藏"`
  844. Pv int `description:"PV"`
  845. CollectNum int `description:"收藏人数"`
  846. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  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. }