report.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. package controllers
  2. import (
  3. "eta/eta_mini_api/models"
  4. "eta/eta_mini_api/models/response"
  5. "eta/eta_mini_api/services"
  6. "eta/eta_mini_api/utils"
  7. "sort"
  8. "strconv"
  9. "time"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. )
  12. type ReportController struct {
  13. BaseAuthController
  14. }
  15. type ReportNoAuthController struct {
  16. BaseCommonController
  17. }
  18. // @Title 研报详情
  19. // @Description 研报详情接口
  20. // @Param ReportId query int true "报告id"
  21. // @Success 200 {object} models.ReportDetailResp
  22. // @router /detail [get]
  23. func (this *ReportController) Detail() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. reportId, _ := this.GetInt("ReportId")
  30. if reportId <= 0 {
  31. br.Msg = "报告不存在"
  32. return
  33. }
  34. user := this.User
  35. if user == nil {
  36. // 如果没有用户没有绑定信息,单独处理
  37. resp, er := services.GetReportDetailNoUser(reportId)
  38. if er != nil {
  39. br.Msg = "查询报告详情失败"
  40. br.ErrMsg = "查询报告失败,系统异常,Err:" + er.Error()
  41. return
  42. }
  43. if resp.Ret != 200 {
  44. br.Msg = resp.Msg
  45. br.ErrMsg = resp.ErrMsg
  46. return
  47. }
  48. br.Msg = "查询成功"
  49. br.Data = resp.Data
  50. br.Success = true
  51. br.Ret = 200
  52. return
  53. }
  54. result, err := services.GetReportDetail(reportId, user.UserId)
  55. if err != nil {
  56. br.Msg = "查询报告详情失败"
  57. br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
  58. return
  59. }
  60. if result.Ret == 403 {
  61. br.Msg = result.Msg
  62. br.ErrMsg = result.ErrMsg
  63. return
  64. }
  65. if result.Ret == 200 && result.Data.Report == nil {
  66. // 后台没有这个报告,那么尝试删除我的收藏
  67. models.DeleteMyReportByUserIdAndReportId(user.UserId, reportId, utils.ReportTypeEta)
  68. br.Msg = "该报告已删除或不存在,请刷新页面"
  69. return
  70. }
  71. count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, reportId, utils.ReportTypeEta)
  72. if err != nil {
  73. br.Msg = "查询收藏数量失败"
  74. br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
  75. return
  76. }
  77. if count > 0 {
  78. result.Data.IsCollect = true
  79. } else {
  80. result.Data.IsCollect = false
  81. }
  82. if user.UserId != 0 {
  83. result.Data.IsSignIn = true
  84. }
  85. br.Msg = "查询成功"
  86. br.Success = true
  87. br.Ret = 200
  88. br.Data = result.Data
  89. }
  90. // @Title 研报列表
  91. // @Description 研报列表
  92. // @Param ChartPermissionId query int true "品种ID"
  93. // @Param Level query int true "品种层级"
  94. // @Param PageSize query int true "每页数据条数"
  95. // @Param CurrentIndex query int true "当前页页码,从1开始"
  96. // @Param RangeType query string true "范围类型,1-一天内,2-一周内,3-半年内"
  97. // @Param ClassifyId query int true "分类id"
  98. // @Success 200 {object} response.ReportList
  99. // @router /list [get]
  100. func (this *ReportController) List() {
  101. br := new(models.BaseResponse).Init()
  102. defer func() {
  103. this.Data["json"] = br
  104. this.ServeJSON()
  105. }()
  106. pageSize, _ := this.GetInt("PageSize")
  107. currentIndex, _ := this.GetInt("CurrentIndex")
  108. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  109. level, _ := this.GetInt("Level")
  110. rangeType, _ := this.GetInt("RangeType")
  111. classifyId, _ := this.GetInt("ClassifyId")
  112. reports, err := services.GetReportList(chartPermissionId, level, rangeType, classifyId, currentIndex, pageSize)
  113. if err != nil {
  114. br.Msg = "研报列表查询失败"
  115. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  116. return
  117. }
  118. if reports.Ret != 200 {
  119. br.Msg = reports.Msg
  120. br.ErrMsg = reports.ErrMsg
  121. return
  122. }
  123. br.Data = reports.Data
  124. br.Msg = "查询成功"
  125. br.Ret = 200
  126. br.Success = true
  127. }
  128. // @Title pdf研报列表
  129. // @Description pdf研报列表
  130. // @Param ChartPermissionId query int true "品种ID"
  131. // @Param PageSize query int true "每页数据条数"
  132. // @Param CurrentIndex query int true "当前页页码,从1开始"
  133. // @Param RangeType query int true "范围类型,1-一天内,2-一周内,3-半年内"
  134. // @Param ClassifyId query int true "二级分类id"
  135. // @Success 200 {object} response.ReportList
  136. // @router /pdf/list [get]
  137. func (this *ReportController) PdfList() {
  138. br := new(models.BaseResponse).Init()
  139. defer func() {
  140. this.Data["json"] = br
  141. this.ServeJSON()
  142. }()
  143. pageSize, _ := this.GetInt("PageSize")
  144. currentIndex, _ := this.GetInt("CurrentIndex")
  145. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  146. classifyId, _ := this.GetInt("ClassifyId")
  147. rangeType, _ := this.GetInt("RangeType")
  148. if pageSize <= 0 {
  149. pageSize = utils.PageSize20
  150. }
  151. if currentIndex <= 0 {
  152. currentIndex = 1
  153. }
  154. if chartPermissionId <= 0 {
  155. br.Msg = "请输入品种ID"
  156. return
  157. }
  158. var condition string
  159. switch rangeType {
  160. case 1:
  161. condition += ` AND DATE(publish_time)=DATE(NOW()) `
  162. case 2:
  163. condition += ` AND DATE(publish_time) BETWEEN DATE_SUB(NOW(),INTERVAL 1 WEEK) AND NOW() `
  164. case 3:
  165. condition += ` AND DATE(publish_time) BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW() `
  166. }
  167. startSize := utils.StartIndex(currentIndex, pageSize)
  168. var leafClassifyIds []int
  169. var leafClassifyIdMap map[int]struct{}
  170. var classifyMap map[int]*models.ClassifyView
  171. classifyResp, err := services.GetAllClassify()
  172. if err != nil {
  173. br.Msg = "获取数据失败"
  174. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  175. return
  176. }
  177. if classifyResp.Ret != 200 {
  178. br.Msg = classifyResp.Msg
  179. br.ErrMsg = classifyResp.ErrMsg
  180. return
  181. }
  182. classifyList := classifyResp.Data
  183. classifyMap = make(map[int]*models.ClassifyView)
  184. isHas := false
  185. for _, v := range classifyList {
  186. if v.Id == classifyId && classifyId != 0 {
  187. isHas = true
  188. }
  189. classifyMap[v.Id] = v
  190. }
  191. if !isHas && classifyId != 0 {
  192. br.Msg = "分类不存在"
  193. return
  194. }
  195. if classifyId != 0 {
  196. leafClassifyIds = getLeafClassifyIds(classifyMap, classifyId)
  197. leafClassifyIdMap = make(map[int]struct{})
  198. for _, v := range leafClassifyIds {
  199. leafClassifyIdMap[v] = struct{}{}
  200. }
  201. }
  202. var permissionClassifyList []int
  203. if chartPermissionId != 0 {
  204. resp, err := services.GetClassifyListByChartPermission(chartPermissionId)
  205. if err != nil {
  206. br.Msg = "获取分类失败"
  207. br.ErrMsg = "获取分类失败,系统异常,Err:" + err.Error()
  208. return
  209. }
  210. if resp.Ret != 200 {
  211. br.Msg = resp.Msg
  212. br.ErrMsg = resp.ErrMsg
  213. return
  214. }
  215. classifyList := resp.Data
  216. if len(classifyList) == 0 {
  217. resp := new(response.ReportPdfResp)
  218. br.Msg = "查询成功"
  219. br.Ret = 200
  220. br.Success = true
  221. br.Data = resp
  222. return
  223. }
  224. for _, item := range classifyList {
  225. permissionClassifyList = append(permissionClassifyList, item.Id)
  226. }
  227. }
  228. queryClassifyIds := make([]int, 0)
  229. if classifyId > 0 {
  230. for _, v := range permissionClassifyList {
  231. if _, ok := leafClassifyIdMap[v]; ok {
  232. queryClassifyIds = append(queryClassifyIds, v)
  233. }
  234. }
  235. } else {
  236. queryClassifyIds = permissionClassifyList
  237. }
  238. firstClassifyIds := make([]int, 0)
  239. secondClassifyIds := make([]int, 0)
  240. thirdClassifyIds := make([]int, 0)
  241. for _, v := range queryClassifyIds {
  242. classify := classifyMap[v]
  243. if classify.HasChild == 1 {
  244. continue
  245. }
  246. switch classifyMap[v].Level {
  247. case 1:
  248. firstClassifyIds = append(firstClassifyIds, v)
  249. case 2:
  250. secondClassifyIds = append(secondClassifyIds, v)
  251. case 3:
  252. thirdClassifyIds = append(thirdClassifyIds, v)
  253. }
  254. }
  255. total, err := models.GetReportPdfCountByCondition(firstClassifyIds, secondClassifyIds, thirdClassifyIds, condition)
  256. if err != nil {
  257. br.Msg = "研报列表查询失败"
  258. br.ErrMsg = "研报列表统计查询失败,系统异常,Err:" + err.Error()
  259. return
  260. }
  261. reportPdfList, err := models.GetReportPdfListByCondition(firstClassifyIds, secondClassifyIds, thirdClassifyIds, condition, startSize, pageSize)
  262. if err != nil {
  263. br.Msg = "研报列表查询失败"
  264. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  265. return
  266. }
  267. page := paging.GetPaging(currentIndex, pageSize, total)
  268. resp := new(response.ReportPdfResp)
  269. resp.List = reportPdfList
  270. resp.Paging = page
  271. br.Msg = "查询成功"
  272. br.Ret = 200
  273. br.Success = true
  274. br.Data = resp
  275. }
  276. func getLeafClassifyIds(classifyMap map[int]*models.ClassifyView, keyId int) []int {
  277. var leafClassifyIds []int
  278. curClassify := classifyMap[keyId]
  279. if curClassify.HasChild == 0 {
  280. leafClassifyIds = append(leafClassifyIds, curClassify.Id)
  281. return leafClassifyIds
  282. }
  283. for _, v := range classifyMap {
  284. if v.ParentId == curClassify.Id {
  285. if v.HasChild == 0 {
  286. leafClassifyIds = append(leafClassifyIds, v.Id)
  287. } else {
  288. leafClassifyIds = append(leafClassifyIds, getLeafClassifyIds(classifyMap, v.Id)...)
  289. }
  290. }
  291. }
  292. return leafClassifyIds
  293. }
  294. // @Title pdf研报详情
  295. // @Description pdf研报详情
  296. // @Param ReportPdfId query int true "品种ID"
  297. // @Success 200 {object} response.ReportList
  298. // @router /pdf/detail [get]
  299. func (this *ReportController) PdfDetail() {
  300. br := new(models.BaseResponse).Init()
  301. defer func() {
  302. this.Data["json"] = br
  303. this.ServeJSON()
  304. }()
  305. user := this.User
  306. // 有效期是否到期
  307. var vailStatus int
  308. if user.Status == utils.UserStatusFormal {
  309. if user.ValidEndTime.After(time.Now()) && user.ValidStartTime.Before(time.Now()) {
  310. vailStatus = 2
  311. } else {
  312. // 不在有效期时间则设置为过期, 将用户状态禁用
  313. vailStatus = 1
  314. user.Status = utils.UserStatusNo
  315. }
  316. }
  317. reportPdfId, _ := this.GetInt("ReportPdfId")
  318. if reportPdfId <= 0 {
  319. br.Msg = "研报不存在或已删除"
  320. return
  321. }
  322. reportPdf, err := models.GetReportPdfById(reportPdfId)
  323. if err != nil && err.Error() != utils.ErrNoRow() {
  324. br.Msg = "研报不存在或已删除"
  325. br.ErrMsg = "研报不存在或已删除,系统异常,Err:" + err.Error()
  326. return
  327. }
  328. if reportPdf == nil {
  329. // 尝试删除收藏列表的记录
  330. models.DeleteMyReportByUserIdAndReportId(user.UserId, reportPdfId, utils.ReportTypePdf)
  331. br.Msg = "研报不存在或已删除"
  332. return
  333. }
  334. reportClassifyId := services.GetReportPdfClassify(reportPdf)
  335. permissionResp, err := services.GetChartPermissionListByClassifyId(reportClassifyId, 0)
  336. if err != nil {
  337. br.Msg = "研报不存在或已删除"
  338. br.ErrMsg = "获取权限失败,系统异常,Err:" + err.Error()
  339. return
  340. }
  341. if permissionResp.Ret != 200 {
  342. br.Msg = permissionResp.Msg
  343. br.ErrMsg = permissionResp.ErrMsg
  344. return
  345. }
  346. var IsHas bool
  347. var IsPublic bool
  348. permissionMap := make(map[int]struct{})
  349. for _, v := range permissionResp.Data {
  350. if v.IsPublic == 1 {
  351. IsPublic = true
  352. }
  353. permissionMap[v.ChartPermissionId] = struct{}{}
  354. }
  355. resp := new(response.ReportPdfDetailResp)
  356. if !IsPublic {
  357. // 如果是私有报告,用户权限过期直接返回有效期已过
  358. if vailStatus == 1 || user.Status == utils.UserStatusNo {
  359. resp.Report = reportPdf
  360. resp.Status = utils.ReportPermissionStatusExpired
  361. br.Ret = 200
  362. br.Data = resp
  363. br.Msg = "用户权限不足"
  364. return
  365. }
  366. // 如果被禁用或是潜在用户,直接返回无阅读报告权限
  367. if user.Status == utils.UserStatusPotential {
  368. resp.Report = reportPdf
  369. resp.Status = utils.ReportPermissionStatusNo
  370. br.Ret = 200
  371. br.Data = resp
  372. br.Msg = "用户权限不足"
  373. return
  374. }
  375. // 正式用户,判断是否有权限查看
  376. userChartPermissionIds, err := models.GetUserChartPermissionIdByUserId(user.UserId)
  377. if err != nil {
  378. br.Msg = "获取用户权限失败"
  379. br.ErrMsg = "获取用户权限失败,Err:" + err.Error()
  380. return
  381. }
  382. if len(userChartPermissionIds) == 0 {
  383. resp.Report = reportPdf
  384. resp.Status = utils.ReportPermissionStatusNoPermission
  385. br.Ret = 200
  386. br.Data = resp
  387. br.Msg = "用户权限不足"
  388. return
  389. }
  390. for _, v := range userChartPermissionIds {
  391. if _, ok := permissionMap[v]; ok {
  392. IsHas = true
  393. break
  394. }
  395. }
  396. if !IsHas {
  397. resp.Report = reportPdf
  398. resp.Status = utils.ReportPermissionStatusNoPermission
  399. br.Ret = 200
  400. br.Data = resp
  401. br.Msg = "用户权限不足"
  402. return
  403. }
  404. } else {
  405. reportPdf.IsPublic = IsPublic
  406. }
  407. count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, reportPdf.ReportPdfId, utils.ReportTypePdf)
  408. if err != nil {
  409. br.Msg = "获取研报详情失败"
  410. br.ErrMsg = "获取用户收藏记录失败,Err:" + err.Error()
  411. return
  412. }
  413. if count > 0 {
  414. reportPdf.IsCollect = true
  415. } else {
  416. reportPdf.IsCollect = false
  417. }
  418. resp.Report = reportPdf
  419. resp.Status = utils.ReportPermissionStatusHas
  420. br.Msg = "查询成功"
  421. br.Ret = 200
  422. br.Success = true
  423. br.Data = resp
  424. }
  425. // @Title 今日研报列表
  426. // @Description 今日研报列表
  427. // @Param PageSize query int true "每页数据条数"
  428. // @Param CurrentIndex query int true "当前页页码,从1开始"
  429. // @Success 200 {object} models.ReportDetailResp
  430. // @router /daily/list [get]
  431. func (this *ReportController) DailyList() {
  432. br := new(models.BaseResponse).Init()
  433. defer func() {
  434. this.Data["json"] = br
  435. this.ServeJSON()
  436. }()
  437. // 暂不使用分页
  438. pageSize, _ := this.GetInt("PageSize")
  439. currentIndex, _ := this.GetInt("CurrentIndex")
  440. if pageSize <= 0 {
  441. pageSize = utils.PageSize20
  442. }
  443. if currentIndex <= 0 {
  444. currentIndex = 1
  445. }
  446. resp, err := services.GetReportDailyList()
  447. if err != nil {
  448. br.Msg = "研报列表查询失败"
  449. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  450. return
  451. }
  452. if resp.Ret != 200 {
  453. br.Msg = resp.Msg
  454. br.ErrMsg = resp.ErrMsg
  455. return
  456. }
  457. reportList := resp.Data
  458. for _, v := range reportList.List {
  459. v.ReportType = utils.ReportTypeEta
  460. }
  461. reportPdfList, err := models.GetReportPdfDailyList()
  462. if err != nil {
  463. br.Msg = "研报列表查询失败"
  464. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  465. return
  466. }
  467. var classifyIds []int
  468. for _, v := range reportPdfList {
  469. var reportClassifyId int
  470. if v.ClassifyIdFirst != 0 {
  471. reportClassifyId = v.ClassifyIdFirst
  472. }
  473. if v.ClassifyIdSecond != 0 {
  474. reportClassifyId = v.ClassifyIdSecond
  475. }
  476. if v.ClassifyIdThird != 0 {
  477. reportClassifyId = v.ClassifyIdThird
  478. }
  479. classifyIds = append(classifyIds, reportClassifyId)
  480. }
  481. if len(classifyIds) > 0 {
  482. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  483. if err != nil {
  484. br.Msg = "研报列表查询失败"
  485. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  486. return
  487. }
  488. if classifyResp.Ret != 200 {
  489. br.Msg = classifyResp.Msg
  490. br.ErrMsg = classifyResp.ErrMsg
  491. return
  492. }
  493. classifyPermissionMap := make(map[int][]string)
  494. for _, v := range classifyResp.Data {
  495. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  496. }
  497. for _, v := range reportPdfList {
  498. var reportClassifyId int
  499. if v.ClassifyIdFirst != 0 {
  500. reportClassifyId = v.ClassifyIdFirst
  501. }
  502. if v.ClassifyIdSecond != 0 {
  503. reportClassifyId = v.ClassifyIdSecond
  504. }
  505. if v.ClassifyIdThird != 0 {
  506. reportClassifyId = v.ClassifyIdThird
  507. }
  508. // 过滤没有绑定品种的研报
  509. if classifyPermissionMap[reportClassifyId] == nil {
  510. continue
  511. }
  512. reportList.List = append(reportList.List, &models.ReportView{
  513. Id: v.ReportPdfId,
  514. ClassifyIdFirst: v.ClassifyIdFirst,
  515. ClassifyNameFirst: v.ClassifyNameFirst,
  516. ClassifyIdSecond: v.ClassifyIdSecond,
  517. ClassifyNameSecond: v.ClassifyNameSecond,
  518. ClassifyIdThird: v.ClassifyIdThird,
  519. ClassifyNameThird: v.ClassifyNameThird,
  520. PermissionNames: classifyPermissionMap[reportClassifyId],
  521. PdfUrl: v.PdfUrl,
  522. Title: v.Title,
  523. Abstract: v.Abstract,
  524. Stage: v.Stage,
  525. Author: v.Author,
  526. ReportType: utils.ReportTypePdf,
  527. PublishTime: v.PublishTime.Format(utils.FormatDateTime),
  528. ModifyTime: v.ModifyTime,
  529. })
  530. }
  531. }
  532. sort.Sort(models.ByPublishTimeReportView(reportList.List))
  533. br.Data = reportList
  534. br.Msg = "查询成功"
  535. br.Ret = 200
  536. br.Success = true
  537. }
  538. // @Title 最新研报列表
  539. // @Description 最新研报列表
  540. // @Param PageSize query int true "每页数据条数"
  541. // @Param CurrentIndex query int true "当前页页码,从1开始"
  542. // @Success 200 {object} models.ReportDetailResp
  543. // @router /recent/list [get]
  544. func (this *ReportController) RecentList() {
  545. br := new(models.BaseResponse).Init()
  546. defer func() {
  547. this.Data["json"] = br
  548. this.ServeJSON()
  549. }()
  550. // 暂不使用分页
  551. pageSize, _ := this.GetInt("PageSize")
  552. currentIndex, _ := this.GetInt("CurrentIndex")
  553. if pageSize <= 0 {
  554. pageSize = 3
  555. }
  556. resp, err := services.GetReportRecentList(currentIndex, pageSize)
  557. if err != nil {
  558. br.Msg = "研报列表查询失败"
  559. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  560. return
  561. }
  562. // 查询已发布的pdf
  563. reportPdfList, err := models.GetRecentReportPdfList(0, 3)
  564. if err != nil {
  565. br.Msg = "研报列表查询失败"
  566. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  567. return
  568. }
  569. reportList := resp.Data
  570. for _, v := range reportList.List {
  571. v.ReportType = utils.ReportTypeEta
  572. }
  573. var classifyIds []int
  574. for _, v := range reportPdfList {
  575. var reportClassifyId int
  576. if v.ClassifyIdFirst != 0 {
  577. reportClassifyId = v.ClassifyIdFirst
  578. }
  579. if v.ClassifyIdSecond != 0 {
  580. reportClassifyId = v.ClassifyIdSecond
  581. }
  582. if v.ClassifyIdThird != 0 {
  583. reportClassifyId = v.ClassifyIdThird
  584. }
  585. classifyIds = append(classifyIds, reportClassifyId)
  586. }
  587. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  588. if err != nil {
  589. br.Msg = "研报列表查询失败"
  590. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  591. return
  592. }
  593. if classifyResp.Ret != 200 {
  594. br.Msg = classifyResp.Msg
  595. br.ErrMsg = classifyResp.ErrMsg
  596. }
  597. classifyPermissionMap := make(map[int][]string)
  598. for _, v := range classifyResp.Data {
  599. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  600. }
  601. for _, v := range reportPdfList {
  602. var reportClassifyId int
  603. if v.ClassifyIdFirst != 0 {
  604. reportClassifyId = v.ClassifyIdFirst
  605. }
  606. if v.ClassifyIdSecond != 0 {
  607. reportClassifyId = v.ClassifyIdSecond
  608. }
  609. if v.ClassifyIdThird != 0 {
  610. reportClassifyId = v.ClassifyIdThird
  611. }
  612. // 过滤没有绑定品种的研报
  613. if classifyPermissionMap[reportClassifyId] == nil {
  614. continue
  615. }
  616. reportList.List = append(reportList.List, &models.ReportView{
  617. Id: v.ReportPdfId,
  618. ClassifyIdFirst: v.ClassifyIdFirst,
  619. ClassifyNameFirst: v.ClassifyNameFirst,
  620. ClassifyIdSecond: v.ClassifyIdSecond,
  621. ClassifyNameSecond: v.ClassifyNameSecond,
  622. ClassifyIdThird: v.ClassifyIdThird,
  623. ClassifyNameThird: v.ClassifyNameThird,
  624. PermissionNames: classifyPermissionMap[reportClassifyId],
  625. PdfUrl: v.PdfUrl,
  626. Title: v.Title,
  627. Abstract: v.Abstract,
  628. Stage: v.Stage,
  629. Author: v.Author,
  630. ReportType: utils.ReportTypePdf,
  631. PublishTime: v.PublishTime.Format(utils.FormatDateTime),
  632. ModifyTime: v.ModifyTime,
  633. })
  634. }
  635. sort.Sort(models.ByPublishTimeReportView(reportList.List))
  636. endIdx := len(reportList.List)
  637. if endIdx > 3 {
  638. endIdx = 3
  639. }
  640. reportList.List = reportList.List[:endIdx]
  641. br.Data = reportList
  642. br.Msg = "查询成功"
  643. br.Ret = 200
  644. br.Success = true
  645. }
  646. // @Title 研报列表
  647. // @Description 研报列表
  648. // @Param ReportId query int true "报告id"
  649. // @Param chartPermissionId query int true "品种ID"
  650. // @Param PageSize query int true "每页数据条数"
  651. // @Param CurrentIndex query int true "当前页页码,从1开始"
  652. // @Success 200 {object} models.ReportDetailResp
  653. // @router /search [get]
  654. func (this *ReportController) Search() {
  655. br := new(models.BaseResponse).Init()
  656. defer func() {
  657. this.Data["json"] = br
  658. this.ServeJSON()
  659. }()
  660. keyWord := this.GetString("KeyWord")
  661. pageSize, _ := this.GetInt("PageSize")
  662. currentIndex, _ := this.GetInt("CurrentIndex")
  663. if pageSize <= 0 {
  664. pageSize = utils.PageSize30
  665. }
  666. if keyWord == "" {
  667. br.Msg = "请输入关键字"
  668. return
  669. }
  670. reports, err := services.SearchReport(keyWord, currentIndex, pageSize)
  671. if err != nil {
  672. br.Msg = "研报列表查询失败"
  673. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  674. return
  675. }
  676. if reports.Ret != 200 {
  677. br.Msg = reports.Msg
  678. br.ErrMsg = reports.ErrMsg
  679. return
  680. }
  681. resp := new(response.ReportSearchViewResp)
  682. list := make([]*response.ReportSearchListView, 0)
  683. for _, v := range reports.Data.List {
  684. tmpReport := &response.ReportSearchListView{
  685. ReportId: v.ReportId,
  686. ReportChapterId: v.ReportChapterId,
  687. ClassifyIdFirst: v.ClassifyIdFirst,
  688. ClassifyNameFirst: v.ClassifyNameFirst,
  689. ClassifyIdSecond: v.ClassifyIdSecond,
  690. ClassifyNameSecond: v.ClassifyNameSecond,
  691. ClassifyIdThird: v.ClassifyIdThird,
  692. ClassifyNameThird: v.ClassifyNameThird,
  693. ReportChapterTypeId: v.ReportChapterTypeId,
  694. PublishTime: v.PublishTime.Format(utils.FormatDate),
  695. Title: v.Title,
  696. ContentSub: v.ContentSub,
  697. Abstract: v.Abstract,
  698. Stage: v.Stage,
  699. Author: v.Author,
  700. PdfUrl: v.PdfUrl,
  701. ReportType: v.ReportType,
  702. }
  703. if v.PublishTime.IsZero() {
  704. tmpReport.PublishTime = ""
  705. }
  706. list = append(list, tmpReport)
  707. }
  708. resp.List = list
  709. resp.Paging = reports.Data.Paging
  710. br.Data = resp
  711. br.Msg = "查询成功"
  712. br.Ret = 200
  713. br.Success = true
  714. }
  715. // @Title 研报列表
  716. // @Description 研报列表
  717. // @Param ChartPermissionId query int true "品种ID"
  718. // @Param Level query int true "品种层级"
  719. // @Param PageSize query int true "每页数据条数"
  720. // @Param CurrentIndex query int true "当前页页码,从1开始"
  721. // @Param RangeType query string true "范围类型,1-一天内,2-一周内,3-半年内"
  722. // @Param ReportType query string true "报告类型,1-eta报告,2-pdf报告"
  723. // @Param ClassifyId query int true "分类id"
  724. // @Success 200 {object} response.ReportList
  725. // @router /list [get]
  726. func (this *ReportNoAuthController) List() {
  727. br := new(models.BaseResponse).Init()
  728. defer func() {
  729. this.Data["json"] = br
  730. this.ServeJSON()
  731. }()
  732. pageSize, _ := this.GetInt("PageSize")
  733. currentIndex, _ := this.GetInt("CurrentIndex")
  734. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  735. level, _ := this.GetInt("Level")
  736. rangeType, _ := this.GetInt("RangeType")
  737. reportType, _ := this.GetInt("ReportType")
  738. classifyId, _ := this.GetInt("ClassifyId")
  739. switch rangeType {
  740. case 1, 2, 3:
  741. default:
  742. br.Msg = "查询失败"
  743. return
  744. }
  745. switch reportType {
  746. case utils.ReportTypeEta, utils.ReportTypePdf:
  747. default:
  748. br.Msg = "报告不存在"
  749. return
  750. }
  751. reports, err := services.GetNoAuthReportList(reportType, chartPermissionId, level, rangeType, classifyId, currentIndex, pageSize)
  752. if err != nil {
  753. br.Msg = "研报列表查询失败"
  754. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  755. return
  756. }
  757. if reports.Ret != 200 {
  758. br.Msg = reports.Msg
  759. br.ErrMsg = reports.ErrMsg
  760. return
  761. }
  762. br.Data = reports.Data
  763. br.Msg = "查询成功"
  764. br.Ret = 200
  765. br.Success = true
  766. }
  767. // @Title 研报详情
  768. // @Description 研报详情接口
  769. // @Param ReportId query int true "报告id"
  770. // @Param ReportType query int true "报告类型:1-eta,2-pdf"
  771. // @Success 200 {object} models.ReportDetailResp
  772. // @router /detail [get]
  773. func (this *ReportNoAuthController) Detail() {
  774. br := new(models.BaseResponse).Init()
  775. defer func() {
  776. this.Data["json"] = br
  777. this.ServeJSON()
  778. }()
  779. reportId, _ := this.GetInt("ReportId")
  780. reportType, _ := this.GetInt("ReportType")
  781. if reportId <= 0 {
  782. br.Msg = "报告不存在"
  783. return
  784. }
  785. switch reportType {
  786. case utils.ReportTypeEta, utils.ReportTypePdf:
  787. default:
  788. br.Msg = "报告不存在"
  789. return
  790. }
  791. reportPush, err := models.GetReportPushStatusByReportId(reportId, reportType)
  792. if err != nil {
  793. br.Msg = "查询报告失败"
  794. br.ErrMsg = "查询报告推送状态失败,系统异常,Err:" + err.Error()
  795. return
  796. }
  797. if reportPush.State != utils.ReportStatePush {
  798. br.Msg = "报告未推送或已删除,请刷新重试"
  799. return
  800. }
  801. switch reportType {
  802. case utils.ReportTypeEta:
  803. result, err := services.GetNoAuthReportDetail(reportId)
  804. if err != nil {
  805. br.Msg = "查询报告详情失败"
  806. br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
  807. return
  808. }
  809. if result.Ret != 200 {
  810. br.Msg = result.Msg
  811. br.ErrMsg = result.ErrMsg
  812. return
  813. }
  814. if result.Ret == 200 && result.Data.Report == nil {
  815. // 报告不存在, 就尝试删除推送的记录
  816. models.DeleteReportPushStatusByReportId(reportId, utils.ReportTypeEta)
  817. br.Msg = "报告已删除或未发布,请刷新重试"
  818. return
  819. }
  820. br.Msg = "查询成功"
  821. br.Success = true
  822. br.Ret = 200
  823. br.Data = result.Data
  824. return
  825. case utils.ReportTypePdf:
  826. reportPdf, err := models.GetReportPdfById(reportId)
  827. if err != nil {
  828. br.Msg = "查询报告详情失败"
  829. br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
  830. return
  831. }
  832. br.Msg = "查询成功"
  833. br.Success = true
  834. br.Ret = 200
  835. br.Data = reportPdf
  836. return
  837. default:
  838. br.Msg = "报告不存在"
  839. return
  840. }
  841. }
  842. // @Title 研报搜索
  843. // @Description 研报搜索
  844. // @Param KeyWord query string true "每页数据条数"
  845. // @Param PageSize query int true "每页数据条数"
  846. // @Param CurrentIndex query int true "当前页页码,从1开始"
  847. // @Success 200 {object} models.ReportDetailResp
  848. // @router /search [get]
  849. func (this *ReportNoAuthController) Search() {
  850. br := new(models.BaseResponse).Init()
  851. defer func() {
  852. this.Data["json"] = br
  853. this.ServeJSON()
  854. }()
  855. keyWord := this.GetString("KeyWord")
  856. pageSize, _ := this.GetInt("PageSize")
  857. currentIndex, _ := this.GetInt("CurrentIndex")
  858. if pageSize <= 0 {
  859. pageSize = utils.PageSize30
  860. }
  861. if currentIndex <= 0 {
  862. currentIndex = 1
  863. }
  864. startSize := utils.StartIndex(currentIndex, pageSize)
  865. if keyWord == "" {
  866. br.Msg = "请输入关键字"
  867. return
  868. }
  869. reports, total, err := services.SearchReportPush(keyWord, startSize, pageSize)
  870. if err != nil {
  871. br.Msg = "研报列表查询失败"
  872. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  873. return
  874. }
  875. resp := new(response.ReportSearchViewResp)
  876. list := make([]*response.ReportSearchListView, 0)
  877. for _, v := range reports {
  878. tmpReport := &response.ReportSearchListView{
  879. ReportId: v.ReportId,
  880. ClassifyIdFirst: v.ClassifyIdFirst,
  881. ClassifyNameFirst: v.ClassifyNameFirst,
  882. ClassifyIdSecond: v.ClassifyIdSecond,
  883. ClassifyNameSecond: v.ClassifyNameSecond,
  884. ClassifyIdThird: v.ClassifyIdThird,
  885. ClassifyNameThird: v.ClassifyNameThird,
  886. PublishTime: v.PublishTime.Format(utils.FormatDate),
  887. Title: v.Title,
  888. Abstract: v.Abstract,
  889. Stage: strconv.Itoa(v.Stage),
  890. Author: v.Author,
  891. ReportType: v.ReportType,
  892. }
  893. if v.PublishTime.IsZero() {
  894. tmpReport.PublishTime = ""
  895. }
  896. list = append(list, tmpReport)
  897. }
  898. page := paging.GetPaging(currentIndex, pageSize, total)
  899. resp.List = list
  900. resp.Paging = page
  901. br.Data = resp
  902. br.Msg = "查询成功"
  903. br.Ret = 200
  904. br.Success = true
  905. }