report_mapping.go 6.5 KB

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