report_mapping.go 6.6 KB

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