report_mapping.go 6.2 KB

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