|
|
@@ -21,6 +21,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -286,32 +289,46 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
|
|
|
@Override
|
|
|
public UploadZipDTO uploadZip(MultipartFile file) {
|
|
|
- // 获得文件名称
|
|
|
- String fileName = file.getOriginalFilename();
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ if (file == null || file.isEmpty() || originalFilename == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String fileName;
|
|
|
+ try {
|
|
|
+ fileName = Paths.get(originalFilename).getFileName().toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ fileName = originalFilename;
|
|
|
+ }
|
|
|
// 获得文件后缀名
|
|
|
String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
- String path = shpLocalFilePath + "/" + fileName;
|
|
|
- File dest = new File(path);
|
|
|
- // 获得上级目录
|
|
|
- File dir = dest.getParentFile();
|
|
|
- if (!dir.exists()) {
|
|
|
- dir.mkdirs();
|
|
|
+ if (!type.equals("zip") && !type.equals("rar")) {
|
|
|
+ return null;
|
|
|
}
|
|
|
+ Path shpBase = Paths.get(shpLocalFilePath);
|
|
|
+ if (!shpBase.isAbsolute()) {
|
|
|
+ Path root = Paths.get(localFilePath);
|
|
|
+ shpBase = root.isAbsolute() ? root.resolve(shpBase).normalize() : shpBase.toAbsolutePath().normalize();
|
|
|
+ } else {
|
|
|
+ shpBase = shpBase.normalize();
|
|
|
+ }
|
|
|
+
|
|
|
// 获取当前时间的时间戳
|
|
|
long timeMillis = System.currentTimeMillis();
|
|
|
- String unzippath = shpLocalFilePath + "/" + timeMillis;
|
|
|
+ Path destPath = shpBase.resolve(fileName).normalize();
|
|
|
+ Path unzipPath = shpBase.resolve(String.valueOf(timeMillis)).normalize();
|
|
|
try {
|
|
|
+ Files.createDirectories(destPath.getParent());
|
|
|
// 上传文件
|
|
|
- file.transferTo(dest);
|
|
|
+ file.transferTo(destPath.toFile());
|
|
|
if (type.equals("zip")) {
|
|
|
- new UnPackageUtils().unPackZip(dest, unzippath);
|
|
|
+ new UnPackageUtils().unPackZip(destPath.toFile(), unzipPath.toString());
|
|
|
} else if (type.equals("rar")) {
|
|
|
// 解压rar格式
|
|
|
- new UnPackageUtils().unPackRar(dest, unzippath);
|
|
|
+ new UnPackageUtils().unPackRar(destPath.toFile(), unzipPath.toString());
|
|
|
}
|
|
|
UploadZipDTO dto = new UploadZipDTO();
|
|
|
- dto.setPath(path);
|
|
|
- dto.setUnzippath(unzippath);
|
|
|
+ dto.setPath(destPath.toString());
|
|
|
+ dto.setUnzippath(unzipPath.toString());
|
|
|
dto.setUuid(StringUtils.getUUID());
|
|
|
return dto;
|
|
|
} catch (IOException e) {
|