report_mapping.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. IsFllow bool `description:"是否关注"`
  36. }
  37. type ReportMappingHome struct {
  38. CategoryId int `description:"分类ID"`
  39. SubCategoryName string `description:"主题名称"`
  40. MatchTypeName string `description:"匹配类型"`
  41. IsRed bool `description:"是否标红"`
  42. ListGroup int `description:"第几组"`
  43. }
  44. type TradeReportMapping struct {
  45. CategoryId int `description:"分类ID"`
  46. CategoryIdSet int `description:"分类映射id"`
  47. PolymerizationId string `description:"分类聚合ID"`
  48. SubCategoryName string `description:"主题名称"`
  49. MatchTypeName string `description:"匹配类型"`
  50. IsRed bool `description:"是否标红"`
  51. UpdateTime string `description:"更新时间"`
  52. Readnum int `description:"阅读数量"`
  53. }
  54. type ReportMappingResp struct {
  55. List []*ReportMapping
  56. }
  57. type ReportMappingHomeResp struct {
  58. List []*ReportMappingHome
  59. ListGroup1 []*ReportMappingHome
  60. ListGroup2 []*ReportMappingHome
  61. ListGroup3 []*ReportMappingHome
  62. ListGroup4 []*ReportMappingHome
  63. }
  64. type TradeReportMappingResp struct {
  65. List []*TradeReportMapping
  66. }
  67. // 获取策略下面的所有分类
  68. func GetReportMappingStrategyAll() (items []*ReportMapping, err error) {
  69. o := orm.NewOrm()
  70. sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND chart_permission_id=23 ORDER BY sort ASC `
  71. _, err = o.Raw(sql).QueryRows(&items)
  72. return
  73. }
  74. // 获取策略下面的所有分类
  75. func GetReportMappingStrategyAllXzs() (items []*IndustrialManagementRep, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT
  78. match_type_name AS industry_name,
  79. category_id AS industrial_management_id,
  80. chart_permission_id
  81. FROM
  82. cygx_report_mapping
  83. WHERE
  84. report_type = 1
  85. AND chart_permission_name IN ('策略','固收')
  86. ORDER BY
  87. sort ASC `
  88. _, err = o.Raw(sql).QueryRows(&items)
  89. return
  90. }
  91. // 获取策略下面的所有分类
  92. func GetReportMappingStrategyHomeAll(chartPermissionId int) (items []*ReportMappingHome, err error) {
  93. o := orm.NewOrm()
  94. sql := `SELECT
  95. re.category_id,re.sub_category_name,re.match_type_name
  96. FROM
  97. cygx_report_mapping AS re
  98. INNER JOIN cygx_article AS art ON art.category_id = re.category_id
  99. WHERE
  100. re.report_type = 1
  101. AND re.chart_permission_id = ?
  102. GROUP BY
  103. re.match_type_name
  104. ORDER BY
  105. sort DESC , art.publish_date DESC`
  106. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  107. return
  108. }
  109. // 获取策略下面的所有分类
  110. func GetReportMappingStrategyHomeAllByCygx(chartPermissionId int) (items []*ReportMappingHome, err error) {
  111. o := orm.NewOrm()
  112. sql := `SELECT
  113. re.id AS category_id,
  114. re.list_group,
  115. re.match_type_name
  116. FROM
  117. cygx_report_mapping_cygx AS re
  118. INNER JOIN cygx_report_mapping_group AS mg ON mg.id_cygx = re.id
  119. INNER JOIN cygx_article AS art ON art.category_id = mg.category_id_celue
  120. WHERE
  121. 1 = 1
  122. AND re.chart_permission_id = ?
  123. AND re.report_type = 1
  124. AND re.list_group > 0
  125. GROUP BY
  126. re.match_type_name
  127. ORDER BY
  128. sort DESC,
  129. art.publish_date DESC`
  130. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  131. return
  132. }
  133. // 行业列表
  134. func GetTradeAll(ChartPermissionId int) (items []*TradeReportMapping, err error) {
  135. o := orm.NewOrm()
  136. sql := `SELECT
  137. re.category_id,
  138. re.category_id_set,
  139. re.polymerization_id,
  140. re.sub_category_name,
  141. re.match_type_name
  142. FROM
  143. cygx_report_mapping AS re
  144. WHERE
  145. re.chart_permission_id = ?
  146. AND re.report_type = 1
  147. AND re.category_id NOT IN ( 67 )
  148. ORDER BY
  149. re.sort DESC `
  150. _, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
  151. return
  152. }
  153. // 行业列表
  154. func GetTradeArticleAndProductInterior(ChartPermissionId int) (items []*TradeReportMapping, err error) {
  155. o := orm.NewOrm()
  156. sql := `SELECT
  157. map.sort,
  158. map.match_type_name,
  159. map.id AS category_id
  160. FROM
  161. cygx_report_mapping_cygx AS map
  162. INNER JOIN cygx_report_mapping_group AS g ON g.id_cygx = map.id
  163. INNER JOIN cygx_report_mapping_celue AS cl ON cl.category_id = g.category_id_celue
  164. INNER JOIN cygx_article AS art ON art.category_id = cl.category_id
  165. WHERE
  166. 1 = 1
  167. AND map.report_type = 1
  168. AND map.is_report = 1
  169. AND art.is_report = 1
  170. AND art.publish_status = 1
  171. AND map.chart_permission_id = ?
  172. GROUP BY
  173. match_type_name UNION ALL
  174. SELECT
  175. map.sort,
  176. map.match_type_name,
  177. map.id AS category_id
  178. FROM
  179. cygx_report_mapping_cygx AS map
  180. INNER JOIN cygx_industrial_management AS im ON im.chart_permission_id = map.chart_permission_id
  181. INNER JOIN cygx_product_interior AS art ON art.match_type_id = map.id
  182. WHERE
  183. 1 = 1
  184. AND art.STATUS = 1
  185. AND art.visible_range = 1
  186. AND map.report_type = 1
  187. AND map.chart_permission_id = ?
  188. GROUP BY
  189. match_type_name
  190. ORDER BY
  191. sort DESC `
  192. _, err = o.Raw(sql, ChartPermissionId, ChartPermissionId).QueryRows(&items)
  193. return
  194. }
  195. type IndustrialToArticleCategoryRep struct {
  196. CategoryId int `description:"分类ID"`
  197. MatchTypeName string `description:"匹配类型"`
  198. IsRed bool `description:"是否标红"`
  199. }
  200. type IndustrialToArticleCategoryListRep struct {
  201. AuthInfo *UserPermissionAuthInfo
  202. LayoutTime string `description:"布局时间"`
  203. IndustryName string `description:"产业名称"`
  204. IndustrialManagementId int `description:"产业D"`
  205. IsShowFollowButton bool `description:"是否展示关注取关按钮"`
  206. IsFollowButton bool `description:"是否关注"`
  207. IndustryVideo *MicroVideoSimpleInfo
  208. List []*IndustrialToArticleCategoryRep
  209. }
  210. // 通过分类ID获取详情
  211. func GetdetailByCategoryId(categoryId int) (item *ReportMapping, err error) {
  212. o := orm.NewOrm()
  213. sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND category_id=? `
  214. err = o.Raw(sql, categoryId).QueryRow(&item)
  215. return
  216. }
  217. // 通过分类ID获取详情
  218. func GetdetailByCategoryIdSet(categoryId int) (ids string, err error) {
  219. o := orm.NewOrm()
  220. sql := `SELECT
  221. GROUP_CONCAT( DISTINCT category_id SEPARATOR ',' ) AS ids
  222. FROM
  223. cygx_report_mapping
  224. WHERE
  225. category_id_set = ? `
  226. err = o.Raw(sql, categoryId).QueryRow(&ids)
  227. return
  228. }
  229. // 通过分类ID获取详情
  230. func GetdetailByCategoryIdPush(categoryId int) (item *ReportMapping, err error) {
  231. o := orm.NewOrm()
  232. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? LIMIT 1 `
  233. err = o.Raw(sql, categoryId).QueryRow(&item)
  234. return
  235. }
  236. // 通过分类ID获取详情主观客观
  237. func GetdetailByCategoryIdSando(categoryId int) (item *ReportMapping, err error) {
  238. o := orm.NewOrm()
  239. sql := `SELECT * FROM cygx_report_mapping WHERE permission_type>0 AND category_id=? LIMIT 1`
  240. err = o.Raw(sql, categoryId).QueryRow(&item)
  241. return
  242. }
  243. // 通过分类ID获取详情
  244. func GetdetailByCategoryIdOne(categoryId int) (item *ReportMapping, err error) {
  245. o := orm.NewOrm()
  246. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? AND report_type = 2 LIMIT 1`
  247. err = o.Raw(sql, categoryId).QueryRow(&item)
  248. return
  249. }
  250. // 通过分类ID获取详情
  251. func GetdetailByCategoryIdOneByHangye(categoryId int) (item *ReportMapping, err error) {
  252. o := orm.NewOrm()
  253. sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? AND report_type = 1 LIMIT 1`
  254. err = o.Raw(sql, categoryId).QueryRow(&item)
  255. return
  256. }
  257. // 判断该分类下最新的文章用户是否阅读
  258. func CheckThisCategoryNewArticleIsRead(uid, categoryId int) (count int, err error) {
  259. o := orm.NewOrm()
  260. sql := `SELECT COUNT(1) count
  261. FROM cygx_article_history_record
  262. WHERE user_id = ?
  263. 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)`
  264. err = o.Raw(sql, uid, categoryId).QueryRow(&count)
  265. return
  266. }
  267. // 获取策略下面的所有分类
  268. func GetMatchTypeNamenNotNull() (items []*ReportMapping, err error) {
  269. o := orm.NewOrm()
  270. sql := `SELECT category_id,category_id_set,match_type_name FROM cygx_report_mapping WHERE match_type_name <> ''`
  271. _, err = o.Raw(sql).QueryRows(&items)
  272. return
  273. }
  274. type ReportMappingStatistical struct {
  275. CategoryId int `description:"分类ID"`
  276. SubCategoryName string `description:"主题名称"`
  277. MatchTypeName string `description:"匹配类型"`
  278. IsSummary string `description:"是否属于纪要,1 是,0否"`
  279. IsClass string `description:"是否归类,1 是,0否"`
  280. Pv int `description:"Pv"`
  281. Uv int `description:"Uv"`
  282. }
  283. // 获取报表
  284. func GetStatisticalReportArtilce(chartPermissionId int) (items []*ReportMappingStatistical, err error) {
  285. o := orm.NewOrm()
  286. sql := `SELECT
  287. m.category_id,
  288. m.chart_permission_name,
  289. a.article_id,
  290. a.title,
  291. a.is_summary,
  292. a.is_class,
  293. (SELECT count( 1 ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS pv,
  294. (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS uv
  295. FROM
  296. cygx_report_mapping AS m
  297. INNER JOIN cygx_article AS a ON a.category_id = m.category_id
  298. WHERE
  299. m.chart_permission_id = ?
  300. and a.is_class= 1
  301. and a.is_report= 1
  302. and m.id !=28
  303. and a.is_filter= 0
  304. GROUP BY a.article_id`
  305. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  306. return
  307. }
  308. // 获取报表
  309. func GetStatisticalReportArtilceExpert() (items []*ReportMappingStatistical, err error) {
  310. o := orm.NewOrm()
  311. sql := `SELECT
  312. a.article_id,
  313. a.title,
  314. a.is_summary,
  315. a.is_class,
  316. (SELECT count( 1 ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS pv,
  317. (SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h WHERE h.article_id = a.article_id ) AS uv
  318. FROM
  319. cygx_article AS a
  320. WHERE
  321. a.category_name LIKE '%研选%'`
  322. _, err = o.Raw(sql).QueryRows(&items)
  323. return
  324. }
  325. // 通过分类ID获取详情 处理路演精华的映射
  326. func GetdetailByCategoryIdLyjh(categoryId int) (item *ReportMapping, err error) {
  327. o := orm.NewOrm()
  328. sql := `SELECT
  329. *
  330. FROM
  331. cygx_report_mapping
  332. WHERE
  333. sub_category_name = '路演精华'
  334. AND chart_permission_id = ( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ? )
  335. LIMIT 1 `
  336. err = o.Raw(sql, categoryId).QueryRow(&item)
  337. return
  338. }
  339. // 获取分类
  340. func GetReportMappingList(condition string, pars []interface{}) (items []*ReportMapping, err error) {
  341. o := orm.NewOrm()
  342. sql := `SELECT * FROM cygx_report_mapping WHERE 1=1 `
  343. if condition != `` {
  344. sql += condition
  345. }
  346. _, err = o.Raw(sql, pars).QueryRows(&items)
  347. return
  348. }
  349. // 获取所有的报告分类
  350. func GetReportMappingByPermissionName(chartPermissionName string) (items []*ReportMapping, err error) {
  351. o := orm.NewOrm()
  352. sql := `SELECT
  353. *
  354. FROM
  355. cygx_report_mapping
  356. WHERE
  357. 1 = 1
  358. AND chart_permission_name = ? `
  359. _, err = o.Raw(sql, chartPermissionName).QueryRows(&items)
  360. return
  361. }
  362. // 获取所有的报告分类
  363. func GetReportMapping() (items []*CygxReportMapping, err error) {
  364. o := orm.NewOrm()
  365. sql := `SELECT
  366. *
  367. FROM
  368. cygx_report_mapping `
  369. _, err = o.Raw(sql).QueryRows(&items)
  370. return
  371. }
  372. // 通过分类ID对应的系列名称
  373. func GetdetailByCategoryIdLabel(categoryId int) (item *CygxReportMapping, err error) {
  374. o := orm.NewOrm()
  375. sql := `SELECT
  376. c.id,c.match_type_name
  377. FROM
  378. cygx_report_mapping_group as g
  379. INNER JOIN cygx_report_mapping_cygx as c ON c.id = g.id_cygx
  380. WHERE
  381. category_id_celue = ? LIMIT 1`
  382. err = o.Raw(sql, categoryId).QueryRow(&item)
  383. return
  384. }
  385. func GetCygxReportMappingById(id int) (items *CygxReportMapping, err error) {
  386. o := orm.NewOrm()
  387. sql := `SELECT * FROM cygx_report_mapping_cygx WHERE id = ?`
  388. err = o.Raw(sql, id).QueryRow(&items)
  389. return
  390. }