diff --git a/fs-framework/fs-common-core/src/main/java/com/xddcodec/fs/framework/common/enums/FileTypeEnum.java b/fs-framework/fs-common-core/src/main/java/com/xddcodec/fs/framework/common/enums/FileTypeEnum.java index 3a022d66e0c013fdcca802eaf4f29467087e9a8a..94d888350e9ee0ca8d0314e08fd2ad4dafb3e343 100644 --- a/fs-framework/fs-common-core/src/main/java/com/xddcodec/fs/framework/common/enums/FileTypeEnum.java +++ b/fs-framework/fs-common-core/src/main/java/com/xddcodec/fs/framework/common/enums/FileTypeEnum.java @@ -222,6 +222,20 @@ public enum FileTypeEnum { .collect(Collectors.toList()); } + /** + * 获取除指定分类外的所有已知后缀 + */ + public static List getAllKnownSuffixesExcluding(FileCategory excludeCategory) { + return Stream.of(values()) + .filter(type -> type != OTHER + && type.getCategory() != excludeCategory + && type.getSuffixes() != null) + .flatMap(type -> type.getSuffixes().stream()) + .distinct() + .collect(Collectors.toList()); + } + + /** * 判断是否为其他类型 */ diff --git a/fs-modules/fs-file/src/main/java/com/xddcodec/fs/file/service/impl/FileInfoServiceImpl.java b/fs-modules/fs-file/src/main/java/com/xddcodec/fs/file/service/impl/FileInfoServiceImpl.java index 7aa2a393bf213e60ad386d8e0d5b84bcc779f6e2..f4b8632e17c62e5255813b7aea54809a76c71e42 100644 --- a/fs-modules/fs-file/src/main/java/com/xddcodec/fs/file/service/impl/FileInfoServiceImpl.java +++ b/fs-modules/fs-file/src/main/java/com/xddcodec/fs/file/service/impl/FileInfoServiceImpl.java @@ -627,17 +627,20 @@ public class FileInfoServiceImpl extends ServiceImpl i * 按分类筛选 */ private void applyFilterByCategory(QueryWrapper wrapper, FileTypeEnum.FileCategory category) { + List categorySuffixes = FileTypeEnum.getSuffixesByCategory(category); + if (category == FileTypeEnum.FileCategory.OTHER) { - // 其他类型:排除所有已知后缀 - List knownSuffixes = FileTypeEnum.getAllKnownSuffixes(); + // OTHER 分类:匹配 OTHER 分类的已知后缀 + 所有未知后缀 + List allOtherKnownSuffixes = FileTypeEnum.getAllKnownSuffixesExcluding(FileTypeEnum.FileCategory.OTHER); + wrapper.and(FILE_INFO.IS_DIR.eq(false)) .and( - FILE_INFO.SUFFIX.notIn(knownSuffixes) + FILE_INFO.SUFFIX.in(categorySuffixes) // zip、rar 等 + .or(FILE_INFO.SUFFIX.notIn(allOtherKnownSuffixes)) // 真正的未知类型 .or(FILE_INFO.SUFFIX.isNull().or(FILE_INFO.SUFFIX.eq(""))) ); } else { - // 常规分类:获取该分类下所有后缀 - List categorySuffixes = FileTypeEnum.getSuffixesByCategory(category); + // 常规分类:直接匹配后缀 if (!categorySuffixes.isEmpty()) { wrapper.and(FILE_INFO.IS_DIR.eq(false)) .and(FILE_INFO.SUFFIX.in(categorySuffixes)); @@ -645,6 +648,7 @@ public class FileInfoServiceImpl extends ServiceImpl i } } + /** * 按具体类型筛选 */