report_mapping.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package models
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/orm"
  4. )
  5. type ReportMapping struct {
  6. CategoryId int `description:"分类ID"`
  7. SubCategoryName string `description:"主题"`
  8. MatchTypeName string `description:"分类名称"`
  9. IsRed bool `description:"是否标红"`
  10. }
  11. type ReportMappingHome struct {
  12. CategoryId int `description:"分类ID"`
  13. SubCategoryName string `description:"主题名称"`
  14. MatchTypeName string `description:"匹配类型"`
  15. IsRed bool `description:"是否标红"`
  16. }
  17. type TradeReportMapping struct {
  18. CategoryId int `description:"分类ID"`
  19. SubCategoryName string `description:"主题名称"`
  20. MatchTypeName string `description:"匹配类型"`
  21. IsRed bool `description:"是否标红"`
  22. UpdateTime string `description:"更新时间"`
  23. Readnum int `description:"阅读数量"`
  24. }
  25. type ReportMappingResp struct {
  26. List []*ReportMapping
  27. }
  28. type ReportMappingHomeResp struct {
  29. List []*ReportMappingHome
  30. }
  31. type TradeReportMappingResp struct {
  32. List []*TradeReportMapping
  33. }
  34. //获取策略下面的所有分类
  35. func GetReportMappingStrategyAll() (items []*ReportMapping, err error) {
  36. o := orm.NewOrm()
  37. sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND chart_permission_id=23 ORDER BY sort ASC `
  38. _, err = o.Raw(sql).QueryRows(&items)
  39. return
  40. }
  41. //获取策略下面的所有分类
  42. func GetReportMappingStrategyHomeAll() (items []*ReportMappingHome, err error) {
  43. o := orm.NewOrm()
  44. sql := `SELECT
  45. re.category_id,re.sub_category_name,re.match_type_name
  46. FROM
  47. cygx_report_mapping AS re
  48. INNER JOIN cygx_article AS art ON art.category_id = re.category_id
  49. WHERE
  50. re.report_type = 1
  51. AND re.chart_permission_id = 23
  52. GROUP BY
  53. re.match_type_name
  54. ORDER BY
  55. sort DESC , art.publish_date DESC`
  56. _, err = o.Raw(sql).QueryRows(&items)
  57. return
  58. }
  59. //行业列表
  60. func GetTradeAll(ChartPermissionId int) (items []*TradeReportMapping, err error) {
  61. o := orm.NewOrm()
  62. sql := `SELECT
  63. MAX( art.publish_date ) AS update_time,
  64. re.category_id,
  65. re.sub_category_name,
  66. re.match_type_name
  67. FROM
  68. cygx_report_mapping AS re
  69. INNER JOIN cygx_article AS art ON re.category_id = art.category_id
  70. WHERE
  71. re.chart_permission_id =?
  72. AND re.report_type = 1
  73. AND art.is_class = 1
  74. AND re.category_id NOT IN (67)
  75. GROUP BY
  76. art.category_id
  77. ORDER BY
  78. update_time DESC`
  79. _, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
  80. return
  81. }
  82. type IndustrialToArticleCategoryRep struct {
  83. CategoryId int `description:"分类ID"`
  84. MatchTypeName string `description:"匹配类型"`
  85. IsRed bool `description:"是否标红"`
  86. }
  87. type IndustrialToArticleCategoryListRep struct {
  88. LayoutTime string `description:"布局时间"`
  89. IndustryName string `description:"产业名称"`
  90. IndustrialManagementId int `description:"产业D"`
  91. List []*IndustrialToArticleCategoryRep
  92. }
  93. //通过分类ID获取详情
  94. func GetdetailByCategoryId(categoryId int) (item *ReportMapping, err error) {
  95. o := orm.NewOrm()
  96. sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND category_id=? `
  97. err = o.Raw(sql, categoryId).QueryRow(&item)
  98. return
  99. }
  100. //判断该分类下最新的文章用户是否阅读
  101. func CheckThisCategoryNewArticleIsRead(uid, categoryId int) (count int, err error) {
  102. o := orm.NewOrm()
  103. sql := `SELECT COUNT(1) count
  104. FROM cygx_article_history_record
  105. WHERE user_id = ?
  106. AND article_id = ( SELECT article_id FROM cygx_article WHERE category_id = ? AND is_class = 1 AND is_report = 1 AND is_filter = 0 ORDER BY publish_date DESC LIMIT 1)`
  107. err = o.Raw(sql, uid, categoryId).QueryRow(&count)
  108. return
  109. }
  110. //获取策略下面的所有分类
  111. func GetMatchTypeNamenNotNull() (items []*ReportMapping, err error) {
  112. o := orm.NewOrm()
  113. sql := `SELECT category_id,match_type_name FROM cygx_report_mapping WHERE match_type_name <> ''`
  114. _, err = o.Raw(sql).QueryRows(&items)
  115. return
  116. }