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.

76 lines
2.4 KiB

  1. package v1
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global/response"
  5. "gin-vue-admin/model"
  6. "gin-vue-admin/model/request"
  7. resp "gin-vue-admin/model/response"
  8. "gin-vue-admin/service"
  9. "github.com/gin-gonic/gin"
  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. response.FailWithMessage(fmt.Sprintf("上传文件失败,%v", err), c)
  25. return
  26. }
  27. err, file = service.UploadFile(header, noSave) // 文件上传后拿到文件路径
  28. if err != nil {
  29. response.FailWithMessage(fmt.Sprintf("修改数据库链接失败,%v", err), c)
  30. return
  31. }
  32. response.OkDetailed(resp.ExaFileResponse{File: file}, "上传成功", c)
  33. }
  34. // @Tags ExaFileUploadAndDownload
  35. // @Summary 删除文件
  36. // @Security ApiKeyAuth
  37. // @Produce application/json
  38. // @Param data body model.ExaFileUploadAndDownload true "传入文件里面id即可"
  39. // @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
  40. // @Router /fileUploadAndDownload/deleteFile [post]
  41. func DeleteFile(c *gin.Context) {
  42. var file model.ExaFileUploadAndDownload
  43. _ = c.ShouldBindJSON(&file)
  44. if err := service.DeleteFile(file); err != nil {
  45. response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
  46. return
  47. }
  48. response.OkWithMessage("删除成功", c)
  49. }
  50. // @Tags ExaFileUploadAndDownload
  51. // @Summary 分页文件列表
  52. // @Security ApiKeyAuth
  53. // @accept application/json
  54. // @Produce application/json
  55. // @Param data body request.PageInfo true "分页获取文件户列表"
  56. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  57. // @Router /fileUploadAndDownload/getFileList [post]
  58. func GetFileList(c *gin.Context) {
  59. var pageInfo request.PageInfo
  60. _ = c.ShouldBindJSON(&pageInfo)
  61. err, list, total := service.GetFileRecordInfoList(pageInfo)
  62. if err != nil {
  63. response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
  64. } else {
  65. response.OkWithData(resp.PageResult{
  66. List: list,
  67. Total: total,
  68. Page: pageInfo.Page,
  69. PageSize: pageInfo.PageSize,
  70. }, c)
  71. }
  72. }