|
|
@@ -16,15 +16,18 @@ import com.siwei.apply.utils.FileExtractUtil;
|
|
|
import com.siwei.apply.utils.ServiceFileUtil;
|
|
|
import com.siwei.apply.utils.ServiceUtil;
|
|
|
import com.siwei.common.core.exception.ServiceException;
|
|
|
+import org.apache.catalina.core.ApplicationContext;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
+import org.apache.poi.sl.usermodel.ObjectMetaData;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.nio.file.*;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -120,14 +123,6 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 处理文件并保存附件信息
|
|
|
* @param filePath 文件路径
|
|
|
@@ -135,7 +130,7 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public String processFileAndSave(String filePath) {
|
|
|
+ public String processFileAndSave(String filePath,String nodeTableName) {
|
|
|
try {
|
|
|
if (filePath == null || filePath.trim().isEmpty()) {
|
|
|
logger.warn("处理文件失败:filePath不能为空");
|
|
|
@@ -155,11 +150,18 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
|
|
|
// 解压文件到同名文件夹并获取目录结构
|
|
|
String extractDir = FileExtractUtil.extractToSameNameFolder(filePath);
|
|
|
if (extractDir != null) {
|
|
|
+ //todo 这里需要校验文件名称,如果不在枚举类中,需要删除整个目录,并且提示
|
|
|
+ if(!this.validUploadZipFile(extractDir,nodeTableName)){
|
|
|
+ //把当前解压的目录删除
|
|
|
+ ServiceFileUtil.deleteDirectory(extractDir);
|
|
|
+ throw new ServiceException("请按照固定目录名上传");
|
|
|
+ }
|
|
|
directoryStructure = FileExtractUtil.getDirectoryStructure(Paths.get(extractDir));
|
|
|
} else {
|
|
|
logger.error("解压文件失败: {}", filePath);
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
}else if(Files.isDirectory(file)) {
|
|
|
// 如果是目录直接获取目录信息
|
|
|
directoryStructure = FileExtractUtil.getDirectoryStructure(file);
|
|
|
@@ -562,6 +564,25 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public Boolean validUploadZipFile(String uploadFilePath,String tableName){
|
|
|
+ Map<String,List<String>> currentAttachmentMap = getCurrentAttachmentName(tableName);
|
|
|
+ List<String> currentAttachmentList = currentAttachmentMap.values().stream().findFirst().get();
|
|
|
+ boolean retFlag = true;
|
|
|
+ try {
|
|
|
+ List<String> directoryPathList = Files.list(Paths.get(uploadFilePath))
|
|
|
+ .filter(Files::isDirectory).map(s->s.getFileName().toString()).collect(Collectors.toList());
|
|
|
+ for(String currentAttachment : currentAttachmentList){
|
|
|
+ if(!CollectionUtils.containsAny(directoryPathList,currentAttachment)){
|
|
|
+ retFlag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return retFlag;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|