From 0fc796b90d3f44b81ef30285edb897223df439f7 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期五, 13 一月 2023 23:04:09 +0800 Subject: [PATCH] update 适配 javax.servlet 替换为 jakarta.servlet 更新所有代码 update 适配 ServletUtils 更换继承 JakartaServletUtil --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java | 62 ++++++++++++------------------- 1 files changed, 24 insertions(+), 38 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java index e40c2f5..f5df421 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java @@ -15,22 +15,20 @@ import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.file.FileUtils; +import com.ruoyi.oss.core.OssClient; +import com.ruoyi.oss.factory.OssFactory; import com.ruoyi.system.domain.SysOss; import com.ruoyi.system.domain.bo.SysOssBo; import com.ruoyi.system.domain.vo.SysOssVo; import com.ruoyi.system.service.ISysOssService; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Parameters; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletResponse; -import javax.validation.constraints.NotEmpty; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.NotEmpty; import java.io.IOException; import java.util.Arrays; import java.util.HashMap; @@ -43,7 +41,6 @@ * @author Lion Li */ @Validated -@Tag(name ="瀵硅薄瀛樺偍鎺у埗鍣�", description = "瀵硅薄瀛樺偍绠$悊") @RequiredArgsConstructor @RestController @RequestMapping("/system/oss") @@ -62,30 +59,30 @@ /** * 鏌ヨOSS瀵硅薄鍩轰簬id涓� + * + * @param ossIds OSS瀵硅薄ID涓� */ @SaCheckPermission("system:oss:list") @GetMapping("/listByIds/{ossIds}") - public R<List<SysOssVo>> listByIds(@Parameter(name = "OSS瀵硅薄ID涓�") - @NotEmpty(message = "涓婚敭涓嶈兘涓虹┖") - @PathVariable Long[] ossIds) { + public R<List<SysOssVo>> listByIds(@NotEmpty(message = "涓婚敭涓嶈兘涓虹┖") + @PathVariable Long[] ossIds) { List<SysOssVo> list = iSysOssService.listByIds(Arrays.asList(ossIds)); return R.ok(list); } /** * 涓婁紶OSS瀵硅薄瀛樺偍 + * + * @param file 鏂囦欢 */ - @Parameters({ - @Parameter(name = "file", description = "鏂囦欢", in = ParameterIn.QUERY, required = true) - }) @SaCheckPermission("system:oss:upload") @Log(title = "OSS瀵硅薄瀛樺偍", businessType = BusinessType.INSERT) - @PostMapping("/upload") + @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public R<Map<String, String>> upload(@RequestPart("file") MultipartFile file) { if (ObjectUtil.isNull(file)) { throw new ServiceException("涓婁紶鏂囦欢涓嶈兘涓虹┖"); } - SysOss oss = iSysOssService.upload(file); + SysOssVo oss = iSysOssService.upload(file); Map<String, String> map = new HashMap<>(2); map.put("url", oss.getUrl()); map.put("fileName", oss.getOriginalName()); @@ -93,39 +90,28 @@ return R.ok(map); } + /** + * 涓嬭浇OSS瀵硅薄 + * + * @param ossId OSS瀵硅薄ID + */ @SaCheckPermission("system:oss:download") @GetMapping("/download/{ossId}") - public void download(@Parameter(name = "OSS瀵硅薄ID") @PathVariable Long ossId, HttpServletResponse response) throws IOException { - SysOss sysOss = iSysOssService.getById(ossId); - if (ObjectUtil.isNull(sysOss)) { - throw new ServiceException("鏂囦欢鏁版嵁涓嶅瓨鍦�!"); - } - response.reset(); - FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName()); - response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8"); - long data; - try { - data = HttpUtil.download(sysOss.getUrl(), response.getOutputStream(), false); - } catch (HttpException e) { - if (e.getMessage().contains("403")) { - throw new ServiceException("鏃犺鍙栨潈闄�, 璇峰湪瀵瑰簲鐨凮SS寮�鍚�'鍏湁璇�'鏉冮檺!"); - } else { - throw new ServiceException(e.getMessage()); - } - } - response.setContentLength(Convert.toInt(data)); + public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException { + iSysOssService.download(ossId,response); } /** * 鍒犻櫎OSS瀵硅薄瀛樺偍 + * + * @param ossIds OSS瀵硅薄ID涓� */ @SaCheckPermission("system:oss:remove") @Log(title = "OSS瀵硅薄瀛樺偍", businessType = BusinessType.DELETE) @DeleteMapping("/{ossIds}") - public R<Void> remove(@Parameter(name = "OSS瀵硅薄ID涓�") - @NotEmpty(message = "涓婚敭涓嶈兘涓虹┖") - @PathVariable Long[] ossIds) { - return toAjax(iSysOssService.deleteWithValidByIds(Arrays.asList(ossIds), true) ? 1 : 0); + public R<Void> remove(@NotEmpty(message = "涓婚敭涓嶈兘涓虹┖") + @PathVariable Long[] ossIds) { + return toAjax(iSysOssService.deleteWithValidByIds(Arrays.asList(ossIds), true)); } } -- Gitblit v1.9.3