report.go 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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. ActivitySpecialExplain string `description:"专项调研活动"`
  231. SearchTxtList SearchTxt `description:"搜索栏回显内容说明"`
  232. }
  233. type SearchTxt struct {
  234. SummarySearch string `description:"素材库搜索说明"`
  235. ReportSearch string `description:"报告搜索说明"`
  236. YanXuanSearch string `description:"研选搜索说明"`
  237. ActivitySearch string `description:"活动搜索说明"`
  238. TabSearch string `description:"素材库搜索说明"`
  239. }
  240. //获取用户是否有查看权限
  241. func GetUserIsAdminCount(mobile string) (count int, err error) {
  242. o := orm.NewOrm()
  243. sql := `SELECT COUNT(1) count FROM admin
  244. WHERE
  245. mobile = ?
  246. AND (group_id IN (11, 13, 14, 15, 16, 17) OR department_id = 3 ) AND enabled = 1`
  247. err = o.Raw(sql, mobile).QueryRow(&count)
  248. return
  249. }
  250. type ReportDetailRoadshow struct {
  251. ArticleId int `description:"报告Id"`
  252. Title string `description:"标题"`
  253. Department string `orm:"column(seller_and_mobile)"description:"作者"`
  254. PublishDate string `description:"发布时间"`
  255. VideoUrl string `description:"链接"`
  256. VideoPlaySeconds string `description:"时长"`
  257. VideoName string `description:"音频名称"`
  258. Abstract string `description:"摘要"`
  259. Body string `description:"内容"`
  260. CategoryName string `description:"行业名称"`
  261. ReportLink string `orm:"column(link_article_id)"description:"报告链接"`
  262. }
  263. type RoadshowDetailResp struct {
  264. Detail *ReportDetailRoadshow
  265. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  266. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  267. }
  268. func GetReportRoadshowDetailById(articleId int) (item *ReportDetailRoadshow, err error) {
  269. o := orm.NewOrm()
  270. sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
  271. err = o.Raw(sql, articleId).QueryRow(&item)
  272. return
  273. }
  274. type CygxIndustryAndArticleList struct {
  275. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  276. Title string `description:"标题"`
  277. PublishDate string `description:"发布时间"`
  278. IndustryName string `description:"产业名称"`
  279. SubjectName string `description:"标的名称"`
  280. }
  281. type CygxIndustrySearchList struct {
  282. ArtList []*CygxIndustryAndArticleList `description:"文章列表"`
  283. IndList []*IndustrialManagement `description:"产业列表"`
  284. }
  285. type CygxIndustrySearchListPc struct {
  286. DepartmentList []*CygxArticleDepartmentRepPc
  287. IndList []*IndustrialManagement `description:"产业列表"`
  288. }
  289. //列表
  290. func GetCygxIndustryAndArticleList(keyWord string) (items []*CygxIndustryAndArticleList, err error) {
  291. o := orm.NewOrm()
  292. sql := `SELECT
  293. art.title,
  294. art.article_id,
  295. art.publish_date
  296. FROM
  297. cygx_article AS art
  298. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
  299. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = mg.article_id
  300. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  301. WHERE
  302. category_name LIKE '%研选%'
  303. 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 )
  304. 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 '%研选%' )
  305. GROUP BY
  306. art.article_id`
  307. _, err = o.Raw(sql).QueryRows(&items)
  308. return
  309. }
  310. func GetArticleIdsBySubId(subjectId string) (articleIds string, err error) {
  311. o := orm.NewOrm()
  312. sql := `SELECT GROUP_CONCAT( DISTINCT a.article_id SEPARATOR ',' ) AS articleIds
  313. FROM cygx_article AS a
  314. WHERE subject_ids LIKE '%` + subjectId + `%'`
  315. err = o.Raw(sql).QueryRow(&articleIds)
  316. return
  317. } //end
  318. //用户收藏榜start
  319. type ArticleCollectionResp struct {
  320. ArticleId int `description:"文章id"`
  321. Title string `description:"标题"`
  322. PublishDate string `description:"发布时间"`
  323. IndustrialManagementId int `description:"产业Id"`
  324. IndustryName string `description:"产业名称"`
  325. DepartmentId int `description:"作者Id"`
  326. NickName string `description:"作者昵称"`
  327. MyCollectNum int `description:"本人是否收藏"`
  328. IsCollect bool `description:"本人是否收藏"`
  329. Pv int `description:"PV"`
  330. CollectNum int `description:"收藏人数"`
  331. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  332. }
  333. type ArticleCollectionLIstResp struct {
  334. List []*ArticleCollectionResp
  335. }
  336. //列表
  337. func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  338. o := orm.NewOrm()
  339. sql := `SELECT
  340. a.article_id,
  341. a.title,
  342. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  343. m.industry_name,
  344. m.industrial_management_id,
  345. d.nick_name,
  346. d.department_id,
  347. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  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 ) AS collect_num,
  349. ( 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,
  350. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  351. FROM
  352. cygx_article AS a
  353. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  354. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  355. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  356. WHERE
  357. 1 = 1 AND a.publish_status = 1 `
  358. if condition != "" {
  359. sql += condition
  360. }
  361. _, err = o.Raw(sql, userId).QueryRows(&items)
  362. return
  363. } //end
  364. //用户收藏榜start
  365. type IndustrialManagementHotResp struct {
  366. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  367. IndustryName string `description:"产业名称"`
  368. IsFollw bool `description:"是否关注"`
  369. FllowNum int `description:"关注数量"`
  370. IsNew bool `description:"是否新标签"`
  371. IsHot bool `description:"是否新标签"`
  372. PublishDate string `description:"发布时间"`
  373. ArticleReadNum int `description:"文章阅读数量"`
  374. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  375. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  376. IndustryVideo *MicroVideoSimpleInfo `description:"产业视频"`
  377. AuthInfo *UserPermissionAuthInfo
  378. }
  379. type IndustrialManagementHotListResp struct {
  380. Paging *paging.PagingItem `description:"分页数据"`
  381. List []*IndustrialManagementHotResp
  382. }
  383. //产业列表
  384. func GetThemeHeatList(userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  385. o := orm.NewOrm()
  386. sql := `SELECT
  387. m.industry_name,
  388. m.industrial_management_id,
  389. m.article_read_num,
  390. MAX( a.publish_date ) AS publish_date,
  391. ( 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,
  392. 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
  393. FROM
  394. cygx_industrial_management AS m
  395. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  396. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  397. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  398. WHERE
  399. 1 = 1
  400. AND a.article_type_id > 0
  401. AND publish_status = 1
  402. GROUP BY m.industrial_management_id ` + condition + ` LIMIT ?,?`
  403. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  404. return
  405. }
  406. //获取数量
  407. func GetThemeHeatListCount(condition string) (count int, err error) {
  408. o := orm.NewOrm()
  409. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  410. cygx_industrial_management AS m
  411. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  412. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  413. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  414. WHERE
  415. 1 = 1
  416. AND a.article_type_id > 0 AND a.publish_status = 1 ` + condition
  417. err = o.Raw(sql).QueryRow(&count)
  418. return
  419. }
  420. //标的列表
  421. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  422. o := orm.NewOrm()
  423. sql := `SELECT
  424. m.subject_name,
  425. m.industrial_management_id,
  426. m.industrial_subject_id
  427. FROM
  428. cygx_article AS a
  429. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  430. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  431. WHERE
  432. 1 = 1`
  433. if condition != "" {
  434. sql += condition
  435. }
  436. sql += ` AND publish_status = 1
  437. GROUP BY
  438. m.industrial_subject_id
  439. ORDER BY
  440. publish_date DESC`
  441. _, err = o.Raw(sql).QueryRows(&items)
  442. return
  443. } //end
  444. //Kol sratr
  445. type DepartmentResp struct {
  446. DepartmentId int `description:"作者Id"`
  447. NickName string `description:"作者昵称"`
  448. ImgUrl string `description:"图片链接"`
  449. IsFollw bool `description:"是否关注"`
  450. FllowNum int `description:"关注数量"`
  451. List []*IndustrialDepartmentListResp
  452. }
  453. type DepartmentListResp struct {
  454. List []*DepartmentResp
  455. }
  456. type IndustrialDepartmentListResp struct {
  457. IndustrialManagementId int `description:"产业Id"`
  458. IndustryName string `description:"产业名称"`
  459. DepartmentId int `description:"作者Id"`
  460. }
  461. //作者列表
  462. func GetDepartmentList(userId int) (items []*DepartmentResp, err error) {
  463. o := orm.NewOrm()
  464. sql := `SELECT
  465. d.nick_name,
  466. d.department_id,
  467. d.img_url,
  468. ( 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,
  469. ( 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
  470. FROM
  471. cygx_article_department AS d
  472. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  473. WHERE
  474. 1 = 1
  475. AND a.article_type_id > 0
  476. AND publish_status = 1
  477. GROUP BY
  478. d.department_id
  479. ORDER BY
  480. sum_num DESC
  481. LIMIT 15`
  482. _, err = o.Raw(sql, userId).QueryRows(&items)
  483. return
  484. }
  485. //作者文章所关联的产业列表
  486. func GetIndustrialDepartmentList() (items []*IndustrialDepartmentListResp, err error) {
  487. o := orm.NewOrm()
  488. sql := `SELECT
  489. m.industrial_management_id,
  490. m.industry_name,
  491. d.department_id
  492. FROM
  493. cygx_article_department AS d
  494. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  495. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  496. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  497. WHERE
  498. 1 = 1
  499. AND a.article_type_id > 0
  500. AND publish_status = 1
  501. GROUP BY
  502. a.article_id
  503. ORDER BY
  504. a.publish_date DESC`
  505. _, err = o.Raw(sql).QueryRows(&items)
  506. return
  507. }
  508. //主题详情start
  509. type GetThemeDetailListResp struct {
  510. ArticleId int `description:"文章id"`
  511. Title string `description:"标题"`
  512. PublishDate string `description:"发布时间"`
  513. SubjectName string `description:"标的名称"`
  514. IndustrialSubjectId int `description:"标的id"`
  515. DepartmentId int `description:"作者Id"`
  516. NickName string `description:"作者昵称"`
  517. Pv int `description:"PV"`
  518. CollectNum int `description:"收藏人数"`
  519. IndustrialManagementId int `description:"产业Id"`
  520. IndustryName string `description:"产业名称"`
  521. FllowNum int `description:"关注数量"`
  522. MyCollectNum int `description:"本人是否收藏"`
  523. IsCollect bool `description:"本人是否收藏"`
  524. }
  525. type GetThemeAericleListResp struct {
  526. ArticleId int `description:"文章id"`
  527. Title string `description:"标题"`
  528. PublishDate string `description:"发布时间"`
  529. SubjectName string `description:"标的名称"`
  530. IndustrialSubjectId int `description:"标的ID"`
  531. DepartmentId int `description:"作者Id"`
  532. NickName string `description:"作者昵称"`
  533. Pv int `description:"PV"`
  534. CollectNum int `description:"收藏人数"`
  535. FllowNum int `description:"关注数量"`
  536. MyCollectNum int `description:"本人是否收藏"`
  537. IsCollect bool `description:"本人是否收藏"`
  538. }
  539. type GetThemeAericleListBuSubjectResp struct {
  540. SubjectName string `description:"标的名称"`
  541. List []*GetThemeAericleListResp
  542. }
  543. //主题详情start
  544. type GetThemeDetailResp struct {
  545. IndustrialManagementId int `description:"产业Id"`
  546. IndustryName string `description:"产业名称"`
  547. IsFollw bool `description:"是否关注"`
  548. ListSubject []*IndustrialSubject `description:"标的列表"`
  549. List []*GetThemeAericleListResp
  550. }
  551. //列表
  552. func GetThemeDetail(userId, industrialManagementId int, condition string) (items []*GetThemeDetailListResp, err error) {
  553. o := orm.NewOrm()
  554. sql := `SELECT
  555. a.article_id,
  556. a.title,
  557. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  558. m.industry_name,
  559. m.industrial_management_id,
  560. d.nick_name,
  561. d.department_id,
  562. s.industrial_subject_id,
  563. s.subject_name,
  564. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  565. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  566. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num,
  567. ( 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
  568. FROM
  569. cygx_article AS a
  570. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  571. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  572. LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
  573. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
  574. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  575. WHERE
  576. 1 = 1
  577. AND m.industrial_management_id = ?
  578. AND publish_status = 1 ` + condition + `
  579. ORDER BY
  580. publish_date DESC`
  581. _, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)
  582. return
  583. } //end
  584. //用户收藏榜start
  585. type DepartmentDetailResp struct {
  586. DepartmentId int `description:"作者Id"`
  587. NickName string `description:"作者昵称"`
  588. ImgUrl string `description:"图片链接"`
  589. FllowNum int `description:"多少人关注"`
  590. ArticleNum int `description:"文章数量"`
  591. CollectNum int `description:"收藏人数"`
  592. IsFllow bool `description:"是否关注"`
  593. List []*ArticleCollectionResp
  594. ListIndustrial []*IndustrialManagementNewResp
  595. }
  596. type DepartmentDetail struct {
  597. DepartmentId int `description:"作者Id"`
  598. NickName string `description:"作者昵称"`
  599. ImgUrl string `description:"图片链接"`
  600. FllowNum int `description:"多少人关注"`
  601. ArticleNum int `description:"文章数量"`
  602. CollectNum int `description:"收藏人数"`
  603. IsFllow bool `description:"是否关注"`
  604. MyFllowNum int `description:"本人是否关注"`
  605. }
  606. //列表
  607. func GetDepartmentDetail(userId, departmentId int) (item DepartmentDetail, err error) {
  608. o := orm.NewOrm()
  609. sql := `SELECT
  610. d.department_id,
  611. d.nick_name,
  612. d.img_url,
  613. ( 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,
  614. ( 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,
  615. ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ) AS article_num,
  616. ( 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
  617. FROM
  618. cygx_article_department AS d
  619. WHERE
  620. d.department_id = ?`
  621. err = o.Raw(sql, userId, departmentId).QueryRow(&item)
  622. return
  623. } //end
  624. //报告搜索start
  625. type ReoprtSearchResp struct {
  626. ListYx []*ArticleCollectionResp `description:"研选报告"`
  627. ListHz []*ArticleCollectionResp `description:"弘则报告"`
  628. }
  629. //列表
  630. func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  631. o := orm.NewOrm()
  632. sql := `SELECT
  633. a.article_id,
  634. a.title,
  635. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  636. m.industry_name,
  637. m.industrial_management_id,
  638. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  639. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  640. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  641. FROM
  642. cygx_article AS a
  643. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  644. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  645. WHERE
  646. 1 = 1 `
  647. if condition != "" {
  648. sql += condition
  649. }
  650. _, err = o.Raw(sql, userId).QueryRows(&items)
  651. return
  652. } //end
  653. //搜索资源包 start
  654. type SearchResourceResp struct {
  655. ListHz []*IndustrialManagementHotResp `description:"弘则"`
  656. ListYx []*IndustrialManagementHotResp `description:"研选"`
  657. }
  658. //搜索资源包 start
  659. type SearchReportAndResourceResp struct {
  660. ListHzResource []*IndustrialManagementHotResp `description:"弘则资源包"`
  661. ListYxResource []*IndustrialManagementHotResp `description:"研选资源包"`
  662. ListYxReport []*ArticleCollectionResp `description:"研选报告"`
  663. ListHzReport []*ArticleCollectionResp `description:"弘则报告"`
  664. }
  665. //产业列表
  666. func GetSearchResourceList(condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  667. o := orm.NewOrm()
  668. sql := `SELECT
  669. m.industry_name,
  670. m.industrial_management_id,
  671. MAX( a.publish_date ) as publish_date_order,
  672. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
  673. FROM
  674. cygx_industrial_management AS m
  675. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  676. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  677. WHERE
  678. 1 = 1
  679. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  680. if startSize > 0 || pageSize > 0 {
  681. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  682. }
  683. _, err = o.Raw(sql).QueryRows(&items)
  684. return
  685. }
  686. //切换列表
  687. type ReportBillboardTableResp struct {
  688. Name string `description:"名称"`
  689. Source int `description:"类型"`
  690. List []*ChartPermission
  691. }
  692. //切换列表
  693. type ReportBillboardTableListResp struct {
  694. List []*ReportBillboardTableResp
  695. }
  696. //报告榜单start
  697. type ArticleReportBillboardResp struct {
  698. ArticleId int `description:"文章id"`
  699. Title string `description:"标题"`
  700. PublishDate string `description:"发布时间"`
  701. PermissionName string `description:"行业名称"`
  702. DepartmentId int `description:"作者Id"`
  703. NickName string `description:"作者昵称"`
  704. IsCollect bool `description:"本人是否收藏"`
  705. Pv int `description:"PV"`
  706. CollectNum int `description:"收藏人数"`
  707. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  708. List []*IndustrialManagementIdInt
  709. }
  710. type ArticleReportBillboardLIstResp struct {
  711. List []*ArticleReportBillboardResp
  712. }
  713. type ArticleReportBillboardLIstPageResp struct {
  714. List []*ArticleReportBillboardResp
  715. Paging *paging.PagingItem
  716. }
  717. //报告收藏榜单列表
  718. func GetReportCollectionBillboardList(limit int, pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  719. o := orm.NewOrm()
  720. sql := `SELECT
  721. ac.id,
  722. a.article_id,
  723. a.title,
  724. date_format(a.publish_date, '%Y-%m-%d') AS publish_date,
  725. m.chart_permission_name AS permission_name,
  726. COUNT(ac.id) AS collection_num
  727. FROM
  728. cygx_article AS a
  729. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  730. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  731. WHERE
  732. 1 = 1
  733. AND a.publish_status = 1 `
  734. if condition != "" {
  735. sql += condition
  736. }
  737. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, ac.id DESC, a.publish_date DESC`
  738. sql += ` LIMIT ?`
  739. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  740. return
  741. }
  742. //报告阅读榜单列表
  743. func GetReportPvBillboardList(pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  744. o := orm.NewOrm()
  745. sql := `SELECT
  746. a.article_id,
  747. a.title,
  748. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date
  749. FROM
  750. cygx_article AS a
  751. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  752. WHERE
  753. 1 = 1
  754. AND a.publish_status = 1 `
  755. if condition != "" {
  756. sql += condition
  757. }
  758. _, err = o.Raw(sql, pars).QueryRows(&items)
  759. return
  760. }
  761. //获取产业报告+晨会点评数量
  762. func GetTimeLineReportIndustrialCount(industrialManagementId int) (count int, err error) {
  763. o := orm.NewOrm()
  764. sql := `SELECT SUM(count) AS count FROM (
  765. SELECT
  766. COUNT( 1 ) count
  767. FROM
  768. cygx_article AS a
  769. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  770. WHERE
  771. a.publish_status = 1
  772. AND a.is_class = 1
  773. AND man_g.industrial_management_id = ?
  774. UNION ALL
  775. SELECT
  776. COUNT( 1 ) count
  777. FROM
  778. cygx_morning_meeting_review_chapter AS mmc
  779. INNER JOIN cygx_morning_meeting_reviews AS mm
  780. WHERE
  781. mm.id = mmc.meeting_id
  782. AND mm.status = 1
  783. AND mmc.industry_id = ? ) AS t `
  784. err = o.Raw(sql, industrialManagementId, industrialManagementId).QueryRow(&count)
  785. return
  786. }
  787. type TimeLineReportItem struct {
  788. Id int `description:"文章或晨报点评id"`
  789. Title string `description:"标题"`
  790. PublishTime string `description:"发布时间"`
  791. Content string `description:"内容"`
  792. VideoUrl string `description:"视频链接"`
  793. IsHaveVideo bool `description:"是否包含视频"`
  794. ImgUrlPc string `description:"pc图片"`
  795. SubCategoryName string `description:"二级分类"`
  796. }
  797. //获取产业报告+晨会点评列表
  798. func GetTimeLineReportIndustrialList(industrialManagementId, startSize, pageSize int) (items []*TimeLineReportItem, err error) {
  799. o := orm.NewOrm()
  800. sql := `SELECT
  801. *
  802. FROM
  803. (
  804. SELECT
  805. a.article_id AS id,
  806. a.title,
  807. a.publish_date AS publish_time,
  808. a.video_url,
  809. a.sub_category_name,
  810. '' AS content
  811. FROM
  812. cygx_article AS a
  813. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  814. WHERE
  815. a.publish_status = 1
  816. AND a.is_class = 1
  817. AND man_g.industrial_management_id = ? GROUP BY id UNION ALL
  818. SELECT
  819. mmc.id,
  820. '' AS title,
  821. mm.meeting_time AS publish_time,
  822. '' AS video_url,
  823. '时间线' AS sub_category_name,
  824. mmc.content
  825. FROM
  826. cygx_morning_meeting_review_chapter AS mmc
  827. INNER JOIN cygx_morning_meeting_reviews AS mm
  828. WHERE
  829. mm.id = mmc.meeting_id
  830. AND mm.STATUS = 1
  831. AND mmc.industry_id = ?
  832. ) AS t
  833. `
  834. sql += ` ORDER BY
  835. t.publish_time DESC LIMIT ?,? `
  836. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  837. return
  838. }