report.go 37 KB

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