report.go 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. "strconv"
  5. //"rdluck_tools/paging"
  6. )
  7. type IndustrialManagementList struct {
  8. List []*IndustrialManagement
  9. }
  10. type IndustrialManagement struct {
  11. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  12. IndustryName string `description:"产业名称"`
  13. RecommendedIndex int `description:"推荐指数"`
  14. CategoryId int `description:"文章分类ID"`
  15. LayoutTime string `description:"布局时间"`
  16. UpdateTime string `description:"更新时间"`
  17. IsRed bool `description:"是否标记红点"`
  18. IsTop bool `description:"是否置顶"`
  19. AnalystList []*IndustrialAnalyst `description:"分析师列表"`
  20. Analyst string `description:"分析师"`
  21. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  22. }
  23. type IndustrialAnalyst struct {
  24. AnalystName string `description:"分析师名称"`
  25. IndustrialManagementId int `description:"产业id"`
  26. }
  27. type IndustrialSubject struct {
  28. IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"`
  29. IndustrialManagementId int `description:"产业id"`
  30. SubjectName string `description:"标的名称"`
  31. }
  32. //获取产业报告数量
  33. func GetReportIndustrialCount(categoryId, industrialManagementId int) (count int, err error) {
  34. o := orm.NewOrm()
  35. sql := `SELECT COUNT(1) count
  36. FROM
  37. cygx_article AS a
  38. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  39. WHERE
  40. a.publish_status = 1
  41. AND category_id = ?
  42. AND man_g.industrial_management_id = ?`
  43. err = o.Raw(sql, categoryId, industrialManagementId).QueryRow(&count)
  44. return
  45. }
  46. //获取产业报告列表
  47. func GetReportIndustrialList(pars []interface{}, categoryId, industrialManagementId, userId, startSize, pageSize int) (items []*ReportArticle, err error) {
  48. o := orm.NewOrm()
  49. 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
  50. FROM
  51. cygx_article AS a
  52. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  53. WHERE
  54. a.publish_status = 1
  55. AND category_id = ?
  56. AND man_g.industrial_management_id = ?`
  57. sql += ` ORDER BY publish_date DESC LIMIT ?,? `
  58. _, err = o.Raw(sql, pars, categoryId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  59. return
  60. }
  61. //产业下所关联的文章分类列表
  62. func IndustrialToArticleCategory(industrialManagementId int) (items []*IndustrialToArticleCategoryRep, err error) {
  63. o := orm.NewOrm()
  64. sql := `SELECT map.match_type_name,map.category_id
  65. FROM cygx_report_mapping AS map
  66. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  67. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  68. WHERE map.report_type = 2
  69. AND man_g.industrial_management_id =?
  70. GROUP BY map.match_type_name`
  71. _, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
  72. return
  73. }
  74. //判断用户是否阅读该产业下,某一分类的文章
  75. func IndustrialUserRecordArticleCount(userId, industrialManagementId, categoryId int) (count int, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT
  78. COUNT(1) count
  79. FROM
  80. cygx_article_history_record
  81. WHERE
  82. 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 )
  83. AND user_id = ? `
  84. err = o.Raw(sql, industrialManagementId, categoryId, userId).QueryRow(&count)
  85. return
  86. }