report.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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 AND a.publish_status = 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(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.article_type_id > 0
  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(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.article_type_id > 0 AND a.publish_status = 1 ` + condition
  382. err = o.Raw(sql).QueryRow(&count)
  383. return
  384. }
  385. //标的列表
  386. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  387. o := orm.NewOrm()
  388. sql := `SELECT
  389. m.subject_name,
  390. m.industrial_management_id,
  391. m.industrial_subject_id
  392. FROM
  393. cygx_article AS a
  394. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  395. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  396. WHERE
  397. 1 = 1`
  398. if condition != "" {
  399. sql += condition
  400. }
  401. sql += ` AND publish_status = 1
  402. GROUP BY
  403. m.industrial_subject_id
  404. ORDER BY
  405. publish_date DESC`
  406. _, err = o.Raw(sql).QueryRows(&items)
  407. return
  408. } //end
  409. //Kol sratr
  410. type DepartmentResp struct {
  411. DepartmentId int `description:"作者Id"`
  412. NickName string `description:"作者昵称"`
  413. ImgUrl string `description:"图片链接"`
  414. IsFollw bool `description:"是否关注"`
  415. FllowNum int `description:"关注数量"`
  416. List []*IndustrialDepartmentListResp
  417. }
  418. type DepartmentListResp struct {
  419. List []*DepartmentResp
  420. }
  421. type IndustrialDepartmentListResp struct {
  422. IndustrialManagementId int `description:"产业Id"`
  423. IndustryName string `description:"产业名称"`
  424. DepartmentId int `description:"作者Id"`
  425. }
  426. //作者列表
  427. func GetDepartmentList(userId int) (items []*DepartmentResp, err error) {
  428. o := orm.NewOrm()
  429. sql := `SELECT
  430. d.nick_name,
  431. d.department_id,
  432. d.img_url,
  433. ( 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,
  434. ( 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
  435. FROM
  436. cygx_article_department AS d
  437. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  438. WHERE
  439. 1 = 1
  440. AND a.article_type_id > 0
  441. AND publish_status = 1
  442. GROUP BY
  443. d.department_id
  444. ORDER BY
  445. sum_num DESC
  446. LIMIT 15`
  447. _, err = o.Raw(sql, userId).QueryRows(&items)
  448. return
  449. }
  450. //作者文章所关联的产业列表
  451. func GetIndustrialDepartmentList() (items []*IndustrialDepartmentListResp, err error) {
  452. o := orm.NewOrm()
  453. sql := `SELECT
  454. m.industrial_management_id,
  455. m.industry_name,
  456. d.department_id
  457. FROM
  458. cygx_article_department AS d
  459. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  460. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  461. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  462. WHERE
  463. 1 = 1
  464. AND a.article_type_id > 0
  465. AND publish_status = 1
  466. GROUP BY
  467. a.article_id
  468. ORDER BY
  469. a.publish_date DESC`
  470. _, err = o.Raw(sql).QueryRows(&items)
  471. return
  472. }
  473. //主题详情start
  474. type GetThemeDetailListResp struct {
  475. ArticleId int `description:"文章id"`
  476. Title string `description:"标题"`
  477. PublishDate string `description:"发布时间"`
  478. SubjectName string `description:"标的名称"`
  479. IndustrialSubjectId int `description:"标的id"`
  480. DepartmentId int `description:"作者Id"`
  481. NickName string `description:"作者昵称"`
  482. Pv int `description:"PV"`
  483. CollectNum int `description:"收藏人数"`
  484. IndustrialManagementId int `description:"产业Id"`
  485. IndustryName string `description:"产业名称"`
  486. FllowNum int `description:"关注数量"`
  487. MyCollectNum int `description:"本人是否收藏"`
  488. IsCollect bool `description:"本人是否收藏"`
  489. }
  490. type GetThemeAericleListResp struct {
  491. ArticleId int `description:"文章id"`
  492. Title string `description:"标题"`
  493. PublishDate string `description:"发布时间"`
  494. SubjectName string `description:"标的名称"`
  495. IndustrialSubjectId int `description:"标的ID"`
  496. DepartmentId int `description:"作者Id"`
  497. NickName string `description:"作者昵称"`
  498. Pv int `description:"PV"`
  499. CollectNum int `description:"收藏人数"`
  500. FllowNum int `description:"关注数量"`
  501. MyCollectNum int `description:"本人是否收藏"`
  502. IsCollect bool `description:"本人是否收藏"`
  503. }
  504. type GetThemeAericleListBuSubjectResp struct {
  505. SubjectName string `description:"标的名称"`
  506. List []*GetThemeAericleListResp
  507. }
  508. //主题详情start
  509. type GetThemeDetailResp struct {
  510. IndustrialManagementId int `description:"产业Id"`
  511. IndustryName string `description:"产业名称"`
  512. IsFollw bool `description:"是否关注"`
  513. ListSubject []*IndustrialSubject `description:"标的列表"`
  514. List []*GetThemeAericleListResp
  515. }
  516. //列表
  517. func GetThemeDetail(userId, industrialManagementId int) (items []*GetThemeDetailListResp, err error) {
  518. o := orm.NewOrm()
  519. sql := `SELECT
  520. a.article_id,
  521. a.title,
  522. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  523. m.industry_name,
  524. m.industrial_management_id,
  525. d.nick_name,
  526. d.department_id,
  527. s.industrial_subject_id,
  528. s.subject_name,
  529. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  530. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  531. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num,
  532. ( 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
  533. FROM
  534. cygx_article AS a
  535. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  536. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  537. LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
  538. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
  539. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  540. WHERE
  541. 1 = 1
  542. AND m.industrial_management_id = ?
  543. AND publish_status = 1
  544. AND a.category_name LIKE '%研选%'
  545. ORDER BY
  546. publish_date DESC`
  547. _, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)
  548. return
  549. } //end
  550. //用户收藏榜start
  551. type DepartmentDetailResp struct {
  552. DepartmentId int `description:"作者Id"`
  553. NickName string `description:"作者昵称"`
  554. ImgUrl string `description:"图片链接"`
  555. FllowNum int `description:"多少人关注"`
  556. ArticleNum int `description:"文章数量"`
  557. CollectNum int `description:"收藏人数"`
  558. IsFllow bool `description:"是否关注"`
  559. List []*ArticleCollectionResp
  560. }
  561. type DepartmentDetail struct {
  562. DepartmentId int `description:"作者Id"`
  563. NickName string `description:"作者昵称"`
  564. ImgUrl string `description:"图片链接"`
  565. FllowNum int `description:"多少人关注"`
  566. ArticleNum int `description:"文章数量"`
  567. CollectNum int `description:"收藏人数"`
  568. IsFllow bool `description:"是否关注"`
  569. MyFllowNum int `description:"本人是否关注"`
  570. }
  571. //列表
  572. func GetDepartmentDetail(userId, departmentId int) (item DepartmentDetail, err error) {
  573. o := orm.NewOrm()
  574. sql := `SELECT
  575. d.department_id,
  576. d.nick_name,
  577. d.img_url,
  578. ( 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,
  579. ( 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,
  580. ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ) AS article_num,
  581. ( 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
  582. FROM
  583. cygx_article_department AS d
  584. WHERE
  585. d.department_id = ?`
  586. err = o.Raw(sql, userId, departmentId).QueryRow(&item)
  587. return
  588. } //end
  589. //报告搜索start
  590. type ReoprtSearchResp struct {
  591. ListYx []*ArticleCollectionResp `description:"研选报告"`
  592. ListHz []*ArticleCollectionResp `description:"弘则报告"`
  593. }
  594. //列表
  595. func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  596. o := orm.NewOrm()
  597. sql := `SELECT
  598. a.article_id,
  599. a.title,
  600. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  601. m.industry_name,
  602. m.industrial_management_id,
  603. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  604. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  605. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  606. FROM
  607. cygx_article AS a
  608. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  609. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  610. WHERE
  611. 1 = 1 `
  612. if condition != "" {
  613. sql += condition
  614. }
  615. _, err = o.Raw(sql, userId).QueryRows(&items)
  616. return
  617. } //end
  618. //搜索资源包 start
  619. type SearchResourceResp struct {
  620. ListHz []*IndustrialManagementHotResp `description:"弘则"`
  621. ListYx []*IndustrialManagementHotResp `description:"研选"`
  622. }
  623. //产业列表
  624. func GetSearchResourceList(condition string) (items []*IndustrialManagementHotResp, err error) {
  625. o := orm.NewOrm()
  626. sql := `SELECT
  627. m.industry_name,
  628. m.industrial_management_id,
  629. MAX( a.publish_date ) as publish_date_order,
  630. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
  631. FROM
  632. cygx_industrial_management AS m
  633. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  634. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  635. WHERE
  636. 1 = 1
  637. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  638. _, err = o.Raw(sql).QueryRows(&items)
  639. return
  640. }