refactor(domain): 优化智能柜应用服务中店铺信息设置逻辑

将流式操作中的直接映射改为先获取店铺对象再设置属性,避免重复查找并增加mode字段的设置
This commit is contained in:
dzq 2025-06-25 09:57:14 +08:00
parent b1328b35ec
commit 4a9e6d8d1c
1 changed files with 18 additions and 16 deletions

View File

@ -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;
}