report.go 33 KB

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