report.go 27 KB

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