report.go 39 KB

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