Explorar el Código

zip解压生成文件夹时,默认将上级的权限字段的值赋值给子集

WuYi hace 5 horas
padre
commit
82bd77053b

+ 9 - 0
ibps-comp-base-root/modules/comp-file-server-api/src/main/java/com/lc/ibps/file/server/model/FolderNodeInfo.java

@@ -4,6 +4,7 @@ public class FolderNodeInfo {
     private String id;
     private String path;
     private int depth;
+    private String authorityName;
 
     public String getId() {
         return id;
@@ -28,4 +29,12 @@ public class FolderNodeInfo {
     public void setDepth(int depth) {
         this.depth = depth;
     }
+
+    public String getAuthorityName() {
+        return authorityName;
+    }
+
+    public void setAuthorityName(String authorityName) {
+        this.authorityName = authorityName;
+    }
 }

+ 12 - 173
ibps-comp-root/modules/comp-file-server/src/main/java/com/lc/ibps/cloud/file/provider/DownloadProvider.java

@@ -204,6 +204,7 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 			rootFolder.setId(parentFolderId);
 			rootFolder.setPath(parentFolderId);
 			rootFolder.setDepth(0);
+			rootFolder.setAuthorityName("");
 		}
 
 		if (StringUtils.isBlank(rootFolder.getPath())) {
@@ -251,55 +252,7 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 		return stat;
 	}
 
-/*
-	private ZipImportStat importZipToDatabase(byte[] zipContent, String parentFolderId) throws IOException {
-		ZipImportStat stat = new ZipImportStat();
-
-		String parentPath = queryFolderPathById(parentFolderId);
-		if (StringUtils.isBlank(parentPath)) {
-			parentPath = "";
-		}
-
-		Map<String, String> folderIdCache = new HashMap<>();
-		folderIdCache.put("", parentFolderId);
 
-		try (ByteArrayInputStream bais = new ByteArrayInputStream(zipContent);
-			 ZipInputStream zipInputStream = new ZipInputStream(bais, Charset.forName("GBK"))) { //指定GBK编码格式
-			// ZipInputStream zipInputStream = new ZipInputStream(bais)) {
-			 ZipEntry entry;
-			while ((entry = zipInputStream.getNextEntry()) != null) {
-				try {
-					String entryName = normalizeZipEntryName(entry.getName());
-
-					if (StringUtils.isBlank(entryName) || isIgnoredZipEntry(entryName)) {
-						continue;
-					}
-
-					if (entry.isDirectory()) {
-						String folderPathInZip = trimTrailingSlash(entryName);
-						ensureFolderImported(folderPathInZip, parentFolderId, parentPath, folderIdCache, stat);
-						continue;
-					}
-
-					String parentPathInZip = getParentPathInZip(entryName);
-					String dbFolderId = ensureFolderImported(parentPathInZip, parentFolderId, parentPath, folderIdCache, stat);
-
-					String zipFileName = getFileNameFromZipPath(entryName);
-					if (StringUtils.isNotBlank(zipFileName)) {
-						byte[] fileBytes = readZipEntryBytes(zipInputStream);
-						Map<String, Object> fileMap = insertFile(dbFolderId, zipFileName, fileBytes);
-						stat.addFileMap(fileMap);
-						stat.increaseFileCount();
-					}
-				} finally {
-					zipInputStream.closeEntry();
-				}
-			}
-		}
-
-		logger.info("ZIP文件解析完成,新增文件夹数: {}, 新增文件数: {}", stat.getFolderCount(), stat.getFileCount());
-		return stat;
-	}*/
 
 	private FolderNodeInfo ensureFolderImported(
 			String folderPathInZip,
@@ -349,55 +302,13 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 		return folderCache.get(normalizedFolderPath);
 	}
 
-	/*
-	private String ensureFolderImported(String folderPathInZip,String rootParentFolderId,String rootParentPath,Map<String, String> folderIdCache,ZipImportStat stat) {
-
-		if (StringUtils.isBlank(folderPathInZip)) {
-			return rootParentFolderId;
-		}
-
-		String normalizedFolderPath = trimTrailingSlash(folderPathInZip);
-		if (folderIdCache.containsKey(normalizedFolderPath)) {
-			return folderIdCache.get(normalizedFolderPath);
-		}
-
-		String[] names = normalizedFolderPath.split("/");
-		String currentZipPath = "";
-		String currentParentId = rootParentFolderId;
-		String currentDbPath = rootParentPath;
-
-		for (String name : names) {
-			if (StringUtils.isBlank(name)) {
-				continue;
-			}
-
-			currentZipPath = StringUtils.isBlank(currentZipPath) ? name : currentZipPath + "/" + name;
-
-			if (folderIdCache.containsKey(currentZipPath)) {
-				currentParentId = folderIdCache.get(currentZipPath);
-				currentDbPath = buildDbPath(currentDbPath, name);
-				continue;
-			}
-			//转化windows读取路径时后缀的/
-			String newDbPath = buildDbPath(currentDbPath, name);
-
-			String newFolderId = insertFolder(name, currentParentId, currentDbPath);
 
-			folderIdCache.put(currentZipPath, newFolderId);
-			stat.increaseFolderCount();
-
-			currentParentId = newFolderId;
-			currentDbPath = newDbPath;
-		}
-
-		return folderIdCache.get(normalizedFolderPath);
-	}*/
 
 	private FolderNodeInfo insertFolder(String folderName, FolderNodeInfo parentFolder) {
 		String folderId = UniqueIdUtil.getId();
 		String folderPath = buildFolderIdPath(parentFolder.getPath(), parentFolder.getId(), folderId);
 		int depth = parentFolder.getDepth() + 1;
-
+		String authorityName = parentFolder.getAuthorityName();
 		Map<String, Object> map = build(
 				"ID_", folderId,
 				"CATEGORY_KEY_", FOLDER_CATEGORY_KEY,
@@ -407,6 +318,7 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 				"PARENT_ID_", parentFolder.getId(),
 				"DEPTH_", depth,
 				"PATH_", folderPath,
+				"AUTHORITY_NAME", authorityName,
 				"IS_LEAF_", "Y",
 				"OWNER_ID_", "0",
 				"TENANT_ID_", "-999",
@@ -416,10 +328,10 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 		);
 
 		String sql = "INSERT INTO " + FOLDER_TABLE + " ("
-				+ "ID_, CATEGORY_KEY_, NAME_, TYPE_KEY_, STRU_TYPE_, PARENT_ID_, DEPTH_, PATH_, "
+				+ "ID_, CATEGORY_KEY_, NAME_, TYPE_KEY_, STRU_TYPE_, PARENT_ID_, DEPTH_, PATH_,AUTHORITY_NAME, "
 				+ "IS_LEAF_, OWNER_ID_, TENANT_ID_, CREATE_BY_, CREATE_TIME_, UPDATE_TIME_"
 				+ ") VALUES ("
-				+ "#{ID_}, #{CATEGORY_KEY_}, #{NAME_}, #{TYPE_KEY_}, #{STRU_TYPE_}, #{PARENT_ID_}, #{DEPTH_}, #{PATH_}, "
+				+ "#{ID_}, #{CATEGORY_KEY_}, #{NAME_}, #{TYPE_KEY_}, #{STRU_TYPE_}, #{PARENT_ID_}, #{DEPTH_}, #{PATH_},#{AUTHORITY_NAME}, "
 				+ "#{IS_LEAF_}, #{OWNER_ID_}, #{TENANT_ID_}, #{CREATE_BY_}, #{CREATE_TIME_}, #{UPDATE_TIME_}"
 				+ ")";
 
@@ -435,14 +347,15 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 		node.setId(folderId);
 		node.setPath(folderPath);
 		node.setDepth(depth);
+		node.setAuthorityName(authorityName);
 
-		logger.info("插入文件夹: id={}, name={}, parentId={}, path={}, depth={}",
-				folderId, folderName, parentFolder.getId(), folderPath, depth);
+		logger.info("插入文件夹: id={}, name={}, parentId={}, path={}, depth={}, authorityName={}",
+				folderId, folderName, parentFolder.getId(), folderPath, depth, authorityName);
 		return node;
 	}
 
 	private FolderNodeInfo querySameLevelFolder(String parentId, String folderName) {
-		String sql = "SELECT ID_, PATH_, DEPTH_ FROM " + FOLDER_TABLE
+		String sql = "SELECT ID_, PATH_, DEPTH_, AUTHORITY_NAME FROM " + FOLDER_TABLE
 				+ " WHERE PARENT_ID_ = #{p0}"
 				+ " AND NAME_ = #{p1}"
 				+ " AND CATEGORY_KEY_ = #{p2}"
@@ -458,7 +371,7 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 	}
 
 	private FolderNodeInfo queryFolderNodeById(String folderId) {
-		String sql = "SELECT ID_, PATH_, DEPTH_ FROM " + FOLDER_TABLE + " WHERE ID_ = #{p0}";
+		String sql = "SELECT ID_, PATH_, DEPTH_, AUTHORITY_NAME FROM  FROM " + FOLDER_TABLE + " WHERE ID_ = #{p0}";
 		List<?> list = commonDao.query(sql, new Object[] { folderId });
 
 		if (list == null || list.isEmpty() || list.get(0) == null) {
@@ -485,24 +398,7 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 
 		commonDao.executeOfMap(sql, params);
 	}
-/*
-	private String buildFolderIdPath(String parentPath, String parentId, String currentId) {
-		String basePath = parentPath;
 
-		if (StringUtils.isBlank(basePath)) {
-			basePath = parentId;
-		}
-
-		if (StringUtils.isBlank(basePath)) {
-			return currentId;
-		}
-
-		if (basePath.endsWith("/")) {
-			return basePath + currentId;
-		}
-
-		return basePath + "/" + currentId;
-	}*/
 
 	private String buildFolderIdPath(String parentPath, String parentId, String currentId) {
 		String basePath = parentPath;
@@ -521,33 +417,7 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 
 		return basePath + currentId + ".";
 	}
-	/*
-	private String insertFolder(String folderName, String parentId, String folderPath) {
-		String folderId = UniqueIdUtil.getId(); //当前节点的id,需要拼接在path上,防止前段后续读取不到层级结构
-		String fileType = "FILE_TYPE"; //文件固定分类
-		//先加数据,后面再来考录path的问题
-		Map<String, Object> map = build("ID_", folderId,
-										"CATEGORY_KEY_", fileType,
-										"name_", folderName,
-										"type_key_", RandomStringUtils.randomAlphabetic(6),
-										"stru_type_", "1",
-										"PARENT_ID_", parentId,
-										"DEPTH_", 6,
-										"PATH_", "",
-										"IS_LEAF_", "Y",
-										"OWNER_ID_", "0",
-										"TENANT_ID_", "-999",
-										"CREATE_BY_", "1",
-										"CREATE_TIME_",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()),
-										"UPDATE_TIME_",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-		try {
-			commonDao.execute(this.buildInsertSql(map, "ibps_cat_type"));
-		}catch (Exception e){
-			logger.warn("添加文件夹数据失败:"+map);
-		}
-		logger.info("插入文件夹: id={}, name={}, parentId={}, path={}", folderId, folderName, parentId, folderPath);
-		return folderId;
-	}*/
+
 
 
 	private FolderNodeInfo toFolderNodeInfo(Object row) {
@@ -561,6 +431,7 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 		node.setId(toStringValue(getMapValue(rowMap, "ID_")));
 		node.setPath(toStringValue(getMapValue(rowMap, "PATH_")));
 		node.setDepth(toIntValue(getMapValue(rowMap, "DEPTH_")));
+		node.setAuthorityName(toStringValue(getMapValue(rowMap, "AUTHORITY_NAME")));
 
 		return StringUtils.isBlank(node.getId()) ? null : node;
 	}
@@ -693,28 +564,7 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 		result.put(KEY_WEN_JIAN_MING, parts[1].trim());
 		return result;
 	}
-/*
-	private String queryFolderPathById(String folderId) {
-		String sql = "SELECT path_ FROM " + FOLDER_TABLE + " WHERE id_ = #{p0}";
-		List<?> list = commonDao.query(sql, new Object[] { folderId });
-
-		if (list == null || list.isEmpty() || list.get(0) == null) {
-			return "";
-		}
 
-		Object row = list.get(0);
-		if (row instanceof Map) {
-			Map<?, ?> rowMap = (Map<?, ?>) row;
-			Object path = rowMap.get("path_");
-			if (path == null) {
-				path = rowMap.get("PATH_");
-			}
-			return path == null ? "" : String.valueOf(path);
-		}
-
-		return String.valueOf(row);
-	}
-*/
 
 	private String normalizeZipEntryName(String entryName) {
 		if (StringUtils.isBlank(entryName)) {
@@ -775,18 +625,7 @@ public class DownloadProvider extends GenericUploadProvider implements IDownload
 		return entryName.substring(index + 1);
 	}
 
-	/*
-	private String buildDbPath(String parentPath, String name) {
-		if (StringUtils.isBlank(parentPath)) {
-			return "/" + name;
-		}
-
-		if (parentPath.endsWith("/")) {
-			return parentPath + name;
-		}
 
-		return parentPath + "/" + name;
-	}*/
 
 	public Map<String,Object> build(Object... keyValues){
 		Map<String, Object> map = new HashMap<>();