report_mapping.go 7.9 KB

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