From 4a9e6d8d1c5bf0efefe39b9cba02e0c7b8960b36 Mon Sep 17 00:00:00 2001 From: dzq Date: Wed, 25 Jun 2025 09:57:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor(domain):=20=E4=BC=98=E5=8C=96=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E6=9F=9C=E5=BA=94=E7=94=A8=E6=9C=8D=E5=8A=A1=E4=B8=AD?= =?UTF-8?q?=E5=BA=97=E9=93=BA=E4=BF=A1=E6=81=AF=E8=AE=BE=E7=BD=AE=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将流式操作中的直接映射改为先获取店铺对象再设置属性,避免重复查找并增加mode字段的设置 --- .../SmartCabinetApplicationService.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/smartCabinet/SmartCabinetApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/smartCabinet/SmartCabinetApplicationService.java index 13cb7a7..5d37045 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/smartCabinet/SmartCabinetApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/smartCabinet/SmartCabinetApplicationService.java @@ -54,14 +54,15 @@ public class SmartCabinetApplicationService { .map(SmartCabinetDTO::new) .collect(Collectors.toList()); - dtoList.forEach(dto -> - dto.setShopName( - shopEntities.stream() - .filter(shop -> shop.getShopId().equals(dto.getShopId())) - .findFirst() - .map(ShopEntity::getShopName) - .orElse("")) - ); + dtoList.forEach(dto -> { + ShopEntity shopDo = shopEntities.stream() + .filter(shop -> shop.getShopId().equals(dto.getShopId())) + .findFirst().orElse(null); + if (shopDo != null) { + dto.setShopName(shopDo.getShopName()); + dto.setMode(shopDo.getMode()); + } + }); return new PageDTO<>(dtoList, page.getTotal()); } @@ -72,14 +73,15 @@ public class SmartCabinetApplicationService { .map(SmartCabinetDTO::new) .collect(Collectors.toList()); - dtoList.forEach(dto -> - dto.setShopName( - shopEntities.stream() - .filter(shop -> shop.getShopId().equals(dto.getShopId())) - .findFirst() - .map(ShopEntity::getShopName) - .orElse("")) - ); + dtoList.forEach(dto -> { + ShopEntity shopDo = shopEntities.stream() + .filter(shop -> shop.getShopId().equals(dto.getShopId())) + .findFirst().orElse(null); + if (shopDo != null) { + dto.setShopName(shopDo.getShopName()); + dto.setMode(shopDo.getMode()); + } + }); return dtoList; }