report.go 27 KB

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