report_mapping.go 8.4 KB

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