report.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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(*) count
  175. // FROM(
  176. // SELECT COUNT(1) count
  177. // FROM
  178. // cygx_article AS art
  179. // INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  180. // INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  181. // INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
  182. // WHERE 1 = 1
  183. // AND art.publish_status = 1`
  184. //if condition != "" {
  185. // sql += condition
  186. //}
  187. //sql += ` ) AS num`
  188. sql := `SELECT COUNT(1) count
  189. FROM
  190. cygx_article AS art
  191. INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  192. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  193. INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
  194. WHERE 1 = 1
  195. AND art.publish_status = 1`
  196. if condition != "" {
  197. sql += condition
  198. }
  199. err = o.Raw(sql).QueryRow(&count)
  200. return
  201. }
  202. type IsShow struct {
  203. IsShow bool `description:"是否展示"`
  204. IsShowResearch bool `description:"研选是否展示限免"`
  205. IsShowChart bool `description:"图表是否展示限免"`
  206. }
  207. //获取用户是否有查看权限
  208. func GetUserIsAdminCount(mobile string) (count int, err error) {
  209. o := orm.NewOrm()
  210. sql := `SELECT COUNT(1) count FROM admin
  211. WHERE
  212. mobile = ?
  213. AND (group_id IN (11, 13, 14, 15, 16, 17) OR department_id = 3 ) AND enabled = 1`
  214. err = o.Raw(sql, mobile).QueryRow(&count)
  215. return
  216. }
  217. type ReportDetailRoadshow struct {
  218. ArticleId int `description:"报告Id"`
  219. Title string `description:"标题"`
  220. Department string `orm:"column(seller_and_mobile)"description:"作者"`
  221. PublishDate string `description:"发布时间"`
  222. VideoUrl string `description:"链接"`
  223. VideoPlaySeconds string `description:"时长"`
  224. VideoName string `description:"音频名称"`
  225. Abstract string `description:"摘要"`
  226. Body string `description:"内容"`
  227. CategoryName string `description:"行业名称"`
  228. ReportLink string `orm:"column(link_article_id)"description:"报告链接"`
  229. }
  230. type RoadshowDetailResp struct {
  231. Detail *ReportDetailRoadshow
  232. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  233. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  234. }
  235. func GetReportRoadshowDetailById(articleId int) (item *ReportDetailRoadshow, err error) {
  236. o := orm.NewOrm()
  237. sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
  238. err = o.Raw(sql, articleId).QueryRow(&item)
  239. return
  240. }
  241. type CygxIndustryAndArticleList struct {
  242. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  243. Title string `description:"标题"`
  244. PublishDate string `description:"发布时间"`
  245. IndustryName string `description:"产业名称"`
  246. SubjectName string `description:"标的名称"`
  247. }
  248. type CygxIndustrySearchList struct {
  249. ArtList []*CygxIndustryAndArticleList `description:"文章列表"`
  250. IndList []*IndustrialManagement `description:"产业列表"`
  251. }
  252. type CygxIndustrySearchListPc struct {
  253. DepartmentList []*CygxArticleDepartmentRepPc
  254. IndList []*IndustrialManagement `description:"产业列表"`
  255. }
  256. //列表
  257. func GetCygxIndustryAndArticleList(keyWord string) (items []*CygxIndustryAndArticleList, err error) {
  258. o := orm.NewOrm()
  259. sql := `SELECT
  260. art.title,
  261. art.article_id,
  262. art.publish_date
  263. FROM
  264. cygx_article AS art
  265. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
  266. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = mg.article_id
  267. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  268. WHERE
  269. category_name LIKE '%研选%'
  270. 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 )
  271. 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 '%研选%' )
  272. GROUP BY
  273. art.article_id`
  274. _, err = o.Raw(sql).QueryRows(&items)
  275. return
  276. }
  277. func GetArticleIdsBySubId(subjectId string) (articleIds string, err error) {
  278. o := orm.NewOrm()
  279. sql := `SELECT GROUP_CONCAT( DISTINCT a.article_id SEPARATOR ',' ) AS articleIds
  280. FROM cygx_article AS a
  281. WHERE subject_ids LIKE '%` + subjectId + `%'`
  282. err = o.Raw(sql).QueryRow(&articleIds)
  283. return
  284. } //end
  285. //用户收藏榜start
  286. type ArticleCollectionResp struct {
  287. ArticleId int `description:"文章id"`
  288. Title string `description:"标题"`
  289. PublishDate string `description:"发布时间"`
  290. IndustrialManagementId int `description:"产业Id"`
  291. IndustryName string `description:"产业名称"`
  292. DepartmentId int `description:"作者Id"`
  293. NickName string `description:"作者昵称"`
  294. Pv int `description:"PV"`
  295. CollectNum int `description:"收藏人数"`
  296. MyCollectNum int `description:"本人是否收藏"`
  297. IsCollect bool `description:"本人是否收藏"`
  298. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  299. }
  300. type ArticleCollectionLIstResp struct {
  301. List []*ArticleCollectionResp
  302. }
  303. //列表
  304. func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  305. o := orm.NewOrm()
  306. sql := `SELECT
  307. a.article_id,
  308. a.title,
  309. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  310. m.industry_name,
  311. m.industrial_management_id,
  312. d.nick_name,
  313. d.department_id,
  314. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  315. ( 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,
  316. ( 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,
  317. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  318. FROM
  319. cygx_article AS a
  320. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  321. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  322. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  323. WHERE
  324. 1 = 1 `
  325. if condition != "" {
  326. sql += condition
  327. }
  328. _, err = o.Raw(sql, userId).QueryRows(&items)
  329. return
  330. } //end
  331. //用户收藏榜start
  332. type IndustrialManagementHotResp struct {
  333. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  334. IndustryName string `description:"产业名称"`
  335. IsFollw bool `description:"是否关注"`
  336. FllowNum int `description:"关注数量"`
  337. IsNew bool `description:"是否新标签"`
  338. IsHot bool `description:"是否新标签"`
  339. PublishDate string `description:"发布时间"`
  340. ArticleReadNum int `description:"文章阅读数量"`
  341. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  342. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  343. }
  344. type IndustrialManagementHotListResp struct {
  345. Paging *paging.PagingItem `description:"分页数据"`
  346. List []*IndustrialManagementHotResp
  347. }
  348. //产业列表
  349. func GetThemeHeatList(permissionName string, userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  350. o := orm.NewOrm()
  351. sql := `SELECT
  352. m.industry_name,
  353. m.industrial_management_id,
  354. m.article_read_num,
  355. MAX( a.publish_date ) AS publish_date,
  356. ( 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,
  357. 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
  358. FROM
  359. cygx_industrial_management AS m
  360. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  361. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  362. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  363. WHERE
  364. 1 = 1
  365. AND a.category_name LIKE '%` + permissionName + `%'
  366. AND publish_status = 1
  367. GROUP BY m.industrial_management_id ` + condition + ` LIMIT ?,?`
  368. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  369. return
  370. }
  371. //获取数量
  372. func GetThemeHeatListCount(permissionName, condition string) (count int, err error) {
  373. o := orm.NewOrm()
  374. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  375. cygx_industrial_management AS m
  376. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  377. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  378. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  379. WHERE
  380. 1 = 1
  381. AND a.category_name LIKE '%` + permissionName + `%'
  382. AND a.publish_status = 1 ` + condition
  383. err = o.Raw(sql).QueryRow(&count)
  384. return
  385. }
  386. //标的列表
  387. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  388. o := orm.NewOrm()
  389. sql := `SELECT
  390. m.subject_name,
  391. m.industrial_management_id,
  392. m.industrial_subject_id
  393. FROM
  394. cygx_article AS a
  395. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  396. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  397. WHERE
  398. 1 = 1`
  399. if condition != "" {
  400. sql += condition
  401. }
  402. sql += ` AND publish_status = 1
  403. GROUP BY
  404. m.industrial_subject_id
  405. ORDER BY
  406. publish_date DESC`
  407. _, err = o.Raw(sql).QueryRows(&items)
  408. return
  409. } //end
  410. //Kol sratr
  411. type DepartmentResp struct {
  412. DepartmentId int `description:"作者Id"`
  413. NickName string `description:"作者昵称"`
  414. ImgUrl string `description:"图片链接"`
  415. IsFollw bool `description:"是否关注"`
  416. FllowNum int `description:"关注数量"`
  417. List []*IndustrialDepartmentListResp
  418. }
  419. type DepartmentListResp struct {
  420. List []*DepartmentResp
  421. }
  422. type IndustrialDepartmentListResp struct {
  423. IndustrialManagementId int `description:"产业Id"`
  424. IndustryName string `description:"产业名称"`
  425. DepartmentId int `description:"作者Id"`
  426. }
  427. //作者列表
  428. func GetDepartmentList(permissionName string, userId int) (items []*DepartmentResp, err error) {
  429. o := orm.NewOrm()
  430. sql := `SELECT
  431. d.nick_name,
  432. d.department_id,
  433. d.img_url,
  434. ( 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,
  435. ( 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
  436. FROM
  437. cygx_article_department AS d
  438. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  439. WHERE
  440. 1 = 1
  441. AND a.category_name LIKE '%` + permissionName + `%'
  442. AND publish_status = 1
  443. GROUP BY
  444. d.department_id
  445. ORDER BY
  446. sum_num DESC
  447. LIMIT 15`
  448. _, err = o.Raw(sql, userId).QueryRows(&items)
  449. return
  450. }
  451. //作者文章所关联的产业列表
  452. func GetIndustrialDepartmentList(permissionName string) (items []*IndustrialDepartmentListResp, err error) {
  453. o := orm.NewOrm()
  454. sql := `SELECT
  455. m.industrial_management_id,
  456. m.industry_name,
  457. d.department_id
  458. FROM
  459. cygx_article_department AS d
  460. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  461. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  462. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  463. WHERE
  464. 1 = 1
  465. AND a.category_name LIKE '%` + permissionName + `%'
  466. AND publish_status = 1
  467. GROUP BY
  468. a.article_id
  469. ORDER BY
  470. a.publish_date DESC`
  471. _, err = o.Raw(sql).QueryRows(&items)
  472. return
  473. }
  474. //主题详情start
  475. type GetThemeDetailListResp struct {
  476. ArticleId int `description:"文章id"`
  477. Title string `description:"标题"`
  478. PublishDate string `description:"发布时间"`
  479. SubjectName string `description:"标的名称"`
  480. IndustrialSubjectId int `description:"标的id"`
  481. DepartmentId int `description:"作者Id"`
  482. NickName string `description:"作者昵称"`
  483. Pv int `description:"PV"`
  484. CollectNum int `description:"收藏人数"`
  485. IndustrialManagementId int `description:"产业Id"`
  486. IndustryName string `description:"产业名称"`
  487. FllowNum int `description:"关注数量"`
  488. MyCollectNum int `description:"本人是否收藏"`
  489. IsCollect bool `description:"本人是否收藏"`
  490. }
  491. type GetThemeAericleListResp struct {
  492. ArticleId int `description:"文章id"`
  493. Title string `description:"标题"`
  494. PublishDate string `description:"发布时间"`
  495. SubjectName string `description:"标的名称"`
  496. IndustrialSubjectId int `description:"标的ID"`
  497. DepartmentId int `description:"作者Id"`
  498. NickName string `description:"作者昵称"`
  499. Pv int `description:"PV"`
  500. CollectNum int `description:"收藏人数"`
  501. FllowNum int `description:"关注数量"`
  502. MyCollectNum int `description:"本人是否收藏"`
  503. IsCollect bool `description:"本人是否收藏"`
  504. }
  505. type GetThemeAericleListBuSubjectResp struct {
  506. SubjectName string `description:"标的名称"`
  507. List []*GetThemeAericleListResp
  508. }
  509. //主题详情start
  510. type GetThemeDetailResp struct {
  511. IndustrialManagementId int `description:"产业Id"`
  512. IndustryName string `description:"产业名称"`
  513. IsFollw bool `description:"是否关注"`
  514. ListSubject []*IndustrialSubject `description:"标的列表"`
  515. List []*GetThemeAericleListResp
  516. }
  517. //列表
  518. func GetThemeDetail(userId, industrialManagementId int) (items []*GetThemeDetailListResp, err error) {
  519. o := orm.NewOrm()
  520. sql := `SELECT
  521. a.article_id,
  522. a.title,
  523. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  524. m.industry_name,
  525. m.industrial_management_id,
  526. d.nick_name,
  527. d.department_id,
  528. s.industrial_subject_id,
  529. s.subject_name,
  530. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  531. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  532. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num,
  533. ( 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
  534. FROM
  535. cygx_article AS a
  536. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  537. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  538. LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
  539. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
  540. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  541. WHERE
  542. 1 = 1
  543. AND m.industrial_management_id = ?
  544. AND publish_status = 1
  545. AND a.category_name LIKE '%研选%'
  546. ORDER BY
  547. publish_date DESC`
  548. _, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)
  549. return
  550. } //end
  551. //用户收藏榜start
  552. type DepartmentDetailResp struct {
  553. DepartmentId int `description:"作者Id"`
  554. NickName string `description:"作者昵称"`
  555. ImgUrl string `description:"图片链接"`
  556. FllowNum int `description:"多少人关注"`
  557. ArticleNum int `description:"文章数量"`
  558. CollectNum int `description:"收藏人数"`
  559. IsFllow bool `description:"是否关注"`
  560. List []*ArticleCollectionResp
  561. }
  562. type DepartmentDetail struct {
  563. DepartmentId int `description:"作者Id"`
  564. NickName string `description:"作者昵称"`
  565. ImgUrl string `description:"图片链接"`
  566. FllowNum int `description:"多少人关注"`
  567. ArticleNum int `description:"文章数量"`
  568. CollectNum int `description:"收藏人数"`
  569. IsFllow bool `description:"是否关注"`
  570. MyFllowNum int `description:"本人是否关注"`
  571. }
  572. //列表
  573. func GetDepartmentDetail(userId, departmentId int) (item DepartmentDetail, err error) {
  574. o := orm.NewOrm()
  575. sql := `SELECT
  576. d.department_id,
  577. d.nick_name,
  578. d.img_url,
  579. ( 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,
  580. ( 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,
  581. ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ) AS article_num,
  582. ( 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
  583. FROM
  584. cygx_article_department AS d
  585. WHERE
  586. d.department_id = ?`
  587. err = o.Raw(sql, userId, departmentId).QueryRow(&item)
  588. return
  589. } //end
  590. //报告搜索start
  591. type ReoprtSearchResp struct {
  592. ListYx []*ArticleCollectionResp `description:"研选报告"`
  593. ListHz []*ArticleCollectionResp `description:"弘则报告"`
  594. }
  595. //列表
  596. func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  597. o := orm.NewOrm()
  598. sql := `SELECT
  599. a.article_id,
  600. a.title,
  601. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  602. m.industry_name,
  603. m.industrial_management_id,
  604. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  605. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  606. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  607. FROM
  608. cygx_article AS a
  609. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  610. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  611. WHERE
  612. 1 = 1 `
  613. if condition != "" {
  614. sql += condition
  615. }
  616. _, err = o.Raw(sql, userId).QueryRows(&items)
  617. return
  618. } //end
  619. //搜索资源包 start
  620. type SearchResourceResp struct {
  621. ListHz []*IndustrialManagementHotResp `description:"弘则"`
  622. ListYx []*IndustrialManagementHotResp `description:"研选"`
  623. }
  624. //产业列表
  625. func GetSearchResourceList(condition string) (items []*IndustrialManagementHotResp, err error) {
  626. o := orm.NewOrm()
  627. sql := `SELECT
  628. m.industry_name,
  629. m.industrial_management_id,
  630. MAX( a.publish_date ) as publish_date_order,
  631. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
  632. FROM
  633. cygx_industrial_management AS m
  634. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  635. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  636. WHERE
  637. 1 = 1
  638. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  639. _, err = o.Raw(sql).QueryRows(&items)
  640. return
  641. }