report_mapping.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package models
  2. import "rdluck_tools/orm"
  3. type ReportMapping struct {
  4. CategoryId int `description:"分类ID"`
  5. SubCategoryName string `description:"权限名称"`
  6. IsRed bool `description:"是否标红"`
  7. }
  8. type ReportMappingHome struct {
  9. CategoryId int `description:"分类ID"`
  10. SubCategoryName string `description:"权限名称"`
  11. IsRed bool `description:"是否标红"`
  12. Readnum int `description:"阅读数量"`
  13. }
  14. type TradeReportMapping struct {
  15. CategoryId int `description:"分类ID"`
  16. SubCategoryName string `description:"权限名称"`
  17. IsRed bool `description:"是否标红"`
  18. UpdateTime string `description:"更新时间"`
  19. Readnum int `description:"阅读数量"`
  20. }
  21. type ReportMappingResp struct {
  22. List []*ReportMapping
  23. }
  24. type ReportMappingHomeResp struct {
  25. List []*ReportMappingHome
  26. }
  27. type TradeReportMappingResp struct {
  28. List []*TradeReportMapping
  29. }
  30. //获取策略下面的所有分类
  31. func GetReportMappingStrategyAll() (items []*ReportMapping, err error) {
  32. o := orm.NewOrm()
  33. sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND chart_permission_id=23 ORDER BY sort ASC `
  34. _, err = o.Raw(sql).QueryRows(&items)
  35. return
  36. }
  37. //获取策略下面的所有分类
  38. func GetReportMappingStrategyHomeAll(uid int) (items []*ReportMappingHome, err error) {
  39. o := orm.NewOrm()
  40. sql := `SELECT
  41. re.category_id,re.sub_category_name, ( SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ? AND rec.article_id = art.article_id ) AS readnum
  42. FROM
  43. cygx_report_mapping AS re
  44. INNER JOIN cygx_article AS art ON art.category_id = re.category_id
  45. WHERE
  46. re.report_type = 1
  47. AND re.chart_permission_id = 23
  48. GROUP BY
  49. re.match_type_name
  50. ORDER BY
  51. sort DESC , art.publish_date DESC`
  52. _, err = o.Raw(sql, uid).QueryRows(&items)
  53. return
  54. }
  55. //行业列表
  56. func GetTradeAll(uid, ChartPermissionId int) (items []*TradeReportMapping, err error) {
  57. o := orm.NewOrm()
  58. //sql := `SELECT * FROM cygx_report_mapping WHERE chart_permission_id = ? AND report_type = 1;`
  59. sql := `SELECT
  60. art.article_id,art.publish_date as update_time ,re.category_id,re.sub_category_name,( SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ? AND rec.article_id = art.article_id ) AS readnum
  61. FROM
  62. cygx_report_mapping as re
  63. INNER JOIN cygx_article as art ON re.category_id = art.category_id
  64. WHERE
  65. re.chart_permission_id = ?
  66. AND re.report_type = 1
  67. ORDER BY art.publish_date DESC
  68. LIMIT 0,1`
  69. _, err = o.Raw(sql, uid, ChartPermissionId).QueryRows(&items)
  70. return
  71. }
  72. type IndustrialToArticleCategoryRep struct {
  73. CategoryId int `description:"分类ID"`
  74. MatchTypeName string `description:"权限名称"`
  75. IsRed bool `description:"是否标红"`
  76. }
  77. type IndustrialToArticleCategoryListRep struct {
  78. LayoutTime string `description:"布局时间"`
  79. IndustryName string `description:"产业名称"`
  80. List []*IndustrialToArticleCategoryRep
  81. }
  82. //产业下所关联的文章分类列表
  83. func IndustrialToArticleCategory(industrialManagementId int) (items []*IndustrialToArticleCategoryRep, err error) {
  84. o := orm.NewOrm()
  85. sql := `SELECT map.match_type_name,map.category_id
  86. FROM cygx_report_mapping AS map
  87. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  88. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  89. WHERE map.report_type = 2
  90. AND man_g.industrial_management_id =?
  91. GROUP BY map.match_type_name`
  92. _, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
  93. return
  94. }