report_mapping.go 8.4 KB

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