report_mapping.go 7.8 KB

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