report_mapping.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. )
  5. type ReportMapping struct {
  6. CategoryId int `description:"分类ID"`
  7. SubCategoryName string `description:"主题"`
  8. MatchTypeName string `description:"分类名称"`
  9. ChartPermissionName string `description:"行业名称"`
  10. ChartPermissionId int `description:"行业ID"`
  11. IsRed bool `description:"是否标红"`
  12. PermissionType int `description:"1主观,2客观"`
  13. CategoryIdSet int `description:"分类映射id"`
  14. PolymerizationId string `description:"分类聚合ID"`
  15. }
  16. type ReportMappingHome struct {
  17. CategoryId int `description:"分类ID"`
  18. SubCategoryName string `description:"主题名称"`
  19. MatchTypeName string `description:"匹配类型"`
  20. IsRed bool `description:"是否标红"`
  21. }
  22. type TradeReportMapping struct {
  23. CategoryId int `description:"分类ID"`
  24. CategoryIdSet int `description:"分类映射id"`
  25. PolymerizationId string `description:"分类聚合ID"`
  26. MatchTypeName string `description:"匹配类型"`
  27. IsRed bool `description:"是否标红"`
  28. IsFollow bool `description:"是否关注"`
  29. UpdateTime string `description:"更新时间"`
  30. Readnum int `description:"阅读数量"`
  31. ListArticle []*HomeArticle `description:"文章列表"`
  32. }
  33. type ReportMappingResp struct {
  34. List []*ReportMapping
  35. }
  36. type ReportMappingHomeResp struct {
  37. List []*ReportMappingHome
  38. }
  39. type TradeReportMappingResp struct {
  40. List []*TradeReportMapping
  41. }
  42. // 获取所有分类
  43. func GetReportMappingStrategyAll() (items []*ReportMapping, err error) {
  44. o := orm.NewOrm()
  45. sql := `SELECT * FROM cygx_report_mapping WHERE 1=1 ORDER BY sort ASC `
  46. _, err = o.Raw(sql).QueryRows(&items)
  47. return
  48. }
  49. // 获取策略下面的所有分类
  50. func GetReportMappingStrategyHomeAll() (items []*TradeReportMapping, err error) {
  51. o := orm.NewOrm()
  52. sql := `SELECT
  53. MAX( art.publish_date ) AS update_time,
  54. re.category_id,re.sub_category_name,re.match_type_name
  55. FROM
  56. cygx_report_mapping AS re
  57. INNER JOIN cygx_article AS art ON art.category_id = re.category_id
  58. WHERE
  59. re.report_type = 1
  60. AND re.chart_permission_id = 23
  61. GROUP BY
  62. re.match_type_name
  63. ORDER BY
  64. sort DESC , art.publish_date DESC`
  65. _, err = o.Raw(sql).QueryRows(&items)
  66. return
  67. }
  68. // 行业列表
  69. func GetTradeAll(ChartPermissionId int) (items []*TradeReportMapping, err error) {
  70. o := orm.NewOrm()
  71. sql := `SELECT
  72. re.category_id,
  73. re.category_id_set,
  74. re.polymerization_id,
  75. re.sub_category_name,
  76. re.match_type_name
  77. FROM
  78. cygx_report_mapping AS re
  79. WHERE
  80. re.chart_permission_id = ?
  81. AND re.report_type = 1
  82. AND re.category_id NOT IN ( 67 )
  83. ORDER BY
  84. re.sort DESC`
  85. _, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
  86. return
  87. }
  88. type IndustrialToArticleCategoryRep struct {
  89. CategoryId int `description:"分类ID"`
  90. MatchTypeName string `description:"匹配类型"`
  91. IsRed bool `description:"是否标红"`
  92. }
  93. type IndustrialToArticleCategoryListRep struct {
  94. LayoutTime string `description:"布局时间"`
  95. IndustryName string `description:"产业名称"`
  96. IndustrialManagementId int `description:"产业D"`
  97. List []*IndustrialToArticleCategoryRep
  98. ListSubject []*IndustrialSubject
  99. IndustryVideo *MicroVideoSimpleInfo
  100. AuthInfo *UserPermissionAuthInfo
  101. }
  102. // 通过分类ID获取详情
  103. func GetdetailByCategoryId(categoryId int) (item *ReportMapping, err error) {
  104. o := orm.NewOrm()
  105. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? LIMIT 1 `
  106. err = o.Raw(sql, categoryId).QueryRow(&item)
  107. return
  108. }
  109. // 通过分类ID获取详情
  110. func GetdetailByCategoryIdPush(categoryId int) (item *ReportMapping, err error) {
  111. o := orm.NewOrm()
  112. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? `
  113. err = o.Raw(sql, categoryId).QueryRow(&item)
  114. return
  115. }
  116. // 通过分类ID获取详情主观客观
  117. func GetdetailByCategoryIdSando(categoryId int) (item *ReportMapping, err error) {
  118. o := orm.NewOrm()
  119. sql := `SELECT * FROM cygx_report_mapping WHERE permission_type>0 AND category_id=? LIMIT 1`
  120. err = o.Raw(sql, categoryId).QueryRow(&item)
  121. return
  122. }
  123. // 通过分类ID获取详情
  124. func GetdetailByCategoryIdOne(categoryId, reportType int) (item *ReportMapping, err error) {
  125. o := orm.NewOrm()
  126. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? AND report_type = ? LIMIT 1`
  127. err = o.Raw(sql, categoryId, reportType).QueryRow(&item)
  128. return
  129. }
  130. // 通过分类ID获取详情
  131. func GetdetailByCategoryIdSet(categoryId int) (ids string, err error) {
  132. o := orm.NewOrm()
  133. sql := `SELECT
  134. GROUP_CONCAT( DISTINCT category_id SEPARATOR ',' ) AS ids
  135. FROM
  136. cygx_report_mapping
  137. WHERE
  138. category_id_set = ? `
  139. err = o.Raw(sql, categoryId).QueryRow(&ids)
  140. return
  141. }
  142. // 判断该分类下最新的文章用户是否阅读
  143. func CheckThisCategoryNewArticleIsRead(uid, categoryId int) (count int, err error) {
  144. o := orm.NewOrm()
  145. sql := `SELECT COUNT(1) count
  146. FROM cygx_article_history_record
  147. WHERE user_id = ?
  148. 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)`
  149. err = o.Raw(sql, uid, categoryId).QueryRow(&count)
  150. return
  151. }
  152. // 获取策略下面的所有分类
  153. func GetMatchTypeNamenNotNull() (items []*ReportMapping, err error) {
  154. o := orm.NewOrm()
  155. sql := `SELECT category_id,match_type_name FROM cygx_report_mapping WHERE match_type_name <> ''`
  156. _, err = o.Raw(sql).QueryRows(&items)
  157. return
  158. }
  159. type ReportMappingStatistical struct {
  160. CategoryId int `description:"分类ID"`
  161. SubCategoryName string `description:"主题名称"`
  162. MatchTypeName string `description:"匹配类型"`
  163. IsSummary string `description:"是否属于纪要,1 是,0否"`
  164. IsClass string `description:"是否归类,1 是,0否"`
  165. Pv int `description:"Pv"`
  166. Uv int `description:"Uv"`
  167. }