report_mapping.go 6.3 KB

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