From dfb86bd135f115e65aaacd3b41249c6100423f33 Mon Sep 17 00:00:00 2001 From: Freedom <459102951@qq.com> Date: Tue, 9 Dec 2025 10:31:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=AD=9B=E9=80=89=E5=85=B6=E4=BB=96=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fs/framework/common/enums/FileTypeEnum.java | 14 ++++++++++++++ .../fs/file/service/impl/FileInfoServiceImpl.java | 14 +++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) 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 3a022d66..94d88835 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 7aa2a393..f4b8632e 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 } } + /** * 按具体类型筛选 */ -- Gitee