report_mapping.go 12 KB

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