You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.6 KiB

  1. package v1
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model"
  5. "gin-vue-admin/model/request"
  6. "gin-vue-admin/model/response"
  7. "gin-vue-admin/service"
  8. "github.com/gin-gonic/gin"
  9. "go.uber.org/zap"
  10. )
  11. // @Tags ExaFileUploadAndDownload
  12. // @Summary 上传文件示例
  13. // @Security ApiKeyAuth
  14. // @accept multipart/form-data
  15. // @Produce application/json
  16. // @Param file formData file true "上传文件示例"
  17. // @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}"
  18. // @Router /fileUploadAndDownload/upload [post]
  19. func UploadFile(c *gin.Context) {
  20. var file model.ExaFileUploadAndDownload
  21. noSave := c.DefaultQuery("noSave", "0")
  22. _, header, err := c.Request.FormFile("file")
  23. if err != nil {
  24. global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
  25. response.FailWithMessage("接收文件失败", c)
  26. return
  27. }
  28. err, file = service.UploadFile(header, noSave) // 文件上传后拿到文件路径
  29. if err != nil {
  30. global.GVA_LOG.Error("修改数据库链接失败!", zap.Any("err", err))
  31. response.FailWithMessage("修改数据库链接失败", c)
  32. return
  33. }
  34. response.OkWithDetailed(response.ExaFileResponse{File: file}, "上传成功", c)
  35. }
  36. // @Tags ExaFileUploadAndDownload
  37. // @Summary 删除文件
  38. // @Security ApiKeyAuth
  39. // @Produce application/json
  40. // @Param data body model.ExaFileUploadAndDownload true "传入文件里面id即可"
  41. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  42. // @Router /fileUploadAndDownload/deleteFile [post]
  43. func DeleteFile(c *gin.Context) {
  44. var file model.ExaFileUploadAndDownload
  45. _ = c.ShouldBindJSON(&file)
  46. if err := service.DeleteFile(file); err != nil {
  47. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  48. response.FailWithMessage("删除失败", c)
  49. return
  50. }
  51. response.OkWithMessage("删除成功", c)
  52. }
  53. // @Tags ExaFileUploadAndDownload
  54. // @Summary 分页文件列表
  55. // @Security ApiKeyAuth
  56. // @accept application/json
  57. // @Produce application/json
  58. // @Param data body request.PageInfo true "页码, 每页大小"
  59. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  60. // @Router /fileUploadAndDownload/getFileList [post]
  61. func GetFileList(c *gin.Context) {
  62. var pageInfo request.PageInfo
  63. _ = c.ShouldBindJSON(&pageInfo)
  64. err, list, total := service.GetFileRecordInfoList(pageInfo)
  65. if err != nil {
  66. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  67. response.FailWithMessage("获取失败", c)
  68. } else {
  69. response.OkWithDetailed(response.PageResult{
  70. List: list,
  71. Total: total,
  72. Page: pageInfo.Page,
  73. PageSize: pageInfo.PageSize,
  74. }, "获取成功", c)
  75. }
  76. }