report.go 31 KB

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