report.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. IsRed bool `description:"是否标记红点"`
  20. IsTop bool `description:"是否置顶"`
  21. IsHot bool `description:"是否是热门"`
  22. IsFollow int `description:"是否关注"`
  23. Analyst string `description:"分析师"`
  24. ArticleReadNum int `description:"文章阅读数量"`
  25. AnalystList []*IndustrialAnalyst `description:"分析师列表"`
  26. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  27. }
  28. type IndustrialAnalyst struct {
  29. AnalystName string `description:"分析师名称"`
  30. IndustrialManagementId int `description:"产业id"`
  31. }
  32. type IndustrialSubject struct {
  33. IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"`
  34. IndustrialManagementId int `description:"产业id"`
  35. SubjectName string `description:"标的名称"`
  36. IndustryName string `description:"产业名称"`
  37. }
  38. //获取产业报告数量
  39. func GetReportIndustrialCount(categoryId, industrialManagementId int) (count int, err error) {
  40. o := orm.NewOrm()
  41. sql := `SELECT COUNT(1) count
  42. FROM
  43. cygx_article AS a
  44. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  45. WHERE
  46. a.publish_status = 1
  47. AND category_id IN (SELECT
  48. category_id
  49. FROM
  50. cygx_report_mapping
  51. WHERE
  52. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` )
  53. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` ) )
  54. AND a.is_class = 1
  55. AND man_g.industrial_management_id = ? `
  56. err = o.Raw(sql, industrialManagementId).QueryRow(&count)
  57. return
  58. }
  59. //获取产业报告列表
  60. func GetReportIndustrialList(pars []interface{}, categoryId, industrialManagementId, userId, startSize, pageSize int) (items []*ReportArticle, err error) {
  61. o := orm.NewOrm()
  62. 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
  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. sql += ` GROUP BY a.article_id ORDER BY publish_date DESC LIMIT ?,? `
  78. _, err = o.Raw(sql, pars, industrialManagementId, startSize, pageSize).QueryRows(&items)
  79. return
  80. }
  81. //产业下所关联的文章分类列表
  82. func IndustrialToArticleCategory(industrialManagementId, chartPermissionId int) (items []*IndustrialToArticleCategoryRep, err error) {
  83. o := orm.NewOrm()
  84. sql := `SELECT map.match_type_name,map.category_id
  85. FROM cygx_report_mapping AS map
  86. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  87. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  88. WHERE map.report_type = 2
  89. AND map.is_report = 1
  90. AND art.is_report = 1
  91. AND art.publish_status = 1
  92. AND man_g.industrial_management_id =?
  93. AND map.chart_permission_id = ?
  94. GROUP BY map.match_type_name`
  95. _, err = o.Raw(sql, industrialManagementId, chartPermissionId).QueryRows(&items)
  96. return
  97. }
  98. //判断用户是否阅读该产业下,某一分类的文章
  99. func IndustrialUserRecordArticleCount(userId, industrialManagementId, categoryId int) (count int, err error) {
  100. o := orm.NewOrm()
  101. sql := `SELECT
  102. COUNT(1) count
  103. FROM
  104. cygx_article_history_record
  105. WHERE
  106. 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 )
  107. AND user_id = ? `
  108. err = o.Raw(sql, industrialManagementId, categoryId, userId).QueryRow(&count)
  109. return
  110. }
  111. //获取最新文章
  112. func GetNewIndustrialUserRecordArticle(industrialManagementId, categoryId int) (item *ArticleDetail, err error) {
  113. o := orm.NewOrm()
  114. 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`
  115. err = o.Raw(sql, industrialManagementId, categoryId).QueryRow(&item)
  116. return
  117. }
  118. //获取最新文章
  119. func GetNewArticleByCategoryId(categoryId int) (item *ArticleDetail, err error) {
  120. o := orm.NewOrm()
  121. sql := ` SELECT * FROM cygx_article WHERE category_id = ? ORDER BY publish_date DESC LIMIT 0, 1`
  122. err = o.Raw(sql, categoryId).QueryRow(&item)
  123. return
  124. }
  125. func GetIndustrialManagementIdsBykeyWord(condition string) (industrialManagementIds string, err error) {
  126. sql := `SELECT GROUP_CONCAT(DISTINCT industrial_management_id SEPARATOR ',') AS industrial_management_ids FROM cygx_industrial_management WHERE` + condition
  127. o := orm.NewOrm()
  128. err = o.Raw(sql).QueryRow(&industrialManagementIds)
  129. return
  130. }
  131. type ReportArticleWhichIndustrial struct {
  132. ArticleId int `description:"文章id"`
  133. Title string `description:"标题"`
  134. PublishDate string `description:"发布时间"`
  135. IndustryName string `description:"产业名称"`
  136. SubjectName string `description:"标的名称"`
  137. NickName string `description:"作者昵称"`
  138. IsRed bool `description:"是否标记红点"`
  139. Readnum int `description:"阅读数量"`
  140. IsResearch bool `description:"是否属于研选"`
  141. Pv int `description:"PV"`
  142. ImgUrlPc string `description:"图片链接"`
  143. }
  144. type ReportArticleWhichIndustrialRepList struct {
  145. HaveResearch bool `description:"是否有研选权限"`
  146. Paging *paging.PagingItem `description:"分页数据"`
  147. NickName string `description:"作者昵称"`
  148. IndustryName string `description:"产业名称"`
  149. List []*ReportArticleWhichIndustrial
  150. }
  151. //列表
  152. func IndustrialToArticleWhichDepartment(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*ReportArticleWhichIndustrial, err error) {
  153. o := orm.NewOrm()
  154. sql := `SELECT
  155. art.* ,m.industry_name,d.nick_name,
  156. (SELECT count(1) FROM cygx_article_history_record_newpv as h WHERE h.article_id = art.article_id ) as pv,
  157. ( 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
  158. FROM
  159. cygx_article AS art
  160. INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  161. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  162. INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
  163. WHERE 1 = 1
  164. AND art.publish_status = 1`
  165. if condition != "" {
  166. sql += condition
  167. }
  168. sql += ` LIMIT ?,?`
  169. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  170. return
  171. }
  172. func GetWhichDepartmentCount(condition string) (count int, err error) {
  173. o := orm.NewOrm()
  174. sql := `SELECT COUNT(1) count
  175. FROM
  176. cygx_article AS art
  177. INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  178. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  179. INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
  180. WHERE 1 = 1
  181. AND art.publish_status = 1`
  182. if condition != "" {
  183. sql += condition
  184. }
  185. err = o.Raw(sql).QueryRow(&count)
  186. return
  187. }
  188. type IsShow struct {
  189. IsShow bool `description:"绝密内参按钮是否展示"`
  190. IsShowResearch bool `description:"研选是否展示限免"`
  191. IsShowChart bool `description:"图表是否展示限免"`
  192. IsShowList bool `description:"榜单是否展示"`
  193. LinkWxExplain string `description:"关注微信公众号链接说明地址"`
  194. YanXuan_Explain bool `description:"研选说明"`
  195. }
  196. //获取用户是否有查看权限
  197. func GetUserIsAdminCount(mobile string) (count int, err error) {
  198. o := orm.NewOrm()
  199. sql := `SELECT COUNT(1) count FROM admin
  200. WHERE
  201. mobile = ?
  202. AND (group_id IN (11, 13, 14, 15, 16, 17) OR department_id = 3 ) AND enabled = 1`
  203. err = o.Raw(sql, mobile).QueryRow(&count)
  204. return
  205. }
  206. type ReportDetailRoadshow struct {
  207. ArticleId int `description:"报告Id"`
  208. Title string `description:"标题"`
  209. Department string `orm:"column(seller_and_mobile)"description:"作者"`
  210. PublishDate string `description:"发布时间"`
  211. VideoUrl string `description:"链接"`
  212. VideoPlaySeconds string `description:"时长"`
  213. VideoName string `description:"音频名称"`
  214. Abstract string `description:"摘要"`
  215. Body string `description:"内容"`
  216. CategoryName string `description:"行业名称"`
  217. ReportLink string `orm:"column(link_article_id)"description:"报告链接"`
  218. }
  219. type RoadshowDetailResp struct {
  220. Detail *ReportDetailRoadshow
  221. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  222. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  223. }
  224. func GetReportRoadshowDetailById(articleId int) (item *ReportDetailRoadshow, err error) {
  225. o := orm.NewOrm()
  226. sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
  227. err = o.Raw(sql, articleId).QueryRow(&item)
  228. return
  229. }
  230. type CygxIndustryAndArticleList struct {
  231. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  232. Title string `description:"标题"`
  233. PublishDate string `description:"发布时间"`
  234. IndustryName string `description:"产业名称"`
  235. SubjectName string `description:"标的名称"`
  236. }
  237. type CygxIndustrySearchList struct {
  238. ArtList []*CygxIndustryAndArticleList `description:"文章列表"`
  239. IndList []*IndustrialManagement `description:"产业列表"`
  240. }
  241. type CygxIndustrySearchListPc struct {
  242. DepartmentList []*CygxArticleDepartmentRepPc
  243. IndList []*IndustrialManagement `description:"产业列表"`
  244. }
  245. //列表
  246. func GetCygxIndustryAndArticleList(keyWord string) (items []*CygxIndustryAndArticleList, err error) {
  247. o := orm.NewOrm()
  248. sql := `SELECT
  249. art.title,
  250. art.article_id,
  251. art.publish_date
  252. FROM
  253. cygx_article AS art
  254. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
  255. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = mg.article_id
  256. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  257. WHERE
  258. category_name LIKE '%研选%'
  259. 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 )
  260. 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 '%研选%' )
  261. GROUP BY
  262. art.article_id`
  263. _, err = o.Raw(sql).QueryRows(&items)
  264. return
  265. }
  266. func GetArticleIdsBySubId(subjectId string) (articleIds string, err error) {
  267. o := orm.NewOrm()
  268. sql := `SELECT GROUP_CONCAT( DISTINCT a.article_id SEPARATOR ',' ) AS articleIds
  269. FROM cygx_article AS a
  270. WHERE subject_ids LIKE '%` + subjectId + `%'`
  271. err = o.Raw(sql).QueryRow(&articleIds)
  272. return
  273. } //end
  274. //用户收藏榜start
  275. type ArticleCollectionResp struct {
  276. ArticleId int `description:"文章id"`
  277. Title string `description:"标题"`
  278. PublishDate string `description:"发布时间"`
  279. IndustrialManagementId int `description:"产业Id"`
  280. IndustryName string `description:"产业名称"`
  281. DepartmentId int `description:"作者Id"`
  282. NickName string `description:"作者昵称"`
  283. Pv int `description:"PV"`
  284. CollectNum int `description:"收藏人数"`
  285. MyCollectNum int `description:"本人是否收藏"`
  286. IsCollect bool `description:"本人是否收藏"`
  287. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  288. }
  289. type ArticleCollectionLIstResp struct {
  290. List []*ArticleCollectionResp
  291. }
  292. //列表
  293. func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  294. o := orm.NewOrm()
  295. sql := `SELECT
  296. a.article_id,
  297. a.title,
  298. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  299. m.industry_name,
  300. m.industrial_management_id,
  301. d.nick_name,
  302. d.department_id,
  303. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  304. ( 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,
  305. ( 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,
  306. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  307. FROM
  308. cygx_article AS a
  309. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  310. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  311. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  312. WHERE
  313. 1 = 1 AND a.publish_status = 1 `
  314. if condition != "" {
  315. sql += condition
  316. }
  317. _, err = o.Raw(sql, userId).QueryRows(&items)
  318. return
  319. } //end
  320. //用户收藏榜start
  321. type IndustrialManagementHotResp struct {
  322. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  323. IndustryName string `description:"产业名称"`
  324. IsFollw bool `description:"是否关注"`
  325. FllowNum int `description:"关注数量"`
  326. IsNew bool `description:"是否新标签"`
  327. IsHot bool `description:"是否新标签"`
  328. PublishDate string `description:"发布时间"`
  329. ArticleReadNum int `description:"文章阅读数量"`
  330. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  331. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  332. }
  333. type IndustrialManagementHotListResp struct {
  334. Paging *paging.PagingItem `description:"分页数据"`
  335. List []*IndustrialManagementHotResp
  336. }
  337. //产业列表
  338. func GetThemeHeatList(userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  339. o := orm.NewOrm()
  340. sql := `SELECT
  341. m.industry_name,
  342. m.industrial_management_id,
  343. m.article_read_num,
  344. MAX( a.publish_date ) AS publish_date,
  345. ( 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,
  346. 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
  347. FROM
  348. cygx_industrial_management AS m
  349. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  350. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  351. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  352. WHERE
  353. 1 = 1
  354. AND a.article_type_id > 0
  355. AND publish_status = 1
  356. GROUP BY m.industrial_management_id ` + condition + ` LIMIT ?,?`
  357. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  358. return
  359. }
  360. //获取数量
  361. func GetThemeHeatListCount(condition string) (count int, err error) {
  362. o := orm.NewOrm()
  363. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  364. cygx_industrial_management AS m
  365. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  366. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  367. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  368. WHERE
  369. 1 = 1
  370. AND a.article_type_id > 0 AND a.publish_status = 1 ` + condition
  371. err = o.Raw(sql).QueryRow(&count)
  372. return
  373. }
  374. //标的列表
  375. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  376. o := orm.NewOrm()
  377. sql := `SELECT
  378. m.subject_name,
  379. m.industrial_management_id,
  380. m.industrial_subject_id
  381. FROM
  382. cygx_article AS a
  383. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  384. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  385. WHERE
  386. 1 = 1`
  387. if condition != "" {
  388. sql += condition
  389. }
  390. sql += ` AND publish_status = 1
  391. GROUP BY
  392. m.industrial_subject_id
  393. ORDER BY
  394. publish_date DESC`
  395. _, err = o.Raw(sql).QueryRows(&items)
  396. return
  397. } //end
  398. //Kol sratr
  399. type DepartmentResp struct {
  400. DepartmentId int `description:"作者Id"`
  401. NickName string `description:"作者昵称"`
  402. ImgUrl string `description:"图片链接"`
  403. IsFollw bool `description:"是否关注"`
  404. FllowNum int `description:"关注数量"`
  405. List []*IndustrialDepartmentListResp
  406. }
  407. type DepartmentListResp struct {
  408. List []*DepartmentResp
  409. }
  410. type IndustrialDepartmentListResp struct {
  411. IndustrialManagementId int `description:"产业Id"`
  412. IndustryName string `description:"产业名称"`
  413. DepartmentId int `description:"作者Id"`
  414. }
  415. //作者列表
  416. func GetDepartmentList(userId int) (items []*DepartmentResp, err error) {
  417. o := orm.NewOrm()
  418. sql := `SELECT
  419. d.nick_name,
  420. d.department_id,
  421. d.img_url,
  422. ( 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,
  423. ( 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
  424. FROM
  425. cygx_article_department AS d
  426. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  427. WHERE
  428. 1 = 1
  429. AND a.article_type_id > 0
  430. AND publish_status = 1
  431. GROUP BY
  432. d.department_id
  433. ORDER BY
  434. sum_num DESC
  435. LIMIT 15`
  436. _, err = o.Raw(sql, userId).QueryRows(&items)
  437. return
  438. }
  439. //作者文章所关联的产业列表
  440. func GetIndustrialDepartmentList() (items []*IndustrialDepartmentListResp, err error) {
  441. o := orm.NewOrm()
  442. sql := `SELECT
  443. m.industrial_management_id,
  444. m.industry_name,
  445. d.department_id
  446. FROM
  447. cygx_article_department AS d
  448. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  449. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  450. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  451. WHERE
  452. 1 = 1
  453. AND a.article_type_id > 0
  454. AND publish_status = 1
  455. GROUP BY
  456. a.article_id
  457. ORDER BY
  458. a.publish_date DESC`
  459. _, err = o.Raw(sql).QueryRows(&items)
  460. return
  461. }
  462. //主题详情start
  463. type GetThemeDetailListResp struct {
  464. ArticleId int `description:"文章id"`
  465. Title string `description:"标题"`
  466. PublishDate string `description:"发布时间"`
  467. SubjectName string `description:"标的名称"`
  468. IndustrialSubjectId int `description:"标的id"`
  469. DepartmentId int `description:"作者Id"`
  470. NickName string `description:"作者昵称"`
  471. Pv int `description:"PV"`
  472. CollectNum int `description:"收藏人数"`
  473. IndustrialManagementId int `description:"产业Id"`
  474. IndustryName string `description:"产业名称"`
  475. FllowNum int `description:"关注数量"`
  476. MyCollectNum int `description:"本人是否收藏"`
  477. IsCollect bool `description:"本人是否收藏"`
  478. }
  479. type GetThemeAericleListResp struct {
  480. ArticleId int `description:"文章id"`
  481. Title string `description:"标题"`
  482. PublishDate string `description:"发布时间"`
  483. SubjectName string `description:"标的名称"`
  484. IndustrialSubjectId int `description:"标的ID"`
  485. DepartmentId int `description:"作者Id"`
  486. NickName string `description:"作者昵称"`
  487. Pv int `description:"PV"`
  488. CollectNum int `description:"收藏人数"`
  489. FllowNum int `description:"关注数量"`
  490. MyCollectNum int `description:"本人是否收藏"`
  491. IsCollect bool `description:"本人是否收藏"`
  492. }
  493. type GetThemeAericleListBuSubjectResp struct {
  494. SubjectName string `description:"标的名称"`
  495. List []*GetThemeAericleListResp
  496. }
  497. //主题详情start
  498. type GetThemeDetailResp struct {
  499. IndustrialManagementId int `description:"产业Id"`
  500. IndustryName string `description:"产业名称"`
  501. IsFollw bool `description:"是否关注"`
  502. ListSubject []*IndustrialSubject `description:"标的列表"`
  503. List []*GetThemeAericleListResp
  504. }
  505. //列表
  506. func GetThemeDetail(userId, industrialManagementId int, condition string) (items []*GetThemeDetailListResp, err error) {
  507. o := orm.NewOrm()
  508. sql := `SELECT
  509. a.article_id,
  510. a.title,
  511. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  512. m.industry_name,
  513. m.industrial_management_id,
  514. d.nick_name,
  515. d.department_id,
  516. s.industrial_subject_id,
  517. s.subject_name,
  518. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  519. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  520. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num,
  521. ( 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
  522. FROM
  523. cygx_article AS a
  524. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  525. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  526. LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
  527. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
  528. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  529. WHERE
  530. 1 = 1
  531. AND m.industrial_management_id = ?
  532. AND publish_status = 1 ` + condition + `
  533. ORDER BY
  534. publish_date DESC`
  535. _, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)
  536. return
  537. } //end
  538. //用户收藏榜start
  539. type DepartmentDetailResp struct {
  540. DepartmentId int `description:"作者Id"`
  541. NickName string `description:"作者昵称"`
  542. ImgUrl string `description:"图片链接"`
  543. FllowNum int `description:"多少人关注"`
  544. ArticleNum int `description:"文章数量"`
  545. CollectNum int `description:"收藏人数"`
  546. IsFllow bool `description:"是否关注"`
  547. List []*ArticleCollectionResp
  548. ListIndustrial []*IndustrialManagementNewResp
  549. }
  550. type DepartmentDetail struct {
  551. DepartmentId int `description:"作者Id"`
  552. NickName string `description:"作者昵称"`
  553. ImgUrl string `description:"图片链接"`
  554. FllowNum int `description:"多少人关注"`
  555. ArticleNum int `description:"文章数量"`
  556. CollectNum int `description:"收藏人数"`
  557. IsFllow bool `description:"是否关注"`
  558. MyFllowNum int `description:"本人是否关注"`
  559. }
  560. //列表
  561. func GetDepartmentDetail(userId, departmentId int) (item DepartmentDetail, err error) {
  562. o := orm.NewOrm()
  563. sql := `SELECT
  564. d.department_id,
  565. d.nick_name,
  566. d.img_url,
  567. ( 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,
  568. ( 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,
  569. ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ) AS article_num,
  570. ( 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
  571. FROM
  572. cygx_article_department AS d
  573. WHERE
  574. d.department_id = ?`
  575. err = o.Raw(sql, userId, departmentId).QueryRow(&item)
  576. return
  577. } //end
  578. //报告搜索start
  579. type ReoprtSearchResp struct {
  580. ListYx []*ArticleCollectionResp `description:"研选报告"`
  581. ListHz []*ArticleCollectionResp `description:"弘则报告"`
  582. }
  583. //列表
  584. func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  585. o := orm.NewOrm()
  586. sql := `SELECT
  587. a.article_id,
  588. a.title,
  589. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  590. m.industry_name,
  591. m.industrial_management_id,
  592. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  593. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  594. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  595. FROM
  596. cygx_article AS a
  597. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  598. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  599. WHERE
  600. 1 = 1 `
  601. if condition != "" {
  602. sql += condition
  603. }
  604. _, err = o.Raw(sql, userId).QueryRows(&items)
  605. return
  606. } //end
  607. //搜索资源包 start
  608. type SearchResourceResp struct {
  609. ListHz []*IndustrialManagementHotResp `description:"弘则"`
  610. ListYx []*IndustrialManagementHotResp `description:"研选"`
  611. }
  612. //产业列表
  613. func GetSearchResourceList(condition string) (items []*IndustrialManagementHotResp, err error) {
  614. o := orm.NewOrm()
  615. sql := `SELECT
  616. m.industry_name,
  617. m.industrial_management_id,
  618. MAX( a.publish_date ) as publish_date_order,
  619. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
  620. FROM
  621. cygx_industrial_management AS m
  622. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  623. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  624. WHERE
  625. 1 = 1
  626. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  627. _, err = o.Raw(sql).QueryRows(&items)
  628. return
  629. }
  630. //切换列表
  631. type ReportBillboardTableResp struct {
  632. Name string `description:"名称"`
  633. Source int `description:"类型"`
  634. List []*ChartPermission
  635. }
  636. //切换列表
  637. type ReportBillboardTableListResp struct {
  638. List []*ReportBillboardTableResp
  639. }
  640. //报告榜单start
  641. type ArticleReportBillboardResp struct {
  642. ArticleId int `description:"文章id"`
  643. Title string `description:"标题"`
  644. PublishDate string `description:"发布时间"`
  645. List []*IndustrialManagementIdInt
  646. }
  647. type ArticleReportBillboardLIstResp struct {
  648. List []*ArticleReportBillboardResp
  649. }
  650. //报告收藏榜单列表
  651. func GetReportCollectionBillboardList(pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  652. o := orm.NewOrm()
  653. sql := `SELECT
  654. ac.id,
  655. a.article_id,
  656. a.title,
  657. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date
  658. FROM
  659. cygx_article AS a
  660. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  661. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  662. WHERE
  663. 1 = 1
  664. AND a.publish_status = 1 `
  665. if condition != "" {
  666. sql += condition
  667. }
  668. _, err = o.Raw(sql, pars).QueryRows(&items)
  669. return
  670. }
  671. //报告阅读榜单列表
  672. func GetReportPvBillboardList(pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  673. o := orm.NewOrm()
  674. sql := `SELECT
  675. a.article_id,
  676. a.title,
  677. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date
  678. FROM
  679. cygx_article AS a
  680. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  681. WHERE
  682. 1 = 1
  683. AND a.publish_status = 1 `
  684. if condition != "" {
  685. sql += condition
  686. }
  687. _, err = o.Raw(sql, pars).QueryRows(&items)
  688. return
  689. }