report_mapping.go 7.9 KB

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