report_mapping.go 13 KB

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