report_mapping.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. )
  5. type CygxReportMapping struct {
  6. Id int `description:"id"`
  7. ChartPermissionId int `description:"行业ID"`
  8. CategoryId int `description:"分类ID"`
  9. SubCategoryId int `description:"主题"`
  10. CategoryName int `description:"主题"`
  11. ChartPermissionName string `description:"行业名称"`
  12. SubCategoryName int `description:"主题"`
  13. MatchTypeName string `description:"分类名称"`
  14. ReportType int `description:"报告类型,2产业报告,1行业报告"`
  15. Sort int `description:"排序"`
  16. IsCustom int `description:"是否属于自定义的匹配类型 ,1是,0否"`
  17. IsSummary int `description:"是否是纪要库,1是,0否"`
  18. IsReport int `description:"是否是报告,1是,0否"`
  19. PermissionType int `description:"1主观,2客观"`
  20. CategoryIdSet int `description:"分类ID手动设置的分类"`
  21. PolymerizationId string `description:"分类聚合ID"`
  22. CeLueFieldId string `description:"策略平台领域ID"`
  23. }
  24. type ReportMapping struct {
  25. CategoryId int `description:"分类ID"`
  26. CategoryIdSet int `description:"分类ID手动设置的分类"`
  27. SubCategoryName string `description:"主题"`
  28. MatchTypeName string `description:"分类名称"`
  29. ChartPermissionName string `description:"行业名称"`
  30. ChartPermissionId int `description:"行业ID"`
  31. IsRed bool `description:"是否标红"`
  32. PermissionType int `description:"1主观,2客观"`
  33. PolymerizationId string `description:"分类聚合ID"`
  34. CeLueFieldId string `description:"策略平台领域ID"`
  35. }
  36. type ReportMappingHome struct {
  37. CategoryId int `description:"分类ID"`
  38. SubCategoryName string `description:"主题名称"`
  39. MatchTypeName string `description:"匹配类型"`
  40. IsRed bool `description:"是否标红"`
  41. }
  42. type TradeReportMapping struct {
  43. CategoryId int `description:"分类ID"`
  44. CategoryIdSet int `description:"分类映射id"`
  45. PolymerizationId string `description:"分类聚合ID"`
  46. SubCategoryName string `description:"主题名称"`
  47. MatchTypeName string `description:"匹配类型"`
  48. IsRed bool `description:"是否标红"`
  49. UpdateTime string `description:"更新时间"`
  50. Readnum int `description:"阅读数量"`
  51. }
  52. type ReportMappingResp struct {
  53. List []*ReportMapping
  54. }
  55. type ReportMappingHomeResp struct {
  56. List []*ReportMappingHome
  57. }
  58. type TradeReportMappingResp struct {
  59. List []*TradeReportMapping
  60. }
  61. // 获取策略下面的所有分类
  62. func GetReportMappingStrategyAll() (items []*ReportMapping, err error) {
  63. o := orm.NewOrm()
  64. sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND chart_permission_id=23 ORDER BY sort ASC `
  65. _, err = o.Raw(sql).QueryRows(&items)
  66. return
  67. }
  68. // 获取策略下面的所有分类
  69. func GetReportMappingStrategyHomeAll(chartPermissionId int) (items []*ReportMappingHome, err error) {
  70. o := orm.NewOrm()
  71. sql := `SELECT
  72. re.category_id,re.sub_category_name,re.match_type_name
  73. FROM
  74. cygx_report_mapping AS re
  75. INNER JOIN cygx_article AS art ON art.category_id = re.category_id
  76. WHERE
  77. re.report_type = 1
  78. AND re.chart_permission_id = ?
  79. GROUP BY
  80. re.match_type_name
  81. ORDER BY
  82. sort DESC , art.publish_date DESC`
  83. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  84. return
  85. }
  86. // 行业列表
  87. func GetTradeAll(ChartPermissionId int) (items []*TradeReportMapping, err error) {
  88. o := orm.NewOrm()
  89. sql := `SELECT
  90. re.category_id,
  91. re.category_id_set,
  92. re.polymerization_id,
  93. re.sub_category_name,
  94. re.match_type_name
  95. FROM
  96. cygx_report_mapping AS re
  97. WHERE
  98. re.chart_permission_id = ?
  99. AND re.report_type = 1
  100. AND re.category_id NOT IN ( 67 )
  101. ORDER BY
  102. re.sort DESC `
  103. _, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
  104. return
  105. }
  106. // 行业列表
  107. func GetTradeArticleAndProductInterior(ChartPermissionId int) (items []*TradeReportMapping, err error) {
  108. o := orm.NewOrm()
  109. sql := `SELECT
  110. map.sort,
  111. map.match_type_name,
  112. map.id AS category_id
  113. FROM
  114. cygx_report_mapping_cygx AS map
  115. INNER JOIN cygx_report_mapping_group AS g ON g.id_cygx = map.id
  116. INNER JOIN cygx_report_mapping_celue AS cl ON cl.category_id = g.category_id_celue
  117. INNER JOIN cygx_article AS art ON art.category_id = cl.category_id
  118. WHERE
  119. 1 = 1
  120. AND map.report_type = 1
  121. AND map.is_report = 1
  122. AND art.is_report = 1
  123. AND art.publish_status = 1
  124. AND map.chart_permission_id = ?
  125. GROUP BY
  126. match_type_name UNION ALL
  127. SELECT
  128. map.sort,
  129. map.match_type_name,
  130. map.id AS category_id
  131. FROM
  132. cygx_report_mapping_cygx AS map
  133. INNER JOIN cygx_industrial_management AS im ON im.chart_permission_id = map.chart_permission_id
  134. INNER JOIN cygx_product_interior AS art ON art.match_type_id = map.id
  135. WHERE
  136. 1 = 1
  137. AND art.STATUS = 1
  138. AND art.visible_range = 1
  139. AND map.report_type = 1
  140. AND map.chart_permission_id = ?
  141. GROUP BY
  142. match_type_name
  143. ORDER BY
  144. sort DESC `
  145. _, err = o.Raw(sql, ChartPermissionId, ChartPermissionId).QueryRows(&items)
  146. return
  147. }
  148. type IndustrialToArticleCategoryRep struct {
  149. CategoryId int `description:"分类ID"`
  150. MatchTypeName string `description:"匹配类型"`
  151. IsRed bool `description:"是否标红"`
  152. }
  153. type IndustrialToArticleCategoryListRep struct {
  154. AuthInfo *UserPermissionAuthInfo
  155. LayoutTime string `description:"布局时间"`
  156. IndustryName string `description:"产业名称"`
  157. IndustrialManagementId int `description:"产业D"`
  158. IsShowFollowButton bool `description:"是否展示关注取关按钮"`
  159. IsFollowButton bool `description:"是否关注"`
  160. IndustryVideo *MicroVideoSimpleInfo
  161. List []*IndustrialToArticleCategoryRep
  162. }
  163. // 通过分类ID获取详情
  164. func GetdetailByCategoryId(categoryId int) (item *ReportMapping, err error) {
  165. o := orm.NewOrm()
  166. sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND category_id=? `
  167. err = o.Raw(sql, categoryId).QueryRow(&item)
  168. return
  169. }
  170. // 通过分类ID获取详情
  171. func GetdetailByCategoryIdSet(categoryId int) (ids string, err error) {
  172. o := orm.NewOrm()
  173. sql := `SELECT
  174. GROUP_CONCAT( DISTINCT category_id SEPARATOR ',' ) AS ids
  175. FROM
  176. cygx_report_mapping
  177. WHERE
  178. category_id_set = ? `
  179. err = o.Raw(sql, categoryId).QueryRow(&ids)
  180. return
  181. }
  182. // 通过分类ID获取详情
  183. func GetdetailByCategoryIdPush(categoryId int) (item *ReportMapping, err error) {
  184. o := orm.NewOrm()
  185. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? LIMIT 1 `
  186. err = o.Raw(sql, categoryId).QueryRow(&item)
  187. return
  188. }
  189. // 通过分类ID获取详情主观客观
  190. func GetdetailByCategoryIdSando(categoryId int) (item *ReportMapping, err error) {
  191. o := orm.NewOrm()
  192. sql := `SELECT * FROM cygx_report_mapping WHERE permission_type>0 AND category_id=? LIMIT 1`
  193. err = o.Raw(sql, categoryId).QueryRow(&item)
  194. return
  195. }
  196. // 通过分类ID获取详情
  197. func GetdetailByCategoryIdOne(categoryId int) (item *ReportMapping, err error) {
  198. o := orm.NewOrm()
  199. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? AND report_type = 2 LIMIT 1`
  200. err = o.Raw(sql, categoryId).QueryRow(&item)
  201. return
  202. }
  203. // 通过分类ID获取详情
  204. func GetdetailByCategoryIdOneByHangye(categoryId int) (item *ReportMapping, err error) {
  205. o := orm.NewOrm()
  206. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? AND report_type = 1 LIMIT 1`
  207. err = o.Raw(sql, categoryId).QueryRow(&item)
  208. return
  209. }
  210. // 判断该分类下最新的文章用户是否阅读
  211. func CheckThisCategoryNewArticleIsRead(uid, categoryId int) (count int, err error) {
  212. o := orm.NewOrm()
  213. sql := `SELECT COUNT(1) count
  214. FROM cygx_article_history_record
  215. WHERE user_id = ?
  216. 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)`
  217. err = o.Raw(sql, uid, categoryId).QueryRow(&count)
  218. return
  219. }
  220. // 获取策略下面的所有分类
  221. func GetMatchTypeNamenNotNull() (items []*ReportMapping, err error) {
  222. o := orm.NewOrm()
  223. sql := `SELECT category_id,category_id_set,match_type_name FROM cygx_report_mapping WHERE match_type_name <> ''`
  224. _, err = o.Raw(sql).QueryRows(&items)
  225. return
  226. }
  227. type ReportMappingStatistical struct {
  228. CategoryId int `description:"分类ID"`
  229. SubCategoryName string `description:"主题名称"`
  230. MatchTypeName string `description:"匹配类型"`
  231. IsSummary string `description:"是否属于纪要,1 是,0否"`
  232. IsClass string `description:"是否归类,1 是,0否"`
  233. Pv int `description:"Pv"`
  234. Uv int `description:"Uv"`
  235. }
  236. // 获取报表
  237. func GetStatisticalReportArtilce(chartPermissionId int) (items []*ReportMappingStatistical, err error) {
  238. o := orm.NewOrm()
  239. sql := `SELECT
  240. m.category_id,
  241. m.chart_permission_name,
  242. a.article_id,
  243. a.title,
  244. a.is_summary,
  245. a.is_class,
  246. (SELECT count( 1 ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS pv,
  247. (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS uv
  248. FROM
  249. cygx_report_mapping AS m
  250. INNER JOIN cygx_article AS a ON a.category_id = m.category_id
  251. WHERE
  252. m.chart_permission_id = ?
  253. and a.is_class= 1
  254. and a.is_report= 1
  255. and m.id !=28
  256. and a.is_filter= 0
  257. GROUP BY a.article_id`
  258. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  259. return
  260. }
  261. // 获取报表
  262. func GetStatisticalReportArtilceExpert() (items []*ReportMappingStatistical, err error) {
  263. o := orm.NewOrm()
  264. sql := `SELECT
  265. a.article_id,
  266. a.title,
  267. a.is_summary,
  268. a.is_class,
  269. (SELECT count( 1 ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS pv,
  270. (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS uv
  271. FROM
  272. cygx_article AS a
  273. WHERE
  274. a.category_name LIKE '%研选%'`
  275. _, err = o.Raw(sql).QueryRows(&items)
  276. return
  277. }
  278. // 通过分类ID获取详情 处理路演精华的映射
  279. func GetdetailByCategoryIdLyjh(categoryId int) (item *ReportMapping, err error) {
  280. o := orm.NewOrm()
  281. sql := `SELECT
  282. *
  283. FROM
  284. cygx_report_mapping
  285. WHERE
  286. sub_category_name = '路演精华'
  287. AND chart_permission_id = ( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ? )
  288. LIMIT 1 `
  289. err = o.Raw(sql, categoryId).QueryRow(&item)
  290. return
  291. }
  292. // 获取分类
  293. func GetReportMappingList(condition string, pars []interface{}) (items []*ReportMapping, err error) {
  294. o := orm.NewOrm()
  295. sql := `SELECT * FROM cygx_report_mapping WHERE 1=1 `
  296. if condition != `` {
  297. sql += condition
  298. }
  299. _, err = o.Raw(sql, pars).QueryRows(&items)
  300. return
  301. }
  302. // 获取所有的报告分类
  303. func GetReportMappingByPermissionName(chartPermissionName string) (items []*ReportMapping, err error) {
  304. o := orm.NewOrm()
  305. sql := `SELECT
  306. *
  307. FROM
  308. cygx_report_mapping
  309. WHERE
  310. 1 = 1
  311. AND chart_permission_name = ? `
  312. _, err = o.Raw(sql, chartPermissionName).QueryRows(&items)
  313. return
  314. }
  315. // 获取所有的报告分类
  316. func GetReportMapping() (items []*CygxReportMapping, err error) {
  317. o := orm.NewOrm()
  318. sql := `SELECT
  319. *
  320. FROM
  321. cygx_report_mapping `
  322. _, err = o.Raw(sql).QueryRows(&items)
  323. return
  324. }