From e1a26b0388372fd64f16a67a16f4c52673163c7c Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期五, 17 一月 2025 17:12:57 +0800 Subject: [PATCH] update 优化 缺少导包问题 --- ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java | 26 +++++++++++--------------- 1 files changed, 11 insertions(+), 15 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java index c901a2f..f745a99 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java @@ -2,7 +2,6 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.convert.Convert; -import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -37,7 +36,7 @@ import java.io.File; import java.io.IOException; -import java.io.InputStream; +import java.time.Duration; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -79,8 +78,9 @@ @Override public List<SysOssVo> listByIds(Collection<Long> ossIds) { List<SysOssVo> list = new ArrayList<>(); + SysOssServiceImpl ossService = SpringUtils.getAopProxy(this); for (Long id : ossIds) { - SysOssVo vo = SpringUtils.getAopProxy(this).getById(id); + SysOssVo vo = ossService.getById(id); if (ObjectUtil.isNotNull(vo)) { try { list.add(this.matchingUrl(vo)); @@ -102,8 +102,9 @@ @Override public String selectUrlByIds(String ossIds) { List<String> list = new ArrayList<>(); + SysOssServiceImpl ossService = SpringUtils.getAopProxy(this); for (Long id : StringUtils.splitTo(ossIds, Convert::toLong)) { - SysOssVo vo = SpringUtils.getAopProxy(this).getById(id); + SysOssVo vo = ossService.getById(id); if (ObjectUtil.isNotNull(vo)) { try { list.add(this.matchingUrl(vo).getUrl()); @@ -177,13 +178,8 @@ FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName()); response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8"); OssClient storage = OssFactory.instance(sysOss.getService()); - try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { - int available = inputStream.available(); - IoUtil.copy(inputStream, response.getOutputStream(), available); - response.setContentLength(available); - } catch (Exception e) { - throw new ServiceException(e.getMessage()); - } + long contentLength = storage.download(sysOss.getFileName(), response.getOutputStream()); + response.setContentLengthLong(contentLength); } /** @@ -200,7 +196,7 @@ OssClient storage = OssFactory.instance(); UploadResult uploadResult; try { - uploadResult = storage.uploadSuffix(file.getBytes(), suffix); + uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType()); } catch (IOException e) { throw new ServiceException(e.getMessage()); } @@ -249,12 +245,12 @@ if (isValid) { // 鍋氫竴浜涗笟鍔′笂鐨勬牎楠�,鍒ゆ柇鏄惁闇�瑕佹牎楠� } - List<SysOss> list = baseMapper.selectBatchIds(ids); + List<SysOss> list = baseMapper.selectByIds(ids); for (SysOss sysOss : list) { OssClient storage = OssFactory.instance(sysOss.getService()); storage.delete(sysOss.getUrl()); } - return baseMapper.deleteBatchIds(ids) > 0; + return baseMapper.deleteByIds(ids) > 0; } /** @@ -267,7 +263,7 @@ OssClient storage = OssFactory.instance(oss.getService()); // 浠呬慨鏀规《绫诲瀷涓� private 鐨刄RL锛屼复鏃禪RL鏃堕暱涓�120s if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) { - oss.setUrl(storage.getPrivateUrl(oss.getFileName(), 120)); + oss.setUrl(storage.getPrivateUrl(oss.getFileName(), Duration.ofSeconds(120))); } return oss; } -- Gitblit v1.9.3