|
|
@@ -1,14 +1,23 @@
|
|
|
package com.xjrsoft.module.system.service.impl;
|
|
|
|
|
|
+import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
+import com.xjrsoft.common.model.result.RT;
|
|
|
import com.xjrsoft.common.utils.FileZipUtil;
|
|
|
import com.xjrsoft.module.system.entity.File;
|
|
|
import com.xjrsoft.module.system.mapper.FileMapper;
|
|
|
import com.xjrsoft.module.system.service.IFileService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
+import org.springframework.core.io.ResourceLoader;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.FileInputStream;
|
|
|
+import java.io.*;
|
|
|
+import java.net.MalformedURLException;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -24,30 +33,38 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class FileServiceImpl extends MPJBaseServiceImpl<FileMapper, File> implements IFileService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ResourceLoader resourceLoader;
|
|
|
+
|
|
|
@Override
|
|
|
public boolean deleteFile(String encode) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean downloadFileByZip(Long folderId) {
|
|
|
+ public byte[] downloadFileByZip(Long folderId) {
|
|
|
List<File> fileList = this.list(Wrappers.<File>query().lambda().eq(File::getFolderId, folderId));
|
|
|
|
|
|
- //生命一个Map,将所有文件装进去,map的key是完整的文件名
|
|
|
+ //声明一个Map,将所有文件装进去,map的key是完整的文件名
|
|
|
Map<String, byte[]> byteAryMap = new HashMap<>();
|
|
|
|
|
|
-// for (int i = 0; i < fileList.size(); i++) {
|
|
|
-// java.io.File file = new java.io.File(fileList.get(i).getFileUrl());
|
|
|
-// byte[] bytes = FileZipUtil.byteArray(new FileInputStream(file), true);
|
|
|
-// byteAryMap.put(file.getName(), );
|
|
|
-// }
|
|
|
+ try {
|
|
|
+ for (int i = 0; i < fileList.size(); i++) {
|
|
|
+ URL url = new URL(fileList.get(i).getFileUrl());
|
|
|
+ URLConnection conn = url.openConnection();
|
|
|
+ InputStream in = conn.getInputStream();
|
|
|
+
|
|
|
+ byte[] bytes = FileZipUtil.byteArray(in, true);
|
|
|
+
|
|
|
+ byteAryMap.put(fileList.get(i).getFileName(), bytes);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
|
|
|
//执行下面这段代码就可以拿到压缩之后的byte数组
|
|
|
byte[] resultBtyeAry_temp = FileZipUtil.byteAryMap2Zip(byteAryMap);
|
|
|
|
|
|
-
|
|
|
- return true;
|
|
|
+ return resultBtyeAry_temp;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|