report.go 33 KB

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