report.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  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. switch classifyMap[v].Level {
  243. case 1:
  244. firstClassifyIds = append(firstClassifyIds, v)
  245. case 2:
  246. secondClassifyIds = append(secondClassifyIds, v)
  247. case 3:
  248. thirdClassifyIds = append(thirdClassifyIds, v)
  249. }
  250. }
  251. total, err := models.GetReportPdfCountByCondition(firstClassifyIds, secondClassifyIds, thirdClassifyIds, condition)
  252. if err != nil {
  253. br.Msg = "研报列表查询失败"
  254. br.ErrMsg = "研报列表统计查询失败,系统异常,Err:" + err.Error()
  255. return
  256. }
  257. reportPdfList, err := models.GetReportPdfListByCondition(firstClassifyIds, secondClassifyIds, thirdClassifyIds, condition, startSize, pageSize)
  258. if err != nil {
  259. br.Msg = "研报列表查询失败"
  260. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  261. return
  262. }
  263. page := paging.GetPaging(currentIndex, pageSize, total)
  264. resp := new(response.ReportPdfResp)
  265. resp.List = reportPdfList
  266. resp.Paging = page
  267. br.Msg = "查询成功"
  268. br.Ret = 200
  269. br.Success = true
  270. br.Data = resp
  271. }
  272. func getLeafClassifyIds(classifyMap map[int]*models.ClassifyView, keyId int) []int {
  273. var leafClassifyIds []int
  274. curClassify := classifyMap[keyId]
  275. if curClassify.HasChild == 0 {
  276. leafClassifyIds = append(leafClassifyIds, curClassify.Id)
  277. return leafClassifyIds
  278. }
  279. for _, v := range classifyMap {
  280. if v.ParentId == curClassify.Id {
  281. if v.HasChild == 0 {
  282. leafClassifyIds = append(leafClassifyIds, v.Id)
  283. } else {
  284. leafClassifyIds = append(leafClassifyIds, getLeafClassifyIds(classifyMap, v.Id)...)
  285. }
  286. }
  287. }
  288. return leafClassifyIds
  289. }
  290. // @Title pdf研报详情
  291. // @Description pdf研报详情
  292. // @Param ReportPdfId query int true "品种ID"
  293. // @Success 200 {object} response.ReportList
  294. // @router /pdf/detail [get]
  295. func (this *ReportController) PdfDetail() {
  296. br := new(models.BaseResponse).Init()
  297. defer func() {
  298. this.Data["json"] = br
  299. this.ServeJSON()
  300. }()
  301. user := this.User
  302. // 有效期是否到期
  303. var vailStatus int
  304. if user.Status == utils.UserStatusFormal {
  305. if user.ValidEndTime.After(time.Now()) && user.ValidStartTime.Before(time.Now()) {
  306. vailStatus = 2
  307. } else {
  308. // 不在有效期时间则设置为过期, 将用户状态禁用
  309. vailStatus = 1
  310. user.Status = utils.UserStatusNo
  311. }
  312. }
  313. reportPdfId, _ := this.GetInt("ReportPdfId")
  314. if reportPdfId <= 0 {
  315. br.Msg = "研报不存在或已删除"
  316. return
  317. }
  318. reportPdf, err := models.GetReportPdfById(reportPdfId)
  319. if err != nil && err.Error() != utils.ErrNoRow() {
  320. br.Msg = "研报不存在或已删除"
  321. br.ErrMsg = "研报不存在或已删除,系统异常,Err:" + err.Error()
  322. return
  323. }
  324. if reportPdf == nil {
  325. // 尝试删除收藏列表的记录
  326. models.DeleteMyReportByUserIdAndReportId(user.UserId, reportPdfId, utils.ReportTypePdf)
  327. br.Msg = "研报不存在或已删除"
  328. return
  329. }
  330. reportClassifyId := services.GetReportPdfClassify(reportPdf)
  331. permissionResp, err := services.GetChartPermissionListByClassifyId(reportClassifyId, 0)
  332. if err != nil {
  333. br.Msg = "研报不存在或已删除"
  334. br.ErrMsg = "获取权限失败,系统异常,Err:" + err.Error()
  335. return
  336. }
  337. if permissionResp.Ret != 200 {
  338. br.Msg = permissionResp.Msg
  339. br.ErrMsg = permissionResp.ErrMsg
  340. return
  341. }
  342. var IsHas bool
  343. var IsPublic bool
  344. permissionMap := make(map[int]struct{})
  345. for _, v := range permissionResp.Data {
  346. if v.IsPublic == 1 {
  347. IsPublic = true
  348. }
  349. permissionMap[v.ChartPermissionId] = struct{}{}
  350. }
  351. resp := new(response.ReportPdfDetailResp)
  352. if !IsPublic {
  353. // 如果是私有报告,用户权限过期直接返回有效期已过
  354. if vailStatus == 1 {
  355. resp.Report = reportPdf
  356. resp.Status = utils.ReportPermissionStatusExpired
  357. br.Ret = 200
  358. br.Data = resp
  359. br.Msg = "用户权限不足"
  360. return
  361. }
  362. // 如果被禁用或是潜在用户,直接返回无阅读报告权限
  363. if user.Status == utils.UserStatusNo || user.Status == utils.UserStatusPotential {
  364. resp.Report = reportPdf
  365. resp.Status = utils.ReportPermissionStatusNo
  366. br.Ret = 200
  367. br.Data = resp
  368. br.Msg = "用户权限不足"
  369. return
  370. }
  371. userChartPermissionIds, err := models.GetUserChartPermissionIdByUserId(user.UserId)
  372. if err != nil {
  373. br.Msg = "获取用户权限失败"
  374. br.ErrMsg = "获取用户权限失败,Err:" + err.Error()
  375. return
  376. }
  377. if len(userChartPermissionIds) == 0 {
  378. resp.Report = reportPdf
  379. resp.Status = utils.ReportPermissionStatusNo
  380. br.Ret = 200
  381. br.Data = resp
  382. br.Msg = "用户权限不足"
  383. return
  384. }
  385. for _, v := range userChartPermissionIds {
  386. if _, ok := permissionMap[v]; ok {
  387. IsHas = true
  388. break
  389. }
  390. }
  391. if !IsHas {
  392. resp.Report = reportPdf
  393. resp.Status = utils.ReportPermissionStatusNoPermission
  394. br.Ret = 200
  395. br.Data = resp
  396. br.Msg = "用户权限不足"
  397. return
  398. }
  399. } else {
  400. reportPdf.IsPublic = IsPublic
  401. }
  402. count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, reportPdf.ReportPdfId, utils.ReportTypePdf)
  403. if err != nil {
  404. br.Msg = "获取研报详情失败"
  405. br.ErrMsg = "获取用户收藏记录失败,Err:" + err.Error()
  406. return
  407. }
  408. if count > 0 {
  409. reportPdf.IsCollect = true
  410. } else {
  411. reportPdf.IsCollect = false
  412. }
  413. resp.Report = reportPdf
  414. resp.Status = utils.ReportPermissionStatusHas
  415. br.Msg = "查询成功"
  416. br.Ret = 200
  417. br.Success = true
  418. br.Data = resp
  419. }
  420. // @Title 今日研报列表
  421. // @Description 今日研报列表
  422. // @Param PageSize query int true "每页数据条数"
  423. // @Param CurrentIndex query int true "当前页页码,从1开始"
  424. // @Success 200 {object} models.ReportDetailResp
  425. // @router /daily/list [get]
  426. func (this *ReportController) DailyList() {
  427. br := new(models.BaseResponse).Init()
  428. defer func() {
  429. this.Data["json"] = br
  430. this.ServeJSON()
  431. }()
  432. // 暂不使用分页
  433. pageSize, _ := this.GetInt("PageSize")
  434. currentIndex, _ := this.GetInt("CurrentIndex")
  435. if pageSize <= 0 {
  436. pageSize = utils.PageSize20
  437. }
  438. if currentIndex <= 0 {
  439. currentIndex = 1
  440. }
  441. resp, err := services.GetReportDailyList()
  442. if err != nil {
  443. br.Msg = "研报列表查询失败"
  444. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  445. return
  446. }
  447. if resp.Ret != 200 {
  448. br.Msg = resp.Msg
  449. br.ErrMsg = resp.ErrMsg
  450. return
  451. }
  452. reportList := resp.Data
  453. for _, v := range reportList.List {
  454. v.ReportType = utils.ReportTypeEta
  455. }
  456. reportPdfList, err := models.GetReportPdfDailyList()
  457. if err != nil {
  458. br.Msg = "研报列表查询失败"
  459. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  460. return
  461. }
  462. var classifyIds []int
  463. for _, v := range reportPdfList {
  464. var reportClassifyId int
  465. if v.ClassifyIdFirst != 0 {
  466. reportClassifyId = v.ClassifyIdFirst
  467. }
  468. if v.ClassifyIdSecond != 0 {
  469. reportClassifyId = v.ClassifyIdSecond
  470. }
  471. if v.ClassifyIdThird != 0 {
  472. reportClassifyId = v.ClassifyIdThird
  473. }
  474. classifyIds = append(classifyIds, reportClassifyId)
  475. }
  476. if len(classifyIds) > 0 {
  477. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  478. if err != nil {
  479. br.Msg = "研报列表查询失败"
  480. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  481. return
  482. }
  483. if classifyResp.Ret != 200 {
  484. br.Msg = classifyResp.Msg
  485. br.ErrMsg = classifyResp.ErrMsg
  486. return
  487. }
  488. classifyPermissionMap := make(map[int][]string)
  489. for _, v := range classifyResp.Data {
  490. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  491. }
  492. for _, v := range reportPdfList {
  493. var reportClassifyId int
  494. if v.ClassifyIdFirst != 0 {
  495. reportClassifyId = v.ClassifyIdFirst
  496. }
  497. if v.ClassifyIdSecond != 0 {
  498. reportClassifyId = v.ClassifyIdSecond
  499. }
  500. if v.ClassifyIdThird != 0 {
  501. reportClassifyId = v.ClassifyIdThird
  502. }
  503. // 过滤没有绑定品种的研报
  504. if classifyPermissionMap[reportClassifyId] == nil {
  505. continue
  506. }
  507. reportList.List = append(reportList.List, &models.ReportView{
  508. Id: v.ReportPdfId,
  509. ClassifyIdFirst: v.ClassifyIdFirst,
  510. ClassifyNameFirst: v.ClassifyNameFirst,
  511. ClassifyIdSecond: v.ClassifyIdSecond,
  512. ClassifyNameSecond: v.ClassifyNameSecond,
  513. ClassifyIdThird: v.ClassifyIdThird,
  514. ClassifyNameThird: v.ClassifyNameThird,
  515. PermissionNames: classifyPermissionMap[reportClassifyId],
  516. PdfUrl: v.PdfUrl,
  517. Title: v.Title,
  518. Abstract: v.Abstract,
  519. Stage: v.Stage,
  520. Author: v.Author,
  521. ReportType: utils.ReportTypePdf,
  522. PublishTime: v.PublishTime.Format(utils.FormatDateTime),
  523. ModifyTime: v.ModifyTime,
  524. })
  525. }
  526. }
  527. sort.Sort(models.ByPublishTimeReportView(reportList.List))
  528. br.Data = reportList
  529. br.Msg = "查询成功"
  530. br.Ret = 200
  531. br.Success = true
  532. }
  533. // @Title 最新研报列表
  534. // @Description 最新研报列表
  535. // @Param PageSize query int true "每页数据条数"
  536. // @Param CurrentIndex query int true "当前页页码,从1开始"
  537. // @Success 200 {object} models.ReportDetailResp
  538. // @router /recent/list [get]
  539. func (this *ReportController) RecentList() {
  540. br := new(models.BaseResponse).Init()
  541. defer func() {
  542. this.Data["json"] = br
  543. this.ServeJSON()
  544. }()
  545. // 暂不使用分页
  546. pageSize, _ := this.GetInt("PageSize")
  547. currentIndex, _ := this.GetInt("CurrentIndex")
  548. if pageSize <= 0 {
  549. pageSize = 3
  550. }
  551. resp, err := services.GetReportRecentList(currentIndex, pageSize)
  552. if err != nil {
  553. br.Msg = "研报列表查询失败"
  554. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  555. return
  556. }
  557. // 查询已发布的pdf
  558. reportPdfList, err := models.GetRecentReportPdfList(0, 3)
  559. if err != nil {
  560. br.Msg = "研报列表查询失败"
  561. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  562. return
  563. }
  564. reportList := resp.Data
  565. for _, v := range reportList.List {
  566. v.ReportType = utils.ReportTypeEta
  567. }
  568. var classifyIds []int
  569. for _, v := range reportPdfList {
  570. var reportClassifyId int
  571. if v.ClassifyIdFirst != 0 {
  572. reportClassifyId = v.ClassifyIdFirst
  573. }
  574. if v.ClassifyIdSecond != 0 {
  575. reportClassifyId = v.ClassifyIdSecond
  576. }
  577. if v.ClassifyIdThird != 0 {
  578. reportClassifyId = v.ClassifyIdThird
  579. }
  580. classifyIds = append(classifyIds, reportClassifyId)
  581. }
  582. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  583. if err != nil {
  584. br.Msg = "研报列表查询失败"
  585. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  586. return
  587. }
  588. if classifyResp.Ret != 200 {
  589. br.Msg = classifyResp.Msg
  590. br.ErrMsg = classifyResp.ErrMsg
  591. }
  592. classifyPermissionMap := make(map[int][]string)
  593. for _, v := range classifyResp.Data {
  594. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  595. }
  596. for _, v := range reportPdfList {
  597. var reportClassifyId int
  598. if v.ClassifyIdFirst != 0 {
  599. reportClassifyId = v.ClassifyIdFirst
  600. }
  601. if v.ClassifyIdSecond != 0 {
  602. reportClassifyId = v.ClassifyIdSecond
  603. }
  604. if v.ClassifyIdThird != 0 {
  605. reportClassifyId = v.ClassifyIdThird
  606. }
  607. // 过滤没有绑定品种的研报
  608. if classifyPermissionMap[reportClassifyId] == nil {
  609. continue
  610. }
  611. reportList.List = append(reportList.List, &models.ReportView{
  612. Id: v.ReportPdfId,
  613. ClassifyIdFirst: v.ClassifyIdFirst,
  614. ClassifyNameFirst: v.ClassifyNameFirst,
  615. ClassifyIdSecond: v.ClassifyIdSecond,
  616. ClassifyNameSecond: v.ClassifyNameSecond,
  617. ClassifyIdThird: v.ClassifyIdThird,
  618. ClassifyNameThird: v.ClassifyNameThird,
  619. PermissionNames: classifyPermissionMap[reportClassifyId],
  620. PdfUrl: v.PdfUrl,
  621. Title: v.Title,
  622. Abstract: v.Abstract,
  623. Stage: v.Stage,
  624. Author: v.Author,
  625. ReportType: utils.ReportTypePdf,
  626. PublishTime: v.PublishTime.Format(utils.FormatDateTime),
  627. ModifyTime: v.ModifyTime,
  628. })
  629. }
  630. sort.Sort(models.ByPublishTimeReportView(reportList.List))
  631. endIdx := len(reportList.List)
  632. if endIdx > 3 {
  633. endIdx = 3
  634. }
  635. reportList.List = reportList.List[:endIdx]
  636. br.Data = reportList
  637. br.Msg = "查询成功"
  638. br.Ret = 200
  639. br.Success = true
  640. }
  641. // @Title 研报列表
  642. // @Description 研报列表
  643. // @Param ReportId query int true "报告id"
  644. // @Param chartPermissionId query int true "品种ID"
  645. // @Param PageSize query int true "每页数据条数"
  646. // @Param CurrentIndex query int true "当前页页码,从1开始"
  647. // @Success 200 {object} models.ReportDetailResp
  648. // @router /search [get]
  649. func (this *ReportController) Search() {
  650. br := new(models.BaseResponse).Init()
  651. defer func() {
  652. this.Data["json"] = br
  653. this.ServeJSON()
  654. }()
  655. keyWord := this.GetString("KeyWord")
  656. pageSize, _ := this.GetInt("PageSize")
  657. currentIndex, _ := this.GetInt("CurrentIndex")
  658. if pageSize <= 0 {
  659. pageSize = utils.PageSize30
  660. }
  661. if keyWord == "" {
  662. br.Msg = "请输入关键字"
  663. return
  664. }
  665. reports, err := services.SearchReport(keyWord, currentIndex, pageSize)
  666. if err != nil {
  667. br.Msg = "研报列表查询失败"
  668. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  669. return
  670. }
  671. if reports.Ret != 200 {
  672. br.Msg = reports.Msg
  673. br.ErrMsg = reports.ErrMsg
  674. return
  675. }
  676. resp := new(response.ReportSearchViewResp)
  677. list := make([]*response.ReportSearchListView, 0)
  678. for _, v := range reports.Data.List {
  679. tmpReport := &response.ReportSearchListView{
  680. ReportId: v.ReportId,
  681. ReportChapterId: v.ReportChapterId,
  682. ClassifyIdFirst: v.ClassifyIdFirst,
  683. ClassifyNameFirst: v.ClassifyNameFirst,
  684. ClassifyIdSecond: v.ClassifyIdSecond,
  685. ClassifyNameSecond: v.ClassifyNameSecond,
  686. ClassifyIdThird: v.ClassifyIdThird,
  687. ClassifyNameThird: v.ClassifyNameThird,
  688. ReportChapterTypeId: v.ReportChapterTypeId,
  689. PublishTime: v.PublishTime.Format(utils.FormatDate),
  690. Title: v.Title,
  691. ContentSub: v.ContentSub,
  692. Abstract: v.Abstract,
  693. Stage: v.Stage,
  694. Author: v.Author,
  695. PdfUrl: v.PdfUrl,
  696. ReportType: v.ReportType,
  697. }
  698. if v.PublishTime.IsZero() {
  699. tmpReport.PublishTime = ""
  700. }
  701. list = append(list, tmpReport)
  702. }
  703. resp.List = list
  704. resp.Paging = reports.Data.Paging
  705. br.Data = resp
  706. br.Msg = "查询成功"
  707. br.Ret = 200
  708. br.Success = true
  709. }
  710. // @Title 研报列表
  711. // @Description 研报列表
  712. // @Param ChartPermissionId query int true "品种ID"
  713. // @Param Level query int true "品种层级"
  714. // @Param PageSize query int true "每页数据条数"
  715. // @Param CurrentIndex query int true "当前页页码,从1开始"
  716. // @Param RangeType query string true "范围类型,1-一天内,2-一周内,3-半年内"
  717. // @Param ClassifyId query int true "分类id"
  718. // @Success 200 {object} response.ReportList
  719. // @router /list [get]
  720. func (this *ReportNoAuthController) List() {
  721. br := new(models.BaseResponse).Init()
  722. defer func() {
  723. this.Data["json"] = br
  724. this.ServeJSON()
  725. }()
  726. pageSize, _ := this.GetInt("PageSize")
  727. currentIndex, _ := this.GetInt("CurrentIndex")
  728. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  729. level, _ := this.GetInt("Level")
  730. rangeType, _ := this.GetInt("RangeType")
  731. classifyId, _ := this.GetInt("ClassifyId")
  732. reports, err := services.GetNoAuthReportList(chartPermissionId, level, rangeType, classifyId, currentIndex, pageSize)
  733. if err != nil {
  734. br.Msg = "研报列表查询失败"
  735. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  736. return
  737. }
  738. if reports.Ret != 200 {
  739. br.Msg = reports.Msg
  740. br.ErrMsg = reports.ErrMsg
  741. return
  742. }
  743. br.Data = reports.Data
  744. br.Msg = "查询成功"
  745. br.Ret = 200
  746. br.Success = true
  747. }
  748. // @Title 研报详情
  749. // @Description 研报详情接口
  750. // @Param ReportId query int true "报告id"
  751. // @Success 200 {object} models.ReportDetailResp
  752. // @router /detail [get]
  753. func (this *ReportNoAuthController) Detail() {
  754. br := new(models.BaseResponse).Init()
  755. defer func() {
  756. this.Data["json"] = br
  757. this.ServeJSON()
  758. }()
  759. reportId, _ := this.GetInt("ReportId")
  760. if reportId <= 0 {
  761. br.Msg = "报告不存在"
  762. return
  763. }
  764. reportPush, err := models.GetReportPushStatusByReportId(reportId, utils.ReportTypeEta)
  765. if err != nil {
  766. br.Msg = "查询报告失败"
  767. br.ErrMsg = "查询报告推送状态失败,系统异常,Err:" + err.Error()
  768. return
  769. }
  770. if reportPush.State != utils.ReportStatePush {
  771. br.Msg = "报告未推送或已删除,请刷新重试"
  772. return
  773. }
  774. result, err := services.GetNoAuthReportDetail(reportId)
  775. if err != nil {
  776. br.Msg = "查询报告详情失败"
  777. br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
  778. return
  779. }
  780. if result.Ret != 200 {
  781. br.Msg = result.Msg
  782. br.ErrMsg = result.ErrMsg
  783. return
  784. }
  785. if result.Ret == 200 && result.Data.Report == nil {
  786. // 报告不存在, 就尝试删除推送的记录
  787. models.DeleteReportPushStatusByReportId(reportId, utils.ReportTypeEta)
  788. br.Msg = "报告已删除或未发布,请刷新重试"
  789. return
  790. }
  791. br.Msg = "查询成功"
  792. br.Success = true
  793. br.Ret = 200
  794. br.Data = result.Data
  795. }
  796. // @Title 研报搜索
  797. // @Description 研报搜索
  798. // @Param KeyWord query string true "每页数据条数"
  799. // @Param PageSize query int true "每页数据条数"
  800. // @Param CurrentIndex query int true "当前页页码,从1开始"
  801. // @Success 200 {object} models.ReportDetailResp
  802. // @router /search [get]
  803. func (this *ReportNoAuthController) Search() {
  804. br := new(models.BaseResponse).Init()
  805. defer func() {
  806. this.Data["json"] = br
  807. this.ServeJSON()
  808. }()
  809. keyWord := this.GetString("KeyWord")
  810. pageSize, _ := this.GetInt("PageSize")
  811. currentIndex, _ := this.GetInt("CurrentIndex")
  812. if pageSize <= 0 {
  813. pageSize = utils.PageSize30
  814. }
  815. if keyWord == "" {
  816. br.Msg = "请输入关键字"
  817. return
  818. }
  819. reports, total, err := services.SearchReportPush(keyWord, currentIndex, pageSize)
  820. if err != nil {
  821. br.Msg = "研报列表查询失败"
  822. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  823. return
  824. }
  825. resp := new(response.ReportSearchViewResp)
  826. list := make([]*response.ReportSearchListView, 0)
  827. for _, v := range reports {
  828. tmpReport := &response.ReportSearchListView{
  829. ReportId: v.ReportId,
  830. ClassifyIdFirst: v.ClassifyIdFirst,
  831. ClassifyNameFirst: v.ClassifyNameFirst,
  832. ClassifyIdSecond: v.ClassifyIdSecond,
  833. ClassifyNameSecond: v.ClassifyNameSecond,
  834. ClassifyIdThird: v.ClassifyIdThird,
  835. ClassifyNameThird: v.ClassifyNameThird,
  836. PublishTime: v.PublishTime.Format(utils.FormatDate),
  837. Title: v.Title,
  838. Abstract: v.Abstract,
  839. Stage: strconv.Itoa(v.Stage),
  840. Author: v.Author,
  841. ReportType: v.ReportType,
  842. }
  843. if v.PublishTime.IsZero() {
  844. tmpReport.PublishTime = ""
  845. }
  846. list = append(list, tmpReport)
  847. }
  848. page := paging.GetPaging(currentIndex, pageSize, total)
  849. resp.List = list
  850. resp.Paging = page
  851. br.Data = resp
  852. br.Msg = "查询成功"
  853. br.Ret = 200
  854. br.Success = true
  855. }