report_mapping.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. IndustryVideo *MicroVideoSimpleInfo
  96. List []*IndustrialToArticleCategoryRep
  97. }
  98. //通过分类ID获取详情
  99. func GetdetailByCategoryId(categoryId int) (item *ReportMapping, err error) {
  100. o := orm.NewOrm()
  101. sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND category_id=? `
  102. err = o.Raw(sql, categoryId).QueryRow(&item)
  103. return
  104. }
  105. //通过分类ID获取详情
  106. func GetdetailByCategoryIdSet(categoryId int) (ids string, err error) {
  107. o := orm.NewOrm()
  108. sql := `SELECT
  109. GROUP_CONCAT( DISTINCT category_id SEPARATOR ',' ) AS ids
  110. FROM
  111. cygx_report_mapping
  112. WHERE
  113. category_id_set = ? `
  114. err = o.Raw(sql, categoryId).QueryRow(&ids)
  115. return
  116. }
  117. //通过分类ID获取详情
  118. func GetdetailByCategoryIdPush(categoryId int) (item *ReportMapping, err error) {
  119. o := orm.NewOrm()
  120. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? `
  121. err = o.Raw(sql, categoryId).QueryRow(&item)
  122. return
  123. }
  124. //通过分类ID获取详情主观客观
  125. func GetdetailByCategoryIdSando(categoryId int) (item *ReportMapping, err error) {
  126. o := orm.NewOrm()
  127. sql := `SELECT * FROM cygx_report_mapping WHERE permission_type>0 AND category_id=? LIMIT 1`
  128. err = o.Raw(sql, categoryId).QueryRow(&item)
  129. return
  130. }
  131. //通过分类ID获取详情
  132. func GetdetailByCategoryIdOne(categoryId int) (item *ReportMapping, err error) {
  133. o := orm.NewOrm()
  134. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? LIMIT 1`
  135. err = o.Raw(sql, categoryId).QueryRow(&item)
  136. return
  137. }
  138. //判断该分类下最新的文章用户是否阅读
  139. func CheckThisCategoryNewArticleIsRead(uid, categoryId int) (count int, err error) {
  140. o := orm.NewOrm()
  141. sql := `SELECT COUNT(1) count
  142. FROM cygx_article_history_record
  143. WHERE user_id = ?
  144. 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)`
  145. err = o.Raw(sql, uid, categoryId).QueryRow(&count)
  146. return
  147. }
  148. //获取策略下面的所有分类
  149. func GetMatchTypeNamenNotNull() (items []*ReportMapping, err error) {
  150. o := orm.NewOrm()
  151. sql := `SELECT category_id,category_id_set,match_type_name FROM cygx_report_mapping WHERE match_type_name <> ''`
  152. _, err = o.Raw(sql).QueryRows(&items)
  153. return
  154. }
  155. type ReportMappingStatistical struct {
  156. CategoryId int `description:"分类ID"`
  157. SubCategoryName string `description:"主题名称"`
  158. MatchTypeName string `description:"匹配类型"`
  159. IsSummary string `description:"是否属于纪要,1 是,0否"`
  160. IsClass string `description:"是否归类,1 是,0否"`
  161. Pv int `description:"Pv"`
  162. Uv int `description:"Uv"`
  163. }
  164. //获取报表
  165. func GetStatisticalReportArtilce(chartPermissionId int) (items []*ReportMappingStatistical, err error) {
  166. o := orm.NewOrm()
  167. sql := `SELECT
  168. m.category_id,
  169. m.chart_permission_name,
  170. a.article_id,
  171. a.title,
  172. a.is_summary,
  173. a.is_class,
  174. (SELECT count( 1 ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS pv,
  175. (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS uv
  176. FROM
  177. cygx_report_mapping AS m
  178. INNER JOIN cygx_article AS a ON a.category_id = m.category_id
  179. WHERE
  180. m.chart_permission_id = ?
  181. and a.is_class= 1
  182. and a.is_report= 1
  183. and m.id !=28
  184. and a.is_filter= 0
  185. GROUP BY a.article_id`
  186. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  187. return
  188. }
  189. //获取报表
  190. func GetStatisticalReportArtilceExpert() (items []*ReportMappingStatistical, err error) {
  191. o := orm.NewOrm()
  192. sql := `SELECT
  193. a.article_id,
  194. a.title,
  195. a.is_summary,
  196. a.is_class,
  197. (SELECT count( 1 ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS pv,
  198. (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS uv
  199. FROM
  200. cygx_article AS a
  201. WHERE
  202. a.category_name LIKE '%研选%'`
  203. _, err = o.Raw(sql).QueryRows(&items)
  204. return
  205. }