report.go 45 KB

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