research_report.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package report
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. "hongze/hongze_yb/logic/report"
  6. "hongze/hongze_yb/services/user"
  7. "strconv"
  8. )
  9. // GetResearchReportInfo
  10. // @Tags 报告接口
  11. // @Summary 获取报告详情
  12. // @Description 获取报告详情
  13. // @Security ApiKeyAuth
  14. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  15. // @Accept json
  16. // @Product json
  17. // @Param research_report_id query int true "活动ID"
  18. // @Success 200 {object} yb_activity.ActivityDetail
  19. // @failure 400 {string} string "获取失败"
  20. // @Router /report/research_report [get]
  21. func GetResearchReportInfo(c *gin.Context) {
  22. userInfo := user.GetInfoByClaims(c)
  23. researchReportIdStr := c.DefaultQuery("research_report_id", "")
  24. if researchReportIdStr == "" {
  25. response.Fail("请传入报告id", c)
  26. return
  27. }
  28. researchReportId, tmpErr := strconv.Atoi(researchReportIdStr)
  29. if tmpErr != nil {
  30. response.Fail("报告id异常", c)
  31. return
  32. }
  33. reportInfo, hasPermission, err := report.GetResearchReportInfo(uint64(researchReportId), userInfo.UserID)
  34. if err != nil {
  35. response.Fail("获取报告失败", c)
  36. return
  37. }
  38. if !hasPermission {
  39. response.Fail("无权限", c)
  40. return
  41. }
  42. response.OkData("获取成功", reportInfo, c)
  43. }
  44. // GetResearchReportChapter
  45. // @Tags 报告接口
  46. // @Summary 获取报告章节详情
  47. // @Description 获取报告章节详情
  48. // @Security ApiKeyAuth
  49. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  50. // @Accept json
  51. // @Product json
  52. // @Param research_report_type_id query int true "章节ID"
  53. // @Success 200 {object} yb_activity.ActivityDetail
  54. // @failure 400 {string} string "获取失败"
  55. // @Router /report/research_report_chapter [get]
  56. func GetResearchReportChapter(c *gin.Context) {
  57. userInfo := user.GetInfoByClaims(c)
  58. researchReportTypeIdStr := c.DefaultQuery("research_report_type_id", "")
  59. if researchReportTypeIdStr == "" {
  60. response.Fail("请传入报告章节id", c)
  61. return
  62. }
  63. researchReportId, tmpErr := strconv.Atoi(researchReportTypeIdStr)
  64. if tmpErr != nil {
  65. response.Fail("报告章节id异常", c)
  66. return
  67. }
  68. reportInfo, hasPermission, err := report.GetResearchReportTypeContentInfo(uint64(researchReportId), userInfo.UserID)
  69. if err != nil {
  70. response.Fail("获取报告章节失败", c)
  71. return
  72. }
  73. if !hasPermission {
  74. response.Fail("无权限", c)
  75. return
  76. }
  77. response.OkData("获取成功", reportInfo, c)
  78. }