report.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. package controllers
  2. import (
  3. "eta/eta_mini_bridge/models"
  4. "eta/eta_mini_bridge/models/response"
  5. "eta/eta_mini_bridge/services"
  6. "eta/eta_mini_bridge/utils"
  7. "html"
  8. "strconv"
  9. "time"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. )
  12. type ReportController struct {
  13. BaseAuthController
  14. }
  15. // @Title List
  16. // @Description create users
  17. // @Param ChartPermissionId query int true "品种ID"
  18. // @Param Level query int true "品种层级"
  19. // @Param PageSize query int true "每页数据条数"
  20. // @Param CurrentIndex query int true "当前页页码,从1开始"
  21. // @Param RangeType query string true "范围类型,1-一天内,2-一周内,3-半年内"
  22. // @Param ClassifyId query int true "分类id"
  23. // @Success 200 {object} response.ReportListResp
  24. // @router /list [get]
  25. func (this *ReportController) List() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. pageSize, _ := this.GetInt("PageSize")
  32. currentIndex, _ := this.GetInt("CurrentIndex")
  33. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  34. level, _ := this.GetInt("Level")
  35. rangeType, _ := this.GetInt("RangeType")
  36. classifyId, _ := this.GetInt("ClassifyId")
  37. if chartPermissionId <= 0 {
  38. br.Msg = "品种参数错误"
  39. return
  40. }
  41. var condition string
  42. switch rangeType {
  43. case 1:
  44. condition += ` AND DATE(a.modify_time)=DATE(NOW()) `
  45. case 2:
  46. condition += ` AND DATE(a.modify_time) BETWEEN DATE_SUB(NOW(),INTERVAL 1 WEEK) AND NOW() `
  47. case 3:
  48. condition += ` AND DATE(a.modify_time) BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW() `
  49. }
  50. var startSize int
  51. if pageSize <= 0 {
  52. pageSize = utils.PageSize20
  53. }
  54. if currentIndex <= 0 {
  55. currentIndex = 1
  56. }
  57. startSize = utils.StartIndex(currentIndex, pageSize)
  58. classifyList, err := models.GetClassifyList()
  59. if err != nil {
  60. br.Msg = "获取数据失败"
  61. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  62. return
  63. }
  64. classifyMap := make(map[int]*models.ClassifyView)
  65. isHas := false
  66. for _, v := range classifyList {
  67. if v.Id == classifyId && classifyId != 0 {
  68. isHas = true
  69. }
  70. classifyMap[v.Id] = v
  71. }
  72. if !isHas && classifyId != 0 {
  73. br.Msg = "分类不存在"
  74. return
  75. }
  76. leafClassifyIds := getLeafClassifyIds(classifyMap, classifyId)
  77. classifyIdMap := make(map[int]struct{})
  78. for _, v := range leafClassifyIds {
  79. classifyIdMap[v] = struct{}{}
  80. }
  81. var total int
  82. var reportList []*models.ReportList
  83. classifyFirstIds := make([]int, 0)
  84. classifySecondIds := make([]int, 0)
  85. classifyThirdIds := make([]int, 0)
  86. switch level {
  87. case 2:
  88. classifyIds, err := models.GetClassifyIdsListById(chartPermissionId)
  89. if err != nil {
  90. br.Msg = "获取报告列表失败"
  91. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  92. return
  93. }
  94. if len(classifyIds) == 0 {
  95. br.Msg = "该品种下没有绑定分类"
  96. br.ErrMsg = "获取数据失败,品种id:" + strconv.Itoa(chartPermissionId)
  97. return
  98. }
  99. classifyIds = utils.Unique(classifyIds)
  100. // 根据分类筛选报告
  101. var selectedClassifyId []int
  102. if classifyId > 0 {
  103. for _, v := range classifyIds {
  104. if _, ok := classifyIdMap[v]; ok {
  105. selectedClassifyId = append(selectedClassifyId, v)
  106. }
  107. }
  108. } else {
  109. selectedClassifyId = classifyIds
  110. }
  111. classifyList, err := models.GetClassifyListByIds(selectedClassifyId)
  112. if err != nil {
  113. br.Msg = "获取报告列表失败"
  114. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  115. return
  116. }
  117. for _, v := range classifyList {
  118. switch v.Level {
  119. case 1:
  120. classifyFirstIds = append(classifyFirstIds, v.Id)
  121. case 2:
  122. classifySecondIds = append(classifySecondIds, v.Id)
  123. case 3:
  124. classifyThirdIds = append(classifyThirdIds, v.Id)
  125. }
  126. }
  127. tmptotal, err := models.GetReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
  128. if err != nil {
  129. br.Msg = "获取数据失败"
  130. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  131. return
  132. }
  133. total = tmptotal
  134. tmpReportList, err := models.GetReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition, startSize, pageSize)
  135. if err != nil {
  136. br.Msg = "获取报告列表失败"
  137. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  138. return
  139. }
  140. reportList = tmpReportList
  141. case 1:
  142. chartPermissionIds, err := models.GetChildChartPermissionIdsById(chartPermissionId)
  143. if err != nil {
  144. br.Msg = "获取报告列表失败"
  145. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  146. return
  147. }
  148. if len(chartPermissionIds) == 0 {
  149. br.Msg = "该品种下没有绑定分类"
  150. br.ErrMsg = "获取数据失败,品种id:" + strconv.Itoa(chartPermissionId)
  151. return
  152. }
  153. classifyIds, err := models.GetClassifyIdsListByIds(chartPermissionIds)
  154. if err != nil {
  155. br.Msg = "获取报告列表失败"
  156. br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  157. return
  158. }
  159. if len(classifyIds) == 0 {
  160. br.Msg = "该品种下没有绑定分类"
  161. return
  162. }
  163. classifyIds = utils.Unique(classifyIds)
  164. // 根据分类筛选报告
  165. var selectedClassifyId []int
  166. if classifyId > 0 {
  167. for _, v := range classifyIds {
  168. if _, ok := classifyIdMap[v]; ok {
  169. selectedClassifyId = append(selectedClassifyId, v)
  170. }
  171. }
  172. } else {
  173. selectedClassifyId = classifyIds
  174. }
  175. classifyList, err := models.GetClassifyListByIds(selectedClassifyId)
  176. if err != nil {
  177. br.Msg = "获取报告列表失败"
  178. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  179. return
  180. }
  181. for _, v := range classifyList {
  182. switch v.Level {
  183. case 1:
  184. classifyFirstIds = append(classifyFirstIds, v.Id)
  185. case 2:
  186. classifySecondIds = append(classifySecondIds, v.Id)
  187. case 3:
  188. classifyThirdIds = append(classifyThirdIds, v.Id)
  189. }
  190. }
  191. tmptotal, err := models.GetReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
  192. if err != nil {
  193. br.Msg = "获取数据失败"
  194. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  195. return
  196. }
  197. total = tmptotal
  198. tmpReportList, err := models.GetReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition, startSize, pageSize)
  199. if err != nil {
  200. br.Msg = "获取报告列表失败"
  201. br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  202. return
  203. }
  204. reportList = tmpReportList
  205. default:
  206. br.Msg = "层级参数错误"
  207. return
  208. }
  209. page := paging.GetPaging(currentIndex, pageSize, total)
  210. resp := new(response.ReportListResp)
  211. resp.Paging = page
  212. resp.List = reportList
  213. br.Ret = 200
  214. br.Success = true
  215. br.Msg = "获取成功"
  216. br.Data = resp
  217. }
  218. func getLeafClassifyIds(classifyMap map[int]*models.ClassifyView, keyId int) []int {
  219. var leafClassifyIds []int
  220. curClassify := classifyMap[keyId]
  221. if curClassify.HasChild == 0 {
  222. leafClassifyIds = append(leafClassifyIds, curClassify.Id)
  223. return leafClassifyIds
  224. }
  225. for _, v := range classifyMap {
  226. if v.ParentId == curClassify.Id {
  227. if v.HasChild == 0 {
  228. leafClassifyIds = append(leafClassifyIds, v.Id)
  229. } else {
  230. leafClassifyIds = append(leafClassifyIds, getLeafClassifyIds(classifyMap, v.Id)...)
  231. }
  232. }
  233. }
  234. return leafClassifyIds
  235. }
  236. // @Title 研报详情
  237. // @Description 研报详情接口
  238. // @Param ReportId query int true "报告id"
  239. // @Param UserId query int true "用户id"
  240. // @Success 200 {object} response.ReportDetailResp
  241. // @router /detail [get]
  242. func (this *ReportController) Detail() {
  243. br := new(models.BaseResponse).Init()
  244. defer func() {
  245. this.Data["json"] = br
  246. this.ServeJSON()
  247. }()
  248. reportId, err := this.GetInt("ReportId")
  249. userId, err := this.GetInt("UserId")
  250. if err != nil {
  251. br.Msg = "参数获取失败"
  252. br.ErrMsg = "参数获取失败,Err:" + err.Error()
  253. return
  254. }
  255. if reportId <= 0 {
  256. br.Msg = "参数错误"
  257. br.ErrMsg = "参数错误,报告id小于等于0"
  258. return
  259. }
  260. if userId <= 0 {
  261. br.Msg = "参数错误"
  262. br.ErrMsg = "参数错误,用户id小于等于0"
  263. return
  264. }
  265. user, err := models.GetUserById(userId)
  266. if err != nil {
  267. br.Msg = "用户不存在"
  268. br.ErrMsg = "用户不存在,系统异常,Err:" + err.Error()
  269. return
  270. }
  271. // 有效期是否到期
  272. var vailStatus int
  273. if user.Status == utils.UserStatusFormal || user.Status == utils.UserStatusNo {
  274. if user.ValidEndTime.After(time.Now()) && user.ValidStartTime.Before(time.Now()) {
  275. vailStatus = 2
  276. } else {
  277. // 不在有效期时间则设置为过期, 将用户状态禁用
  278. vailStatus = 1
  279. user.Status = utils.UserStatusNo
  280. }
  281. }
  282. report, err := models.GetReportById(reportId)
  283. if err != nil {
  284. if err.Error() == utils.ErrNoRow() {
  285. br.Ret = 200
  286. br.Data = new(response.ReportDetailResp)
  287. br.Success = true
  288. br.Msg = "该报告已删除或不存在"
  289. return
  290. }
  291. br.Msg = "该报告已删除"
  292. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  293. return
  294. }
  295. if report.HeadResourceId > 0 || report.EndResourceId > 0 {
  296. headImg, err := models.GetSmartReportResourceById(report.HeadResourceId)
  297. if err != nil && err.Error() != utils.ErrNoRow() {
  298. utils.FileLog.Warn("版头数据获取失败,Err:" + err.Error())
  299. }
  300. endImg, err := models.GetSmartReportResourceById(report.EndResourceId)
  301. if err != nil && err.Error() != utils.ErrNoRow() {
  302. utils.FileLog.Warn("版尾数据获取失败,Err:" + err.Error())
  303. }
  304. if headImg != nil {
  305. report.HeadResource = headImg
  306. }
  307. if endImg != nil {
  308. report.EndResource = endImg
  309. }
  310. }
  311. if report.HasChapter == 1 {
  312. chapterList, err := models.GetReportChapterList(report.Id)
  313. if err != nil {
  314. br.Msg = "该报告已删除"
  315. br.ErrMsg = "获取章节列表失败,Err:" + err.Error()
  316. return
  317. }
  318. report.ChapterContent = chapterList
  319. }
  320. report.ContentSub = html.UnescapeString(report.ContentSub)
  321. report.Content = html.UnescapeString(report.Content)
  322. if report == nil {
  323. br.Msg = "报告不存在"
  324. return
  325. }
  326. reportChartPermissionIds, err := models.GetChartPermissionIdsListByClassifyId(report.ClassifyIdSecond)
  327. if err != nil {
  328. br.Msg = "获取研报权限失败"
  329. br.ErrMsg = "获取研报权限失败,Err:" + err.Error()
  330. return
  331. }
  332. chartPermissionList, err := models.GetChartPermissionListByStrIds(reportChartPermissionIds)
  333. if err != nil {
  334. br.Msg = "获取研报权限失败"
  335. br.ErrMsg = "获取研报权限失败,Err:" + err.Error()
  336. return
  337. }
  338. var IsHas bool
  339. var IsPublic bool
  340. for _, v := range chartPermissionList {
  341. if v.IsPublic == 1 {
  342. IsPublic = true
  343. break
  344. }
  345. }
  346. resp := new(response.ReportDetailResp)
  347. if !IsPublic {
  348. // 如果是私有报告,用户权限过期直接返回有效期已过
  349. if vailStatus == 1 {
  350. resp.Report = report
  351. resp.Status = utils.ReportPermissionStatusExpired
  352. report.Content = ""
  353. br.Ret = 200
  354. br.Data = resp
  355. br.Msg = "用户权限不足"
  356. return
  357. }
  358. // 如果被禁用或是潜在用户,直接返回无阅读报告权限
  359. if user.Status == utils.UserStatusNo || user.Status == utils.UserStatusPotential {
  360. resp.Report = report
  361. resp.Status = utils.ReportPermissionStatusNo
  362. report.Content = ""
  363. br.Ret = 200
  364. br.Data = resp
  365. br.Msg = "用户权限不足"
  366. return
  367. }
  368. chartPermissionIds, err := models.GetChartPermissionIdByUserId(userId)
  369. if err != nil {
  370. br.Msg = "获取用户权限失败"
  371. br.ErrMsg = "获取用户权限失败,Err:" + err.Error()
  372. return
  373. }
  374. if len(chartPermissionIds) <= 0 {
  375. resp.Report = report
  376. resp.Status = utils.ReportPermissionStatusNo
  377. report.Content = ""
  378. br.Ret = 200
  379. br.Data = resp
  380. br.Msg = "用户权限不足"
  381. return
  382. }
  383. classifyIds, err := models.GetClassifyIdsListByIds(chartPermissionIds)
  384. if err != nil {
  385. br.Msg = "获取用户权限失败"
  386. br.ErrMsg = "获取用户分类权限失败,Err:" + err.Error()
  387. return
  388. }
  389. if len(classifyIds) <= 0 {
  390. resp.Report = report
  391. resp.Status = utils.ReportPermissionStatusNoPermission
  392. report.Content = ""
  393. br.Ret = 200
  394. br.Data = resp
  395. br.Msg = "用户权限不足"
  396. return
  397. }
  398. for _, v := range classifyIds {
  399. if v == report.ClassifyIdSecond {
  400. IsHas = true
  401. }
  402. }
  403. if !IsHas {
  404. resp.Report = report
  405. resp.Status = utils.ReportPermissionStatusNoPermission
  406. report.Content = ""
  407. br.Ret = 200
  408. br.Data = resp
  409. br.Msg = "用户权限不足"
  410. return
  411. }
  412. } else {
  413. report.IsPublic = IsPublic
  414. }
  415. resp.Report = report
  416. resp.Status = utils.ReportPermissionStatusHas
  417. br.Data = resp
  418. br.Ret = 200
  419. br.Success = true
  420. br.Msg = "获取成功"
  421. }
  422. // @Title 研报详情
  423. // @Description 研报详情接口
  424. // @Param ReportId query int true "报告id"
  425. // @Success 200 {object} response.ReportDetailResp
  426. // @router /detail/noUser [get]
  427. func (this *ReportController) DetailNoUser() {
  428. br := new(models.BaseResponse).Init()
  429. defer func() {
  430. this.Data["json"] = br
  431. this.ServeJSON()
  432. }()
  433. reportId, err := this.GetInt("ReportId")
  434. if err != nil {
  435. br.Msg = "参数获取失败"
  436. br.ErrMsg = "参数获取失败,Err:" + err.Error()
  437. return
  438. }
  439. if reportId <= 0 {
  440. br.Msg = "参数错误"
  441. br.ErrMsg = "参数错误,报告id小于等于0"
  442. return
  443. }
  444. report, err := models.GetReportById(reportId)
  445. if err != nil {
  446. if err.Error() == utils.ErrNoRow() {
  447. br.Ret = 200
  448. br.Data = new(response.ReportDetailResp)
  449. br.Success = true
  450. br.Msg = "该报告已删除或不存在"
  451. return
  452. }
  453. br.Msg = "该报告已删除"
  454. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  455. return
  456. }
  457. report.ContentSub = html.UnescapeString(report.ContentSub)
  458. report.Content = ""
  459. if report == nil {
  460. br.Msg = "报告不存在"
  461. return
  462. }
  463. resp := new(response.ReportDetailResp)
  464. resp.Report = report
  465. resp.Status = utils.ReportPermissionStatusNoUser
  466. br.Data = resp
  467. br.Ret = 200
  468. br.Success = true
  469. br.Msg = "获取成功"
  470. }
  471. // @Title 今日研报列表
  472. // @Description 今日研报列表
  473. // @Success 200 {object} response.ReportListResp
  474. // @router /daily/list [get]
  475. func (this *ReportController) Today() {
  476. br := new(models.BaseResponse).Init()
  477. defer func() {
  478. this.Data["json"] = br
  479. this.ServeJSON()
  480. }()
  481. total, err := models.GetReportDailyListCount()
  482. if err != nil {
  483. br.Msg = "获取数据失败"
  484. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  485. return
  486. }
  487. list, err := models.GetReportDailyList(0, total)
  488. if err != nil {
  489. br.Msg = "获取失败"
  490. br.ErrMsg = "获取失败,Err:" + err.Error()
  491. return
  492. }
  493. classifyIds := make([]string, 0)
  494. for _, v := range list {
  495. classifyIds = append(classifyIds, strconv.Itoa(v.ClassifyIdSecond))
  496. }
  497. classifyIds = utils.Unique(classifyIds)
  498. // 获取二级分类和二级品种权限的映射
  499. chartPermissionMapping, err := models.GetChartPermissionListByClassifyStrIds(classifyIds)
  500. if err != nil {
  501. br.Msg = "获取研报权限失败"
  502. br.ErrMsg = "获取研报权限失败,Err:" + err.Error()
  503. return
  504. }
  505. classifyToPermissionMap2 := make(map[int][]int)
  506. chartPermissionIds := make([]string, 0)
  507. for _, v := range chartPermissionMapping {
  508. classifyToPermissionMap2[v.ClassifyId] = append(classifyToPermissionMap2[v.ClassifyId], v.ChartPermissionId)
  509. chartPermissionIds = append(chartPermissionIds, strconv.Itoa(v.ChartPermissionId))
  510. }
  511. // 获取二级品种的权限,并建立映射
  512. chartPermissionList2, err := models.GetChartPermissionListByStrIds(chartPermissionIds)
  513. if err != nil {
  514. br.Msg = "获取研报二级品种权限失败"
  515. br.ErrMsg = "获取研报二级品种权限失败,Err:" + err.Error()
  516. return
  517. }
  518. chartPermissionViewMap2 := make(map[int]*models.ChartPermission)
  519. for _, v := range chartPermissionList2 {
  520. chartPermissionViewMap2[v.ChartPermissionId] = v
  521. }
  522. // 获取一级品种的权限,并建立映射
  523. chartPermissionList1, err := models.GetChildChartPermissionListById(0)
  524. if err != nil {
  525. br.Msg = "获取研报一级品种权限失败"
  526. br.ErrMsg = "获取研报一级品种权限失败,Err:" + err.Error()
  527. return
  528. }
  529. chartPermissionMap1 := make(map[int]*models.ChartPermission)
  530. for _, v := range chartPermissionList1 {
  531. chartPermissionMap1[v.ChartPermissionId] = v
  532. }
  533. // 组合数据
  534. for _, v := range list {
  535. var permissionNames []string
  536. for _, vv := range classifyToPermissionMap2[v.ClassifyIdSecond] {
  537. if item, ok := chartPermissionViewMap2[vv]; ok {
  538. parent2 := item.ParentId
  539. permissionNames = append(permissionNames, chartPermissionMap1[parent2].PermissionName)
  540. }
  541. }
  542. v.PermissionNames = utils.Unique(permissionNames)
  543. }
  544. resp := new(response.ReportListResp)
  545. resp.List = list
  546. br.Ret = 200
  547. br.Success = true
  548. br.Msg = "获取成功"
  549. br.Data = resp
  550. }
  551. // @Title 最新研报列表
  552. // @Description 最新研报列表
  553. // @Param PageSize query int true "每页数据条数"
  554. // @Param CurrentIndex query int true "当前页页码,从1开始"
  555. // @Success 200 {object} response.ReportListResp
  556. // @router /recent/list [get]
  557. func (this *ReportController) RecentList() {
  558. br := new(models.BaseResponse).Init()
  559. defer func() {
  560. this.Data["json"] = br
  561. this.ServeJSON()
  562. }()
  563. pageSize, _ := this.GetInt("PageSize")
  564. currentIndex, _ := this.GetInt("CurrentIndex")
  565. var startSize int
  566. if pageSize <= 0 {
  567. pageSize = utils.PageSize30
  568. }
  569. if currentIndex <= 0 {
  570. currentIndex = 1
  571. }
  572. startSize = utils.StartIndex(currentIndex, pageSize)
  573. total, err := models.GetReportRecentListCount()
  574. if err != nil {
  575. br.Msg = "获取数据失败"
  576. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  577. return
  578. }
  579. list, err := models.GetReportRecentList(startSize, pageSize)
  580. if err != nil {
  581. br.Msg = "获取失败"
  582. br.ErrMsg = "获取失败,Err:" + err.Error()
  583. return
  584. }
  585. classifyIds := make([]string, 0)
  586. for _, v := range list {
  587. classifyIds = append(classifyIds, strconv.Itoa(v.ClassifyIdSecond))
  588. }
  589. classifyIds = utils.Unique(classifyIds)
  590. // 获取二级分类和二级品种权限的映射
  591. chartPermissionMapping, err := models.GetChartPermissionListByClassifyStrIds(classifyIds)
  592. if err != nil {
  593. br.Msg = "获取研报权限失败"
  594. br.ErrMsg = "获取研报权限失败,Err:" + err.Error()
  595. return
  596. }
  597. classifyToPermissionMap2 := make(map[int][]int)
  598. chartPermissionIds := make([]string, 0)
  599. for _, v := range chartPermissionMapping {
  600. classifyToPermissionMap2[v.ClassifyId] = append(classifyToPermissionMap2[v.ClassifyId], v.ChartPermissionId)
  601. chartPermissionIds = append(chartPermissionIds, strconv.Itoa(v.ChartPermissionId))
  602. }
  603. // 获取二级品种的权限,并建立映射
  604. chartPermissionList2, err := models.GetChartPermissionListByStrIds(chartPermissionIds)
  605. if err != nil {
  606. br.Msg = "获取研报二级品种权限失败"
  607. br.ErrMsg = "获取研报二级品种权限失败,Err:" + err.Error()
  608. return
  609. }
  610. chartPermissionViewMap2 := make(map[int]*models.ChartPermission)
  611. for _, v := range chartPermissionList2 {
  612. chartPermissionViewMap2[v.ChartPermissionId] = v
  613. }
  614. // 获取一级品种的权限,并建立映射
  615. chartPermissionList1, err := models.GetChildChartPermissionListById(0)
  616. if err != nil {
  617. br.Msg = "获取研报一级品种权限失败"
  618. br.ErrMsg = "获取研报一级品种权限失败,Err:" + err.Error()
  619. return
  620. }
  621. chartPermissionMap1 := make(map[int]*models.ChartPermission)
  622. for _, v := range chartPermissionList1 {
  623. chartPermissionMap1[v.ChartPermissionId] = v
  624. }
  625. // 组合数据
  626. for _, v := range list {
  627. var permissionNames []string
  628. for _, vv := range classifyToPermissionMap2[v.ClassifyIdSecond] {
  629. if item, ok := chartPermissionViewMap2[vv]; ok {
  630. parent2 := item.ParentId
  631. permissionNames = append(permissionNames, chartPermissionMap1[parent2].PermissionName)
  632. }
  633. }
  634. v.PermissionNames = utils.Unique(permissionNames)
  635. }
  636. page := paging.GetPaging(currentIndex, pageSize, total)
  637. resp := new(response.ReportListResp)
  638. resp.Paging = page
  639. resp.List = list
  640. br.Ret = 200
  641. br.Success = true
  642. br.Msg = "获取成功"
  643. br.Data = resp
  644. }
  645. // @Title 研报搜索
  646. // @Description 研报搜索
  647. // @Param PageSize query int true "每页数据条数"
  648. // @Param CurrentIndex query int true "当前页页码,从1开始"
  649. // @Param KeyWord query string true "关键字"
  650. // @Success 200 {object} response.ReportSearchResp
  651. // @router /search [get]
  652. func (this *ReportController) Search() {
  653. br := new(models.BaseResponse).Init()
  654. defer func() {
  655. this.Data["json"] = br
  656. this.ServeJSON()
  657. }()
  658. keyWord := this.GetString("KeyWord")
  659. pageSize, _ := this.GetInt("PageSize")
  660. currentIndex, _ := this.GetInt("CurrentIndex")
  661. if pageSize <= 0 {
  662. pageSize = utils.PageSize30
  663. }
  664. if currentIndex <= 0 {
  665. currentIndex = 1
  666. }
  667. if keyWord == "" {
  668. br.Msg = "请输入关键字"
  669. return
  670. }
  671. reportList, err, errMsg := services.SearchReport(keyWord, currentIndex, pageSize)
  672. if err != nil {
  673. br.Msg = "研报搜索失败"
  674. br.ErrMsg = errMsg + ",Err:" + err.Error()
  675. return
  676. }
  677. br.Data = reportList
  678. br.Msg = "查询成功"
  679. br.Ret = 200
  680. br.Success = true
  681. }