From 24baf7751658b23e9952a31851d95e2fe6db181d Mon Sep 17 00:00:00 2001 From: Sol Date: Fri, 13 Jun 2025 11:34:59 +0800 Subject: [PATCH] fix(common-base-web): Optimize the null value processing of the findIds method --- .../bgasol/common/core/base/service/BaseService.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cloud/common/common-base-web/src/main/java/com/bgasol/common/core/base/service/BaseService.java b/cloud/common/common-base-web/src/main/java/com/bgasol/common/core/base/service/BaseService.java index cedae6c..a661ec6 100644 --- a/cloud/common/common-base-web/src/main/java/com/bgasol/common/core/base/service/BaseService.java +++ b/cloud/common/common-base-web/src/main/java/com/bgasol/common/core/base/service/BaseService.java @@ -263,6 +263,9 @@ public abstract class BaseService findIds(String... ids) { // 优先从缓存查询结果 if (ObjectUtils.isEmpty(commonBaseRedissonClient())) { + if (ObjectUtils.isEmpty(ids)) { + return new ArrayList<>(); + } return commonBaseMapper().selectByIds(Arrays.asList(ids)); } @@ -272,8 +275,12 @@ public abstract class BaseService noneCacheIds = Arrays.stream(ids).filter(id -> !cacheList.containsKey(id)).toList(); - List entities = commonBaseMapper().selectByIds(noneCacheIds); - + List entities; + if (ObjectUtils.isEmpty(noneCacheIds)) { + entities = new ArrayList<>(); + } else { + entities = commonBaseMapper().selectByIds(noneCacheIds); + } // 准备缓存的新数据 数据库中也没有查到的数据制作为NULL_PLACEHOLDER实体 Map toCacheDate = noneCacheIds.stream().collect(Collectors.toMap(id -> id, id -> entities.stream().filter(entity -> entity.getId().equals(id)).findFirst().orElse( @@ -282,7 +289,6 @@ public abstract class BaseService result = new ArrayList<>(cacheList.values().stream().filter(entity -> !entity.getId().equals(NULL_PLACEHOLDER)).toList()); result.addAll(entities);