|
@@ -1,8 +1,12 @@
|
|
package org.dromara.system.service.impl;
|
|
package org.dromara.system.service.impl;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.IoUtil;
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
|
+import cn.hutool.core.net.URLEncodeUtil;
|
|
|
|
+import cn.hutool.core.util.CharsetUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import cn.hutool.core.util.ZipUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -133,6 +137,56 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ public void downloads(List<Long> ossId, HttpServletResponse response) throws IOException {
|
|
|
|
+
|
|
|
|
+ List<SysOssVo> mediaFileEntityList = new ArrayList<>();
|
|
|
|
+ for (Long id : ossId) {
|
|
|
|
+ SysOssVo vo = SpringUtils.getAopProxy(this).getById(id);
|
|
|
|
+ mediaFileEntityList.add(vo);
|
|
|
|
+ }
|
|
|
|
+// List<SysOssVo> mediaFileEntityList = SpringUtils.getAopProxy(this).listByIds(ossId);
|
|
|
|
+ if (mediaFileEntityList.size()<1) {
|
|
|
|
+ throw new ServiceException("文件数据不存在!");
|
|
|
|
+ }
|
|
|
|
+ int i = 0;
|
|
|
|
+ //如果有附件 进行zip处理
|
|
|
|
+ if (mediaFileEntityList != null && mediaFileEntityList.size() > 0) {
|
|
|
|
+ List<File> files = new ArrayList<>();
|
|
|
|
+ try {
|
|
|
|
+ //被压缩文件流集合
|
|
|
|
+ InputStream[] srcFiles = new InputStream[mediaFileEntityList.size()];
|
|
|
|
+ //被压缩文件名称
|
|
|
|
+ String[] srcFileNames = new String[mediaFileEntityList.size()];
|
|
|
|
+
|
|
|
|
+ for (SysOssVo entity : mediaFileEntityList) {
|
|
|
|
+ //以下代码为获取图片inputStream
|
|
|
|
+ OssClient storage = OssFactory.instance(entity.getService());
|
|
|
|
+ try(InputStream inputStream = storage.getObjectContent(entity.getUrl())) {
|
|
|
|
+ File temp= FileUtil.createTempFile();
|
|
|
|
+ int available = inputStream.available();
|
|
|
|
+ IoUtil.copy(inputStream, FileUtil.getOutputStream(temp), available);
|
|
|
|
+ files.add(temp);
|
|
|
|
+ srcFiles[i] = FileUtil.getInputStream(temp);
|
|
|
|
+ srcFileNames[i] = entity.getOriginalName();
|
|
|
|
+ i++;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new ServiceException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
|
+ FileUtils.setAttachmentResponseHeader(response, "下载.zip");
|
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
|
|
|
|
+ //多个文件压缩成压缩包返回
|
|
|
|
+ ZipUtil.zip(response.getOutputStream(), srcFileNames, srcFiles);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }finally {
|
|
|
|
+ files.stream().map(File::delete);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
public SysOssVo upload(MultipartFile file) {
|
|
public SysOssVo upload(MultipartFile file) {
|
|
String originalfileName = file.getOriginalFilename();
|
|
String originalfileName = file.getOriginalFilename();
|
|
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
|
|
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
|