feat: 文件夹层级限制

This commit is contained in:
2023-11-08 16:00:56 +08:00
parent 18bd843e92
commit 5986f5a65f
@@ -1430,17 +1430,17 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
// 解压缩 // 解压缩
String zipEntryName = FileUnZip.unZipFiles(path + File.separator + file.getOriginalFilename(), String.valueOf(path)); String zipEntryName = FileUnZip.unZipFiles(path + File.separator + file.getOriginalFilename(), String.valueOf(path));
// 需求变更 不做判断
//判断压缩包下是否只有一个文件夹 //判断压缩包下是否只有一个文件夹
File fileTemp = new File(path.toUri()); // File fileTemp = new File(path.toUri());
int length = fileTemp.listFiles().length; // int length = fileTemp.listFiles().length;
if (length > 2) { // if (length > 2) {
FileUnZip.deleteDir(saveDirectory); // FileUnZip.deleteDir(saveDirectory);
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.FOLDER_ONLY_ONE)); // throw new JeroBootException(MessageUtils.getMessage(ResultCommon.FOLDER_ONLY_ONE));
} // }
List<File> fileList = new ArrayList<>(); List<File> fileList = new ArrayList<>();
File fileNew = new File(zipEntryName); for (File file1 : Objects.requireNonNull(saveDirectory.listFiles())) {
for (File file1 : Objects.requireNonNull(fileNew.listFiles())) {
if (file1.getName().contains(".xls") || file1.getName().contains(".xlsx")) { if (file1.getName().contains(".xls") || file1.getName().contains(".xlsx")) {
fileList.add(file1); fileList.add(file1);
} }
@@ -1452,7 +1452,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
FileUnZip.deleteDir(saveDirectory); FileUnZip.deleteDir(saveDirectory);
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.IMPORT_TEMPLATE_ERROR)); throw new JeroBootException(MessageUtils.getMessage(ResultCommon.IMPORT_TEMPLATE_ERROR));
} }
List<File> excelfilelist = FileUnZip.readImpExcelFile(fileNew.getPath()); List<File> excelfilelist = FileUnZip.readImpExcelFile(saveDirectory.getPath());
System.gc(); System.gc();
if (excelfilelist.size() != 1) { if (excelfilelist.size() != 1) {
FileUnZip.deleteDir(saveDirectory); FileUnZip.deleteDir(saveDirectory);
@@ -1483,7 +1483,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
// 数据内容格式校验 // 数据内容格式校验
Map<String, File> fileMap = new HashMap<>(); Map<String, File> fileMap = new HashMap<>();
// 遍历saveDirectory下的所有文件 // 遍历saveDirectory下的所有文件
populateFileMap(fileNew, fileNew, fileMap); populateFileMap(saveDirectory, saveDirectory, fileMap);
try (Workbook workbook = new XSSFWorkbook(Files.newInputStream(excelfilelist.get(0).toPath()))) { try (Workbook workbook = new XSSFWorkbook(Files.newInputStream(excelfilelist.get(0).toPath()))) {
// 检测是否是空Excel // 检测是否是空Excel