report.go 39 KB

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