report.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. "time"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. )
  11. type ReportController struct {
  12. BaseAuthController
  13. }
  14. // @Title 研报详情
  15. // @Description 研报详情接口
  16. // @Param ReportId query int true "报告id"
  17. // @Success 200 {object} models.ReportDetailResp
  18. // @router /detail [get]
  19. func (this *ReportController) Detail() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. reportId, _ := this.GetInt("ReportId")
  26. if reportId <= 0 {
  27. br.Msg = "报告不存在"
  28. return
  29. }
  30. user := this.User
  31. if user == nil {
  32. // 如果没有用户没有绑定信息,单独处理
  33. resp, er := services.GetReportDetailNoUser(reportId)
  34. if er != nil {
  35. br.Msg = "查询报告详情失败"
  36. br.ErrMsg = "查询报告失败,系统异常,Err:" + er.Error()
  37. return
  38. }
  39. if resp.Ret != 200 {
  40. br.Msg = resp.Msg
  41. br.ErrMsg = resp.ErrMsg
  42. return
  43. }
  44. br.Msg = "查询成功"
  45. br.Data = resp.Data
  46. br.Success = true
  47. br.Ret = 200
  48. return
  49. }
  50. result, err := services.GetReportDetail(reportId, user.UserId)
  51. if err != nil {
  52. br.Msg = "查询报告详情失败"
  53. br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
  54. return
  55. }
  56. if result.Ret == 403 {
  57. br.Msg = result.Msg
  58. br.ErrMsg = result.ErrMsg
  59. return
  60. }
  61. if result.Ret == 200 && result.Data.Report == nil {
  62. // 后台没有这个报告,那么尝试删除我的收藏
  63. models.DeleteMyReportByUserIdAndReportId(user.UserId, reportId, utils.ReportTypeEta)
  64. br.Msg = "该报告已删除或不存在,请刷新页面"
  65. return
  66. }
  67. count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, reportId, utils.ReportTypeEta)
  68. if err != nil {
  69. br.Msg = "查询收藏数量失败"
  70. br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
  71. return
  72. }
  73. if count > 0 {
  74. result.Data.IsCollect = true
  75. } else {
  76. result.Data.IsCollect = false
  77. }
  78. if user.UserId != 0 {
  79. result.Data.IsSignIn = true
  80. }
  81. br.Msg = "查询成功"
  82. br.Success = true
  83. br.Ret = 200
  84. br.Data = result.Data
  85. }
  86. // @Title 研报列表
  87. // @Description 研报列表
  88. // @Param ChartPermissionId query int true "品种ID"
  89. // @Param Level query int true "品种层级"
  90. // @Param PageSize query int true "每页数据条数"
  91. // @Param CurrentIndex query int true "当前页页码,从1开始"
  92. // @Param RangeType query string true "范围类型,1-一天内,2-一周内,3-半年内"
  93. // @Param ClassifyId query int true "分类id"
  94. // @Success 200 {object} response.ReportList
  95. // @router /list [get]
  96. func (this *ReportController) List() {
  97. br := new(models.BaseResponse).Init()
  98. defer func() {
  99. this.Data["json"] = br
  100. this.ServeJSON()
  101. }()
  102. pageSize, _ := this.GetInt("PageSize")
  103. currentIndex, _ := this.GetInt("CurrentIndex")
  104. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  105. level, _ := this.GetInt("Level")
  106. rangeType, _ := this.GetInt("RangeType")
  107. classifyId, _ := this.GetInt("ClassifyId")
  108. reports, err := services.GetReportList(chartPermissionId, level, rangeType, classifyId, currentIndex, pageSize)
  109. if err != nil {
  110. br.Msg = "研报列表查询失败"
  111. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  112. return
  113. }
  114. if reports.Ret != 200 {
  115. br.Msg = reports.Msg
  116. br.ErrMsg = reports.ErrMsg
  117. return
  118. }
  119. br.Data = reports.Data
  120. br.Msg = "查询成功"
  121. br.Ret = 200
  122. br.Success = true
  123. }
  124. // @Title pdf研报列表
  125. // @Description pdf研报列表
  126. // @Param ChartPermissionId query int true "品种ID"
  127. // @Param PageSize query int true "每页数据条数"
  128. // @Param CurrentIndex query int true "当前页页码,从1开始"
  129. // @Param RangeType query int true "范围类型,1-一天内,2-一周内,3-半年内"
  130. // @Param ClassifyId query int true "二级分类id"
  131. // @Success 200 {object} response.ReportList
  132. // @router /pdf/list [get]
  133. func (this *ReportController) PdfList() {
  134. br := new(models.BaseResponse).Init()
  135. defer func() {
  136. this.Data["json"] = br
  137. this.ServeJSON()
  138. }()
  139. pageSize, _ := this.GetInt("PageSize")
  140. currentIndex, _ := this.GetInt("CurrentIndex")
  141. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  142. classifyId, _ := this.GetInt("ClassifyId")
  143. rangeType, _ := this.GetInt("RangeType")
  144. if pageSize <= 0 {
  145. pageSize = utils.PageSize20
  146. }
  147. if currentIndex <= 0 {
  148. currentIndex = 1
  149. }
  150. if chartPermissionId <= 0 {
  151. br.Msg = "请输入品种ID"
  152. return
  153. }
  154. var condition string
  155. var pars []interface{}
  156. switch rangeType {
  157. case 1:
  158. condition += ` AND DATE(publish_time)=DATE(NOW()) `
  159. case 2:
  160. condition += ` AND DATE(publish_time) BETWEEN DATE_SUB(NOW(),INTERVAL 1 WEEK) AND NOW() `
  161. case 3:
  162. condition += ` AND DATE(publish_time) BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW() `
  163. }
  164. startSize := utils.StartIndex(currentIndex, pageSize)
  165. if classifyId != 0 {
  166. condition += ` AND classify_id_second=?`
  167. pars = append(pars, classifyId)
  168. } else if chartPermissionId != 0 {
  169. resp, err := services.GetClassifyListByChartPermission(chartPermissionId)
  170. if err != nil {
  171. br.Msg = "获取分类失败"
  172. br.ErrMsg = "获取分类失败,系统异常,Err:" + err.Error()
  173. return
  174. }
  175. if resp.Ret != 200 {
  176. br.Msg = resp.Msg
  177. br.ErrMsg = resp.ErrMsg
  178. return
  179. }
  180. classifyList := resp.Data
  181. if len(classifyList) == 0 {
  182. resp := new(response.ReportPdfResp)
  183. br.Msg = "查询成功"
  184. br.Ret = 200
  185. br.Success = true
  186. br.Data = resp
  187. return
  188. }
  189. condition += ` AND classify_id_second IN (` + utils.GetOrmReplaceHolder(len(classifyList)) + `)`
  190. for _, item := range classifyList {
  191. pars = append(pars, item.Id)
  192. }
  193. }
  194. total, err := models.GetReportPdfCountByCondition(condition, pars)
  195. if err != nil {
  196. br.Msg = "研报列表查询失败"
  197. br.ErrMsg = "研报列表统计查询失败,系统异常,Err:" + err.Error()
  198. return
  199. }
  200. reportPdfList, err := models.GetReportPdfListByCondition(condition, pars, startSize, pageSize)
  201. if err != nil {
  202. br.Msg = "研报列表查询失败"
  203. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  204. return
  205. }
  206. page := paging.GetPaging(currentIndex, pageSize, total)
  207. resp := new(response.ReportPdfResp)
  208. resp.List = reportPdfList
  209. resp.Paging = page
  210. br.Msg = "查询成功"
  211. br.Ret = 200
  212. br.Success = true
  213. br.Data = resp
  214. }
  215. // @Title pdf研报详情
  216. // @Description pdf研报详情
  217. // @Param ReportPdfId query int true "品种ID"
  218. // @Success 200 {object} response.ReportList
  219. // @router /pdf/detail [get]
  220. func (this *ReportController) PdfDetail() {
  221. br := new(models.BaseResponse).Init()
  222. defer func() {
  223. this.Data["json"] = br
  224. this.ServeJSON()
  225. }()
  226. user := this.User
  227. // 有效期是否到期
  228. var vailStatus int
  229. if user.Status == utils.UserStatusFormal || user.Status == utils.UserStatusNo {
  230. if user.ValidEndTime.After(time.Now()) && user.ValidStartTime.Before(time.Now()) {
  231. vailStatus = 2
  232. } else {
  233. // 不在有效期时间则设置为过期, 将用户状态禁用
  234. vailStatus = 1
  235. user.Status = utils.UserStatusNo
  236. }
  237. }
  238. reportPdfId, _ := this.GetInt("ReportPdfId")
  239. if reportPdfId <= 0 {
  240. br.Msg = "研报不存在或已删除"
  241. return
  242. }
  243. reportPdf, err := models.GetReportPdfById(reportPdfId)
  244. if err != nil {
  245. if err.Error() == utils.ErrNoRow() {
  246. br.Msg = "研报不存在或已删除"
  247. return
  248. }
  249. br.Msg = "研报不存在或已删除"
  250. br.ErrMsg = "研报不存在或已删除,系统异常,Err:" + err.Error()
  251. return
  252. }
  253. permissionResp, err := services.GetChartPermissionListByClassifyId(reportPdf.ClassifyIdSecond, 0)
  254. if err != nil {
  255. br.Msg = "研报不存在或已删除"
  256. br.ErrMsg = "获取权限失败,系统异常,Err:" + err.Error()
  257. return
  258. }
  259. if permissionResp.Ret != 200 {
  260. br.Msg = permissionResp.Msg
  261. br.ErrMsg = permissionResp.ErrMsg
  262. return
  263. }
  264. var IsHas bool
  265. var IsPublic bool
  266. permissionMap := make(map[int]struct{})
  267. for _, v := range permissionResp.Data {
  268. if v.ChartPermissionId == 1 {
  269. IsPublic = true
  270. }
  271. permissionMap[v.ChartPermissionId] = struct{}{}
  272. }
  273. resp := new(response.ReportPdfDetailResp)
  274. if !IsPublic {
  275. // 如果是私有报告,用户权限过期直接返回有效期已过
  276. if vailStatus == 1 {
  277. resp.Report = reportPdf
  278. resp.Status = utils.ReportPermissionStatusExpired
  279. br.Ret = 200
  280. br.Data = resp
  281. br.Msg = "用户权限不足"
  282. return
  283. }
  284. // 如果被禁用或是潜在用户,直接返回无阅读报告权限
  285. if user.Status == utils.UserStatusNo || user.Status == utils.UserStatusPotential {
  286. resp.Report = reportPdf
  287. resp.Status = utils.ReportPermissionStatusNo
  288. br.Ret = 200
  289. br.Data = resp
  290. br.Msg = "用户权限不足"
  291. return
  292. }
  293. userChartPermissionIds, err := models.GetUserChartPermissionIdByUserId(user.UserId)
  294. if err != nil {
  295. br.Msg = "获取用户权限失败"
  296. br.ErrMsg = "获取用户权限失败,Err:" + err.Error()
  297. return
  298. }
  299. if len(userChartPermissionIds) == 0 {
  300. resp.Report = reportPdf
  301. resp.Status = utils.ReportPermissionStatusNo
  302. br.Ret = 200
  303. br.Data = resp
  304. br.Msg = "用户权限不足"
  305. return
  306. }
  307. for _, v := range userChartPermissionIds {
  308. if _, ok := permissionMap[v]; ok {
  309. IsHas = true
  310. break
  311. }
  312. }
  313. if !IsHas {
  314. resp.Report = reportPdf
  315. resp.Status = utils.ReportPermissionStatusNoPermission
  316. br.Ret = 200
  317. br.Data = resp
  318. br.Msg = "用户权限不足"
  319. return
  320. }
  321. } else {
  322. reportPdf.IsPublic = IsPublic
  323. }
  324. count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, reportPdf.ReportPdfId, utils.ReportTypePdf)
  325. if err != nil {
  326. br.Msg = "获取研报详情失败"
  327. br.ErrMsg = "获取用户收藏记录失败,Err:" + err.Error()
  328. return
  329. }
  330. if count > 0 {
  331. reportPdf.IsCollect = true
  332. } else {
  333. reportPdf.IsCollect = false
  334. }
  335. resp.Report = reportPdf
  336. resp.Status = utils.ReportPermissionStatusHas
  337. br.Msg = "查询成功"
  338. br.Ret = 200
  339. br.Success = true
  340. br.Data = resp
  341. }
  342. // @Title 今日研报列表
  343. // @Description 今日研报列表
  344. // @Param PageSize query int true "每页数据条数"
  345. // @Param CurrentIndex query int true "当前页页码,从1开始"
  346. // @Success 200 {object} models.ReportDetailResp
  347. // @router /daily/list [get]
  348. func (this *ReportController) DailyList() {
  349. br := new(models.BaseResponse).Init()
  350. defer func() {
  351. this.Data["json"] = br
  352. this.ServeJSON()
  353. }()
  354. // 暂不使用分页
  355. pageSize, _ := this.GetInt("PageSize")
  356. currentIndex, _ := this.GetInt("CurrentIndex")
  357. if pageSize <= 0 {
  358. pageSize = utils.PageSize20
  359. }
  360. if currentIndex <= 0 {
  361. currentIndex = 1
  362. }
  363. resp, err := services.GetReportDailyList()
  364. if err != nil {
  365. br.Msg = "研报列表查询失败"
  366. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  367. return
  368. }
  369. if resp.Ret != 200 {
  370. br.Msg = resp.Msg
  371. br.ErrMsg = resp.ErrMsg
  372. return
  373. }
  374. reportList := resp.Data
  375. for _, v := range reportList.List {
  376. v.ReportType = utils.ReportTypeEta
  377. }
  378. reportPdfList, err := models.GetReportPdfDailyList()
  379. if err != nil {
  380. br.Msg = "研报列表查询失败"
  381. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  382. return
  383. }
  384. var classifyIds []int
  385. for _, v := range reportPdfList {
  386. classifyIds = append(classifyIds, v.ClassifyIdSecond)
  387. }
  388. if len(classifyIds) > 0 {
  389. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  390. if err != nil {
  391. br.Msg = "研报列表查询失败"
  392. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  393. return
  394. }
  395. if classifyResp.Ret != 200 {
  396. br.Msg = classifyResp.Msg
  397. br.ErrMsg = classifyResp.ErrMsg
  398. return
  399. }
  400. classifyPermissionMap := make(map[int][]string)
  401. for _, v := range classifyResp.Data {
  402. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  403. }
  404. for _, v := range reportPdfList {
  405. reportList.List = append(reportList.List, &models.ReportView{
  406. Id: v.ReportPdfId,
  407. ClassifyIdFirst: v.ClassifyIdFirst,
  408. ClassifyNameFirst: v.ClassifyNameFirst,
  409. ClassifyIdSecond: v.ClassifyIdSecond,
  410. ClassifyNameSecond: v.ClassifyNameSecond,
  411. PermissionNames: classifyPermissionMap[v.ClassifyIdSecond],
  412. PdfUrl: v.PdfUrl,
  413. Title: v.Title,
  414. Abstract: v.Abstract,
  415. Stage: v.Stage,
  416. Author: v.Author,
  417. ReportType: utils.ReportTypePdf,
  418. PublishTime: v.PublishTime.Format(utils.FormatDateTime),
  419. ModifyTime: v.ModifyTime,
  420. })
  421. }
  422. }
  423. sort.Sort(models.ByPublishTimeReportView(reportList.List))
  424. br.Data = reportList
  425. br.Msg = "查询成功"
  426. br.Ret = 200
  427. br.Success = true
  428. }
  429. // @Title 最新研报列表
  430. // @Description 最新研报列表
  431. // @Param PageSize query int true "每页数据条数"
  432. // @Param CurrentIndex query int true "当前页页码,从1开始"
  433. // @Success 200 {object} models.ReportDetailResp
  434. // @router /recent/list [get]
  435. func (this *ReportController) RecentList() {
  436. br := new(models.BaseResponse).Init()
  437. defer func() {
  438. this.Data["json"] = br
  439. this.ServeJSON()
  440. }()
  441. // 暂不使用分页
  442. pageSize, _ := this.GetInt("PageSize")
  443. currentIndex, _ := this.GetInt("CurrentIndex")
  444. if pageSize <= 0 {
  445. pageSize = 3
  446. }
  447. resp, err := services.GetReportRecentList(currentIndex, pageSize)
  448. if err != nil {
  449. br.Msg = "研报列表查询失败"
  450. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  451. return
  452. }
  453. // 查询已发布的pdf
  454. condition := ` AND state=1 `
  455. reportPdfList, err := models.GetReportPdfListByCondition(condition, []interface{}{}, 0, 3)
  456. if err != nil {
  457. br.Msg = "研报列表查询失败"
  458. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  459. return
  460. }
  461. reportList := resp.Data
  462. for _, v := range reportList.List {
  463. v.ReportType = utils.ReportTypeEta
  464. }
  465. var classifyIds []int
  466. for _, v := range reportPdfList {
  467. classifyIds = append(classifyIds, v.ClassifyIdSecond)
  468. }
  469. classifyResp, err := services.GetFirstChartPermission(classifyIds)
  470. if err != nil {
  471. br.Msg = "研报列表查询失败"
  472. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  473. return
  474. }
  475. if classifyResp.Ret != 200 {
  476. br.Msg = classifyResp.Msg
  477. br.ErrMsg = classifyResp.ErrMsg
  478. return
  479. }
  480. classifyPermissionMap := make(map[int][]string)
  481. for _, v := range classifyResp.Data {
  482. classifyPermissionMap[v.ClassifyId] = v.PermissionNames
  483. }
  484. for _, v := range reportPdfList {
  485. reportList.List = append(reportList.List, &models.ReportView{
  486. Id: v.ReportPdfId,
  487. ClassifyIdFirst: v.ClassifyIdFirst,
  488. ClassifyNameFirst: v.ClassifyNameFirst,
  489. ClassifyIdSecond: v.ClassifyIdSecond,
  490. ClassifyNameSecond: v.ClassifyNameSecond,
  491. PermissionNames: classifyPermissionMap[v.ClassifyIdSecond],
  492. PdfUrl: v.PdfUrl,
  493. Title: v.Title,
  494. Abstract: v.Abstract,
  495. Stage: v.Stage,
  496. Author: v.Author,
  497. ReportType: utils.ReportTypePdf,
  498. PublishTime: v.PublishTime.Format(utils.FormatDateTime),
  499. ModifyTime: v.ModifyTime,
  500. })
  501. }
  502. sort.Sort(models.ByPublishTimeReportView(reportList.List))
  503. endIdx := len(reportList.List)
  504. if endIdx > 3 {
  505. endIdx = 3
  506. }
  507. reportList.List = reportList.List[:endIdx]
  508. br.Data = reportList
  509. br.Msg = "查询成功"
  510. br.Ret = 200
  511. br.Success = true
  512. }
  513. // @Title 研报列表
  514. // @Description 研报列表
  515. // @Param ReportId query int true "报告id"
  516. // @Param chartPermissionId query int true "品种ID"
  517. // @Param PageSize query int true "每页数据条数"
  518. // @Param CurrentIndex query int true "当前页页码,从1开始"
  519. // @Success 200 {object} models.ReportDetailResp
  520. // @router /search [get]
  521. func (this *ReportController) Search() {
  522. br := new(models.BaseResponse).Init()
  523. defer func() {
  524. this.Data["json"] = br
  525. this.ServeJSON()
  526. }()
  527. keyWord := this.GetString("KeyWord")
  528. pageSize, _ := this.GetInt("PageSize")
  529. currentIndex, _ := this.GetInt("CurrentIndex")
  530. if pageSize <= 0 {
  531. pageSize = utils.PageSize30
  532. }
  533. if keyWord == "" {
  534. br.Msg = "请输入关键字"
  535. return
  536. }
  537. reports, err := services.SearchReport(keyWord, currentIndex, pageSize)
  538. if err != nil {
  539. br.Msg = "研报列表查询失败"
  540. br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
  541. return
  542. }
  543. if reports.Ret != 200 {
  544. br.Msg = reports.Msg
  545. br.ErrMsg = reports.ErrMsg
  546. return
  547. }
  548. resp := new(response.ReportSearchViewResp)
  549. list := make([]*response.ReportSearchListView, 0)
  550. for _, v := range reports.Data.List {
  551. tmpReport := &response.ReportSearchListView{
  552. ReportId: v.ReportId,
  553. ReportChapterId: v.ReportChapterId,
  554. ClassifyIdFirst: v.ClassifyIdFirst,
  555. ClassifyNameFirst: v.ClassifyNameFirst,
  556. ClassifyIdSecond: v.ClassifyIdSecond,
  557. ClassifyNameSecond: v.ClassifyNameSecond,
  558. ReportChapterTypeId: v.ReportChapterTypeId,
  559. PublishTime: v.PublishTime.Format(utils.FormatDate),
  560. Title: v.Title,
  561. ContentSub: v.ContentSub,
  562. Abstract: v.Abstract,
  563. Stage: v.Stage,
  564. Author: v.Author,
  565. PdfUrl: v.PdfUrl,
  566. ReportType: v.ReportType,
  567. }
  568. if v.PublishTime.IsZero() {
  569. tmpReport.PublishTime = ""
  570. }
  571. list = append(list, tmpReport)
  572. }
  573. resp.List = list
  574. resp.Paging = reports.Data.Paging
  575. br.Data = resp
  576. br.Msg = "查询成功"
  577. br.Ret = 200
  578. br.Success = true
  579. }