report_mapping.go 8.4 KB

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