report.go 34 KB

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