report.go 35 KB

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