report.go 36 KB

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