report_mapping.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. 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=? LIMIT 1`
  136. err = o.Raw(sql, categoryId).QueryRow(&item)
  137. return
  138. }
  139. //判断该分类下最新的文章用户是否阅读
  140. func CheckThisCategoryNewArticleIsRead(uid, categoryId int) (count int, err error) {
  141. o := orm.NewOrm()
  142. sql := `SELECT COUNT(1) count
  143. FROM cygx_article_history_record
  144. WHERE user_id = ?
  145. 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)`
  146. err = o.Raw(sql, uid, categoryId).QueryRow(&count)
  147. return
  148. }
  149. //获取策略下面的所有分类
  150. func GetMatchTypeNamenNotNull() (items []*ReportMapping, err error) {
  151. o := orm.NewOrm()
  152. sql := `SELECT category_id,category_id_set,match_type_name FROM cygx_report_mapping WHERE match_type_name <> ''`
  153. _, err = o.Raw(sql).QueryRows(&items)
  154. return
  155. }
  156. type ReportMappingStatistical struct {
  157. CategoryId int `description:"分类ID"`
  158. SubCategoryName string `description:"主题名称"`
  159. MatchTypeName string `description:"匹配类型"`
  160. IsSummary string `description:"是否属于纪要,1 是,0否"`
  161. IsClass string `description:"是否归类,1 是,0否"`
  162. Pv int `description:"Pv"`
  163. Uv int `description:"Uv"`
  164. }
  165. //获取报表
  166. func GetStatisticalReportArtilce(chartPermissionId int) (items []*ReportMappingStatistical, err error) {
  167. o := orm.NewOrm()
  168. sql := `SELECT
  169. m.category_id,
  170. m.chart_permission_name,
  171. a.article_id,
  172. a.title,
  173. a.is_summary,
  174. a.is_class,
  175. (SELECT count( 1 ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS pv,
  176. (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS uv
  177. FROM
  178. cygx_report_mapping AS m
  179. INNER JOIN cygx_article AS a ON a.category_id = m.category_id
  180. WHERE
  181. m.chart_permission_id = ?
  182. and a.is_class= 1
  183. and a.is_report= 1
  184. and m.id !=28
  185. and a.is_filter= 0
  186. GROUP BY a.article_id`
  187. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  188. return
  189. }
  190. //获取报表
  191. func GetStatisticalReportArtilceExpert() (items []*ReportMappingStatistical, err error) {
  192. o := orm.NewOrm()
  193. sql := `SELECT
  194. a.article_id,
  195. a.title,
  196. a.is_summary,
  197. a.is_class,
  198. (SELECT count( 1 ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS pv,
  199. (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS uv
  200. FROM
  201. cygx_article AS a
  202. WHERE
  203. a.category_name LIKE '%研选%'`
  204. _, err = o.Raw(sql).QueryRows(&items)
  205. return
  206. }
  207. //通过分类ID获取详情 处理路演精华的映射
  208. func GetdetailByCategoryIdLyjh(categoryId int) (item *ReportMapping, err error) {
  209. o := orm.NewOrm()
  210. sql := `SELECT
  211. *
  212. FROM
  213. cygx_report_mapping
  214. WHERE
  215. sub_category_name = '路演精华'
  216. AND chart_permission_id = ( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ? )
  217. LIMIT 1 `
  218. err = o.Raw(sql, categoryId).QueryRow(&item)
  219. return
  220. }