report_mapping.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "strconv"
  5. )
  6. type ReportMapping struct {
  7. CategoryId 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. CategoryIdSet int `description:"分类映射id"`
  15. PolymerizationId string `description:"分类聚合ID"`
  16. CeLueFieldId string `description:"策略平台领域ID"`
  17. }
  18. type ReportMappingHome struct {
  19. CategoryId int `description:"分类ID"`
  20. SubCategoryName string `description:"主题名称"`
  21. MatchTypeName string `description:"匹配类型"`
  22. IsRed bool `description:"是否标红"`
  23. }
  24. type TradeReportMapping struct {
  25. CategoryId int `description:"分类ID"`
  26. CategoryIdSet int `description:"分类映射id"`
  27. PolymerizationId string `description:"分类聚合ID"`
  28. MatchTypeName string `description:"匹配类型"`
  29. IsRed bool `description:"是否标红"`
  30. IsFollow bool `description:"是否关注"`
  31. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  32. UpdateTime string `description:"更新时间"`
  33. Readnum int `description:"阅读数量"`
  34. ListArticle []*HomeArticle `description:"文章列表"`
  35. }
  36. type ReportMappingResp struct {
  37. List []*ReportMapping
  38. }
  39. type ReportMappingHomeResp struct {
  40. List []*ReportMappingHome
  41. }
  42. type TradeReportMappingResp struct {
  43. List []*TradeReportMapping
  44. }
  45. // 获取所有分类
  46. func GetReportMappingStrategyAll() (items []*ReportMapping, err error) {
  47. o := orm.NewOrm()
  48. sql := `SELECT * FROM cygx_report_mapping WHERE 1=1 ORDER BY sort ASC `
  49. _, err = o.Raw(sql).QueryRows(&items)
  50. return
  51. }
  52. // 获取策略下面的所有分类
  53. func GetReportMappingStrategyHomeAll(userId, ChartPermissionId int) (items []*TradeReportMapping, err error) {
  54. o := orm.NewOrm()
  55. sql := `SELECT
  56. MAX( art.publish_date ) AS update_time,
  57. (SELECT COUNT(1) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id=art.article_id) AS readnum,
  58. re.category_id,re.sub_category_name,re.match_type_name
  59. FROM
  60. cygx_report_mapping AS re
  61. INNER JOIN cygx_article AS art ON art.category_id = re.category_id
  62. WHERE
  63. re.report_type = 1
  64. AND re.chart_permission_id = ?
  65. GROUP BY
  66. re.match_type_name
  67. ORDER BY
  68. sort DESC , art.publish_date DESC`
  69. _, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
  70. return
  71. }
  72. // 获取策略下面的所有分类
  73. func GetReportMappingStrategyHomeAllByCygx(userId, chartPermissionId int) (items []*TradeReportMapping, err error) {
  74. o := orm.NewOrm()
  75. sql := `SELECT
  76. MAX( art.publish_date ) AS update_time,
  77. (SELECT COUNT(1) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id=art.article_id) AS readnum,
  78. re.id AS category_id,
  79. re.match_type_name
  80. FROM
  81. cygx_report_mapping_cygx AS re
  82. INNER JOIN cygx_report_mapping_group AS mg ON mg.id_cygx = re.id
  83. INNER JOIN cygx_article AS art ON art.category_id = mg.category_id_celue
  84. WHERE
  85. 1 = 1
  86. AND re.chart_permission_id = ?
  87. AND re.report_type = 1
  88. AND re.list_group > 0
  89. GROUP BY
  90. re.match_type_name
  91. ORDER BY
  92. sort DESC,
  93. art.publish_date DESC`
  94. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  95. return
  96. }
  97. // 行业列表
  98. func GetTradeAll(ChartPermissionId int) (items []*TradeReportMapping, err error) {
  99. o := orm.NewOrm()
  100. sql := `SELECT
  101. re.category_id,
  102. re.category_id_set,
  103. re.polymerization_id,
  104. re.sub_category_name,
  105. re.match_type_name
  106. FROM
  107. cygx_report_mapping AS re
  108. WHERE
  109. re.chart_permission_id = ?
  110. AND re.report_type = 1
  111. AND re.category_id NOT IN ( 67 )
  112. ORDER BY
  113. re.sort DESC`
  114. _, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
  115. return
  116. }
  117. type IndustrialToArticleCategoryRep struct {
  118. CategoryId int `description:"分类ID"`
  119. MatchTypeName string `description:"匹配类型"`
  120. IsRed bool `description:"是否标红"`
  121. }
  122. type IndustrialToArticleCategoryListRep struct {
  123. LayoutTime string `description:"布局时间"`
  124. IndustryName string `description:"产业名称"`
  125. IndustrialManagementId int `description:"产业D"`
  126. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  127. List []*IndustrialToArticleCategoryRep
  128. ListSubject []*IndustrialSubject
  129. IndustryVideo *MicroVideoSimpleInfo
  130. AuthInfo *UserPermissionAuthInfo
  131. }
  132. // 通过分类ID获取详情
  133. func GetdetailByCategoryId(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. // 通过分类ID获取详情
  140. func GetdetailByCategoryIdPush(categoryId int) (item *ReportMapping, err error) {
  141. o := orm.NewOrm()
  142. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? `
  143. err = o.Raw(sql, categoryId).QueryRow(&item)
  144. return
  145. }
  146. // 通过分类ID获取详情主观客观
  147. func GetdetailByCategoryIdSando(categoryId int) (item *ReportMapping, err error) {
  148. o := orm.NewOrm()
  149. sql := `SELECT * FROM cygx_report_mapping WHERE permission_type>0 AND category_id=? LIMIT 1`
  150. err = o.Raw(sql, categoryId).QueryRow(&item)
  151. return
  152. }
  153. // 通过分类ID获取详情
  154. func GetdetailByCategoryIdOne(categoryId, reportType int) (item *ReportMapping, err error) {
  155. o := orm.NewOrm()
  156. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? AND report_type = ? LIMIT 1`
  157. err = o.Raw(sql, categoryId, reportType).QueryRow(&item)
  158. return
  159. }
  160. // 通过分类ID获取详情
  161. func GetdetailByCategoryIdSet(categoryId int) (ids string, err error) {
  162. o := orm.NewOrm()
  163. sql := `SELECT
  164. GROUP_CONCAT( DISTINCT category_id SEPARATOR ',' ) AS ids
  165. FROM
  166. cygx_report_mapping
  167. WHERE
  168. category_id_set = ? `
  169. err = o.Raw(sql, categoryId).QueryRow(&ids)
  170. return
  171. }
  172. // 判断该分类下最新的文章用户是否阅读
  173. func CheckThisCategoryNewArticleIsRead(uid, categoryId int) (count int, err error) {
  174. o := orm.NewOrm()
  175. sql := `SELECT COUNT(1) count
  176. FROM cygx_article_history_record
  177. WHERE user_id = ?
  178. 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)`
  179. err = o.Raw(sql, uid, categoryId).QueryRow(&count)
  180. return
  181. }
  182. // 获取策略下面的所有分类
  183. func GetMatchTypeNamenNotNull() (items []*ReportMapping, err error) {
  184. o := orm.NewOrm()
  185. sql := `SELECT category_id,match_type_name FROM cygx_report_mapping WHERE match_type_name <> ''`
  186. _, err = o.Raw(sql).QueryRows(&items)
  187. return
  188. }
  189. type ReportMappingStatistical struct {
  190. CategoryId int `description:"分类ID"`
  191. SubCategoryName string `description:"主题名称"`
  192. MatchTypeName string `description:"匹配类型"`
  193. IsSummary string `description:"是否属于纪要,1 是,0否"`
  194. IsClass string `description:"是否归类,1 是,0否"`
  195. Pv int `description:"Pv"`
  196. Uv int `description:"Uv"`
  197. }
  198. // 行业列表
  199. func GetTradeArticleAndProductInterior(ChartPermissionId int) (items []*TradeReportMapping, err error) {
  200. o := orm.NewOrm()
  201. sql := `SELECT
  202. map.sort,
  203. map.match_type_name,
  204. map.id AS category_id
  205. FROM
  206. cygx_report_mapping_cygx AS map
  207. INNER JOIN cygx_report_mapping_group AS g ON g.id_cygx = map.id
  208. INNER JOIN cygx_report_mapping_celue AS cl ON cl.category_id = g.category_id_celue
  209. INNER JOIN cygx_article AS art ON art.category_id = cl.category_id
  210. WHERE
  211. 1 = 1
  212. AND map.report_type = 1
  213. AND map.is_report = 1
  214. AND art.is_report = 1
  215. AND art.publish_status = 1
  216. AND map.chart_permission_id = ?
  217. GROUP BY
  218. match_type_name UNION ALL
  219. SELECT
  220. map.sort,
  221. map.match_type_name,
  222. map.id AS category_id
  223. FROM
  224. cygx_report_mapping_cygx AS map
  225. INNER JOIN cygx_industrial_management AS im ON im.chart_permission_id = map.chart_permission_id
  226. INNER JOIN cygx_product_interior AS art ON art.match_type_id = map.id
  227. WHERE
  228. 1 = 1
  229. AND art.STATUS = 1
  230. AND art.visible_range = 1
  231. AND map.report_type = 1
  232. AND map.chart_permission_id = ?
  233. GROUP BY
  234. match_type_name
  235. ORDER BY
  236. sort DESC `
  237. _, err = o.Raw(sql, ChartPermissionId, ChartPermissionId).QueryRows(&items)
  238. return
  239. }