From 2d27b24029adafdbfc5703b38a519d65beda6a68 Mon Sep 17 00:00:00 2001 From: heheng <heheng@123456> Date: 星期三, 20 十一月 2024 16:23:23 +0800 Subject: [PATCH] 更改 --- expert-admin/src/main/java/com/gkhy/web/controller/common/CommonController.java | 42 +++++++++++++++++++++++++++--------------- 1 files changed, 27 insertions(+), 15 deletions(-) diff --git a/expert-admin/src/main/java/com/gkhy/web/controller/common/CommonController.java b/expert-admin/src/main/java/com/gkhy/web/controller/common/CommonController.java index d153648..be5d96a 100644 --- a/expert-admin/src/main/java/com/gkhy/web/controller/common/CommonController.java +++ b/expert-admin/src/main/java/com/gkhy/web/controller/common/CommonController.java @@ -1,9 +1,16 @@ package com.gkhy.web.controller.common; -import java.util.ArrayList; -import java.util.List; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import com.gkhy.common.annotation.Anonymous; +import com.gkhy.common.annotation.RepeatSubmit; +import com.gkhy.common.config.ExpertConfig; +import com.gkhy.common.constant.Constants; +import com.gkhy.common.core.domain.AjaxResult; +import com.gkhy.common.utils.StringUtils; +import com.gkhy.common.utils.file.FileUploadUtils; +import com.gkhy.common.utils.file.FileUtils; +import com.gkhy.framework.config.ServerConfig; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -13,13 +20,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import com.gkhy.common.config.expertConfig; -import com.gkhy.common.constant.Constants; -import com.gkhy.common.core.domain.AjaxResult; -import com.gkhy.common.utils.StringUtils; -import com.gkhy.common.utils.file.FileUploadUtils; -import com.gkhy.common.utils.file.FileUtils; -import com.gkhy.framework.config.ServerConfig; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.List; /** * 通用请求处理 @@ -28,6 +33,7 @@ */ @RestController @RequestMapping("/common") +@Api(tags = "附件上传下载") public class CommonController { private static final Logger log = LoggerFactory.getLogger(CommonController.class); @@ -44,6 +50,7 @@ * @param delete 是否删除 */ @GetMapping("/download") + @ApiOperation(value = "通用下载请求") public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { try @@ -53,7 +60,7 @@ throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName)); } String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); - String filePath = expertConfig.getDownloadPath() + fileName; + String filePath = ExpertConfig.getDownloadPath() + fileName; response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); FileUtils.setAttachmentResponseHeader(response, realFileName); @@ -73,12 +80,15 @@ * 通用上传请求(单个) */ @PostMapping("/upload") + @ApiOperation(value = "通用上传请求(单个)") + @Anonymous + @RepeatSubmit public AjaxResult uploadFile(MultipartFile file) throws Exception { try { // 上传文件路径 - String filePath = expertConfig.getUploadPath(); + String filePath = ExpertConfig.getUploadPath(); // 上传并返回新文件名称 String fileName = FileUploadUtils.upload(filePath, file); String url = serverConfig.getUrl() + fileName; @@ -99,12 +109,13 @@ * 通用上传请求(多个) */ @PostMapping("/uploads") + @ApiOperation(value = "通用上传请求(多个)") public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception { try { // 上传文件路径 - String filePath = expertConfig.getUploadPath(); + String filePath = ExpertConfig.getUploadPath(); List<String> urls = new ArrayList<String>(); List<String> fileNames = new ArrayList<String>(); List<String> newFileNames = new ArrayList<String>(); @@ -136,6 +147,7 @@ * 本地资源通用下载 */ @GetMapping("/download/resource") + @ApiOperation(value = "本地资源通用下载") public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response) throws Exception { @@ -146,7 +158,7 @@ throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource)); } // 本地资源路径 - String localPath = expertConfig.getProfile(); + String localPath = ExpertConfig.getProfile(); // 数据库资源地址 String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX); // 下载名称 -- Gitblit v1.9.2