report.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  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 {
  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.UserStatusNo || 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. userChartPermissionIds, err := models.GetUserChartPermissionIdByUserId(user.UserId)
  376. if err != nil {
  377. br.Msg = "获取用户权限失败"
  378. br.ErrMsg = "获取用户权限失败,Err:" + err.Error()
  379. return
  380. }
  381. if len(userChartPermissionIds) == 0 {
  382. resp.Report = reportPdf
  383. resp.Status = utils.ReportPermissionStatusNo
  384. br.Ret = 200
  385. br.Data = resp
  386. br.Msg = "用户权限不足"
  387. return
  388. }
  389. for _, v := range userChartPermissionIds {
  390. if _, ok := permissionMap[v]; ok {
  391. IsHas = true
  392. break
  393. }
  394. }
  395. if !IsHas {
  396. resp.Report = reportPdf
  397. resp.Status = utils.ReportPermissionStatusNoPermission
  398. br.Ret = 200
  399. br.Data = resp
  400. br.Msg = "用户权限不足"
  401. return
  402. }
  403. } else {
  404. reportPdf.IsPublic = IsPublic
  405. }
  406. count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, reportPdf.ReportPdfId, utils.ReportTypePdf)
  407. if err != nil {
  408. br.Msg = "获取研报详情失败"
  409. br.ErrMsg = "获取用户收藏记录失败,Err:" + err.Error()
  410. return
  411. }
  412. if count > 0 {
  413. reportPdf.IsCollect = true
  414. } else {
  415. reportPdf.IsCollect = false
  416. }
  417. resp.Report = reportPdf
  418. resp.Status = utils.ReportPermissionStatusHas
  419. br.Msg = "查询成功"
  420. br.Ret = 200
  421. br.Success = true
  422. br.Data = resp
  423. }
  424. // @Title 今日研报列表
  425. // @Description 今日研报列表
  426. // @Param PageSize query int true "每页数据条数"
  427. // @Param CurrentIndex query int true "当前页页码,从1开始"
  428. // @Success 200 {object} models.ReportDetailResp
  429. // @router /daily/list [get]
  430. func (this *ReportController) DailyList() {
  431. br := new(models.BaseResponse).Init()
  432. defer func() {
  433. this.Data["json"] = br
  434. this.ServeJSON()
  435. }()
  436. // 暂不使用分页
  437. pageSize, _ := this.GetInt("PageSize")
  438. currentIndex, _ := this.GetInt("CurrentIndex")
  439. if pageSize <= 0 {
  440. pageSize = utils.PageSize20
  441. }
  442. if currentIndex <= 0 {
  443. currentIndex = 1
  444. }
  445. resp, err := services.GetReportDailyList()
  446. if err != nil {
  447. br.Msg = "研报列表查询失败"
  448. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  449. return
  450. }
  451. if resp.Ret != 200 {
  452. br.Msg = resp.Msg
  453. br.ErrMsg = resp.ErrMsg
  454. return
  455. }
  456. reportList := resp.Data
  457. for _, v := range reportList.List {
  458. v.ReportType = utils.ReportTypeEta
  459. }
  460. reportPdfList, err := models.GetReportPdfDailyList()
  461. if err != nil {
  462. br.Msg = "研报列表查询失败"
  463. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  464. return
  465. }
  466. var classifyIds []int
  467. for _, v := range reportPdfList {
  468. var reportClassifyId int
  469. if v.ClassifyIdFirst != 0 {
  470. reportClassifyId = v.ClassifyIdFirst
  471. }
  472. if v.ClassifyIdSecond != 0 {
  473. reportClassifyId = v.ClassifyIdSecond
  474. }
  475. if v.ClassifyIdThird != 0 {
  476. reportClassifyId = v.ClassifyIdThird
  477. }
  478. classifyIds = append(classifyIds, reportClassifyId)
  479. }
  480. if len(classifyIds) > 0 {
  481. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  482. if err != nil {
  483. br.Msg = "研报列表查询失败"
  484. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  485. return
  486. }
  487. if classifyResp.Ret != 200 {
  488. br.Msg = classifyResp.Msg
  489. br.ErrMsg = classifyResp.ErrMsg
  490. return
  491. }
  492. classifyPermissionMap := make(map[int][]string)
  493. for _, v := range classifyResp.Data {
  494. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  495. }
  496. for _, v := range reportPdfList {
  497. var reportClassifyId int
  498. if v.ClassifyIdFirst != 0 {
  499. reportClassifyId = v.ClassifyIdFirst
  500. }
  501. if v.ClassifyIdSecond != 0 {
  502. reportClassifyId = v.ClassifyIdSecond
  503. }
  504. if v.ClassifyIdThird != 0 {
  505. reportClassifyId = v.ClassifyIdThird
  506. }
  507. // 过滤没有绑定品种的研报
  508. if classifyPermissionMap[reportClassifyId] == nil {
  509. continue
  510. }
  511. reportList.List = append(reportList.List, &models.ReportView{
  512. Id: v.ReportPdfId,
  513. ClassifyIdFirst: v.ClassifyIdFirst,
  514. ClassifyNameFirst: v.ClassifyNameFirst,
  515. ClassifyIdSecond: v.ClassifyIdSecond,
  516. ClassifyNameSecond: v.ClassifyNameSecond,
  517. ClassifyIdThird: v.ClassifyIdThird,
  518. ClassifyNameThird: v.ClassifyNameThird,
  519. PermissionNames: classifyPermissionMap[reportClassifyId],
  520. PdfUrl: v.PdfUrl,
  521. Title: v.Title,
  522. Abstract: v.Abstract,
  523. Stage: v.Stage,
  524. Author: v.Author,
  525. ReportType: utils.ReportTypePdf,
  526. PublishTime: v.PublishTime.Format(utils.FormatDateTime),
  527. ModifyTime: v.ModifyTime,
  528. })
  529. }
  530. }
  531. sort.Sort(models.ByPublishTimeReportView(reportList.List))
  532. br.Data = reportList
  533. br.Msg = "查询成功"
  534. br.Ret = 200
  535. br.Success = true
  536. }
  537. // @Title 最新研报列表
  538. // @Description 最新研报列表
  539. // @Param PageSize query int true "每页数据条数"
  540. // @Param CurrentIndex query int true "当前页页码,从1开始"
  541. // @Success 200 {object} models.ReportDetailResp
  542. // @router /recent/list [get]
  543. func (this *ReportController) RecentList() {
  544. br := new(models.BaseResponse).Init()
  545. defer func() {
  546. this.Data["json"] = br
  547. this.ServeJSON()
  548. }()
  549. // 暂不使用分页
  550. pageSize, _ := this.GetInt("PageSize")
  551. currentIndex, _ := this.GetInt("CurrentIndex")
  552. if pageSize <= 0 {
  553. pageSize = 3
  554. }
  555. resp, err := services.GetReportRecentList(currentIndex, pageSize)
  556. if err != nil {
  557. br.Msg = "研报列表查询失败"
  558. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  559. return
  560. }
  561. // 查询已发布的pdf
  562. reportPdfList, err := models.GetRecentReportPdfList(0, 3)
  563. if err != nil {
  564. br.Msg = "研报列表查询失败"
  565. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  566. return
  567. }
  568. reportList := resp.Data
  569. for _, v := range reportList.List {
  570. v.ReportType = utils.ReportTypeEta
  571. }
  572. var classifyIds []int
  573. for _, v := range reportPdfList {
  574. var reportClassifyId int
  575. if v.ClassifyIdFirst != 0 {
  576. reportClassifyId = v.ClassifyIdFirst
  577. }
  578. if v.ClassifyIdSecond != 0 {
  579. reportClassifyId = v.ClassifyIdSecond
  580. }
  581. if v.ClassifyIdThird != 0 {
  582. reportClassifyId = v.ClassifyIdThird
  583. }
  584. classifyIds = append(classifyIds, reportClassifyId)
  585. }
  586. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  587. if err != nil {
  588. br.Msg = "研报列表查询失败"
  589. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  590. return
  591. }
  592. if classifyResp.Ret != 200 {
  593. br.Msg = classifyResp.Msg
  594. br.ErrMsg = classifyResp.ErrMsg
  595. }
  596. classifyPermissionMap := make(map[int][]string)
  597. for _, v := range classifyResp.Data {
  598. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  599. }
  600. for _, v := range reportPdfList {
  601. var reportClassifyId int
  602. if v.ClassifyIdFirst != 0 {
  603. reportClassifyId = v.ClassifyIdFirst
  604. }
  605. if v.ClassifyIdSecond != 0 {
  606. reportClassifyId = v.ClassifyIdSecond
  607. }
  608. if v.ClassifyIdThird != 0 {
  609. reportClassifyId = v.ClassifyIdThird
  610. }
  611. // 过滤没有绑定品种的研报
  612. if classifyPermissionMap[reportClassifyId] == nil {
  613. continue
  614. }
  615. reportList.List = append(reportList.List, &models.ReportView{
  616. Id: v.ReportPdfId,
  617. ClassifyIdFirst: v.ClassifyIdFirst,
  618. ClassifyNameFirst: v.ClassifyNameFirst,
  619. ClassifyIdSecond: v.ClassifyIdSecond,
  620. ClassifyNameSecond: v.ClassifyNameSecond,
  621. ClassifyIdThird: v.ClassifyIdThird,
  622. ClassifyNameThird: v.ClassifyNameThird,
  623. PermissionNames: classifyPermissionMap[reportClassifyId],
  624. PdfUrl: v.PdfUrl,
  625. Title: v.Title,
  626. Abstract: v.Abstract,
  627. Stage: v.Stage,
  628. Author: v.Author,
  629. ReportType: utils.ReportTypePdf,
  630. PublishTime: v.PublishTime.Format(utils.FormatDateTime),
  631. ModifyTime: v.ModifyTime,
  632. })
  633. }
  634. sort.Sort(models.ByPublishTimeReportView(reportList.List))
  635. endIdx := len(reportList.List)
  636. if endIdx > 3 {
  637. endIdx = 3
  638. }
  639. reportList.List = reportList.List[:endIdx]
  640. br.Data = reportList
  641. br.Msg = "查询成功"
  642. br.Ret = 200
  643. br.Success = true
  644. }
  645. // @Title 研报列表
  646. // @Description 研报列表
  647. // @Param ReportId query int true "报告id"
  648. // @Param chartPermissionId query int true "品种ID"
  649. // @Param PageSize query int true "每页数据条数"
  650. // @Param CurrentIndex query int true "当前页页码,从1开始"
  651. // @Success 200 {object} models.ReportDetailResp
  652. // @router /search [get]
  653. func (this *ReportController) Search() {
  654. br := new(models.BaseResponse).Init()
  655. defer func() {
  656. this.Data["json"] = br
  657. this.ServeJSON()
  658. }()
  659. keyWord := this.GetString("KeyWord")
  660. pageSize, _ := this.GetInt("PageSize")
  661. currentIndex, _ := this.GetInt("CurrentIndex")
  662. if pageSize <= 0 {
  663. pageSize = utils.PageSize30
  664. }
  665. if keyWord == "" {
  666. br.Msg = "请输入关键字"
  667. return
  668. }
  669. reports, err := services.SearchReport(keyWord, currentIndex, pageSize)
  670. if err != nil {
  671. br.Msg = "研报列表查询失败"
  672. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  673. return
  674. }
  675. if reports.Ret != 200 {
  676. br.Msg = reports.Msg
  677. br.ErrMsg = reports.ErrMsg
  678. return
  679. }
  680. resp := new(response.ReportSearchViewResp)
  681. list := make([]*response.ReportSearchListView, 0)
  682. for _, v := range reports.Data.List {
  683. tmpReport := &response.ReportSearchListView{
  684. ReportId: v.ReportId,
  685. ReportChapterId: v.ReportChapterId,
  686. ClassifyIdFirst: v.ClassifyIdFirst,
  687. ClassifyNameFirst: v.ClassifyNameFirst,
  688. ClassifyIdSecond: v.ClassifyIdSecond,
  689. ClassifyNameSecond: v.ClassifyNameSecond,
  690. ClassifyIdThird: v.ClassifyIdThird,
  691. ClassifyNameThird: v.ClassifyNameThird,
  692. ReportChapterTypeId: v.ReportChapterTypeId,
  693. PublishTime: v.PublishTime.Format(utils.FormatDate),
  694. Title: v.Title,
  695. ContentSub: v.ContentSub,
  696. Abstract: v.Abstract,
  697. Stage: v.Stage,
  698. Author: v.Author,
  699. PdfUrl: v.PdfUrl,
  700. ReportType: v.ReportType,
  701. }
  702. if v.PublishTime.IsZero() {
  703. tmpReport.PublishTime = ""
  704. }
  705. list = append(list, tmpReport)
  706. }
  707. resp.List = list
  708. resp.Paging = reports.Data.Paging
  709. br.Data = resp
  710. br.Msg = "查询成功"
  711. br.Ret = 200
  712. br.Success = true
  713. }
  714. // @Title 研报列表
  715. // @Description 研报列表
  716. // @Param ChartPermissionId query int true "品种ID"
  717. // @Param Level query int true "品种层级"
  718. // @Param PageSize query int true "每页数据条数"
  719. // @Param CurrentIndex query int true "当前页页码,从1开始"
  720. // @Param RangeType query string true "范围类型,1-一天内,2-一周内,3-半年内"
  721. // @Param ClassifyId query int true "分类id"
  722. // @Success 200 {object} response.ReportList
  723. // @router /list [get]
  724. func (this *ReportNoAuthController) List() {
  725. br := new(models.BaseResponse).Init()
  726. defer func() {
  727. this.Data["json"] = br
  728. this.ServeJSON()
  729. }()
  730. pageSize, _ := this.GetInt("PageSize")
  731. currentIndex, _ := this.GetInt("CurrentIndex")
  732. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  733. level, _ := this.GetInt("Level")
  734. rangeType, _ := this.GetInt("RangeType")
  735. classifyId, _ := this.GetInt("ClassifyId")
  736. reports, err := services.GetNoAuthReportList(chartPermissionId, level, rangeType, classifyId, currentIndex, pageSize)
  737. if err != nil {
  738. br.Msg = "研报列表查询失败"
  739. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  740. return
  741. }
  742. if reports.Ret != 200 {
  743. br.Msg = reports.Msg
  744. br.ErrMsg = reports.ErrMsg
  745. return
  746. }
  747. br.Data = reports.Data
  748. br.Msg = "查询成功"
  749. br.Ret = 200
  750. br.Success = true
  751. }
  752. // @Title 研报详情
  753. // @Description 研报详情接口
  754. // @Param ReportId query int true "报告id"
  755. // @Success 200 {object} models.ReportDetailResp
  756. // @router /detail [get]
  757. func (this *ReportNoAuthController) Detail() {
  758. br := new(models.BaseResponse).Init()
  759. defer func() {
  760. this.Data["json"] = br
  761. this.ServeJSON()
  762. }()
  763. reportId, _ := this.GetInt("ReportId")
  764. if reportId <= 0 {
  765. br.Msg = "报告不存在"
  766. return
  767. }
  768. reportPush, err := models.GetReportPushStatusByReportId(reportId, utils.ReportTypeEta)
  769. if err != nil {
  770. br.Msg = "查询报告失败"
  771. br.ErrMsg = "查询报告推送状态失败,系统异常,Err:" + err.Error()
  772. return
  773. }
  774. if reportPush.State != utils.ReportStatePush {
  775. br.Msg = "报告未推送或已删除,请刷新重试"
  776. return
  777. }
  778. result, err := services.GetNoAuthReportDetail(reportId)
  779. if err != nil {
  780. br.Msg = "查询报告详情失败"
  781. br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
  782. return
  783. }
  784. if result.Ret != 200 {
  785. br.Msg = result.Msg
  786. br.ErrMsg = result.ErrMsg
  787. return
  788. }
  789. if result.Ret == 200 && result.Data.Report == nil {
  790. // 报告不存在, 就尝试删除推送的记录
  791. models.DeleteReportPushStatusByReportId(reportId, utils.ReportTypeEta)
  792. br.Msg = "报告已删除或未发布,请刷新重试"
  793. return
  794. }
  795. br.Msg = "查询成功"
  796. br.Success = true
  797. br.Ret = 200
  798. br.Data = result.Data
  799. }
  800. // @Title 研报搜索
  801. // @Description 研报搜索
  802. // @Param KeyWord query string true "每页数据条数"
  803. // @Param PageSize query int true "每页数据条数"
  804. // @Param CurrentIndex query int true "当前页页码,从1开始"
  805. // @Success 200 {object} models.ReportDetailResp
  806. // @router /search [get]
  807. func (this *ReportNoAuthController) Search() {
  808. br := new(models.BaseResponse).Init()
  809. defer func() {
  810. this.Data["json"] = br
  811. this.ServeJSON()
  812. }()
  813. keyWord := this.GetString("KeyWord")
  814. pageSize, _ := this.GetInt("PageSize")
  815. currentIndex, _ := this.GetInt("CurrentIndex")
  816. if pageSize <= 0 {
  817. pageSize = utils.PageSize30
  818. }
  819. if keyWord == "" {
  820. br.Msg = "请输入关键字"
  821. return
  822. }
  823. reports, total, err := services.SearchReportPush(keyWord, currentIndex, pageSize)
  824. if err != nil {
  825. br.Msg = "研报列表查询失败"
  826. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  827. return
  828. }
  829. resp := new(response.ReportSearchViewResp)
  830. list := make([]*response.ReportSearchListView, 0)
  831. for _, v := range reports {
  832. tmpReport := &response.ReportSearchListView{
  833. ReportId: v.ReportId,
  834. ClassifyIdFirst: v.ClassifyIdFirst,
  835. ClassifyNameFirst: v.ClassifyNameFirst,
  836. ClassifyIdSecond: v.ClassifyIdSecond,
  837. ClassifyNameSecond: v.ClassifyNameSecond,
  838. ClassifyIdThird: v.ClassifyIdThird,
  839. ClassifyNameThird: v.ClassifyNameThird,
  840. PublishTime: v.PublishTime.Format(utils.FormatDate),
  841. Title: v.Title,
  842. Abstract: v.Abstract,
  843. Stage: strconv.Itoa(v.Stage),
  844. Author: v.Author,
  845. ReportType: v.ReportType,
  846. }
  847. if v.PublishTime.IsZero() {
  848. tmpReport.PublishTime = ""
  849. }
  850. list = append(list, tmpReport)
  851. }
  852. page := paging.GetPaging(currentIndex, pageSize, total)
  853. resp.List = list
  854. resp.Paging = page
  855. br.Data = resp
  856. br.Msg = "查询成功"
  857. br.Ret = 200
  858. br.Success = true
  859. }