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) .map(SmartCabinetDTO::new)
.collect(Collectors.toList()); .collect(Collectors.toList());
dtoList.forEach(dto -> dtoList.forEach(dto -> {
dto.setShopName( ShopEntity shopDo = shopEntities.stream()
shopEntities.stream()
.filter(shop -> shop.getShopId().equals(dto.getShopId())) .filter(shop -> shop.getShopId().equals(dto.getShopId()))
.findFirst() .findFirst().orElse(null);
.map(ShopEntity::getShopName) if (shopDo != null) {
.orElse("")) dto.setShopName(shopDo.getShopName());
); dto.setMode(shopDo.getMode());
}
});
return new PageDTO<>(dtoList, page.getTotal()); return new PageDTO<>(dtoList, page.getTotal());
} }
@ -72,14 +73,15 @@ public class SmartCabinetApplicationService {
.map(SmartCabinetDTO::new) .map(SmartCabinetDTO::new)
.collect(Collectors.toList()); .collect(Collectors.toList());
dtoList.forEach(dto -> dtoList.forEach(dto -> {
dto.setShopName( ShopEntity shopDo = shopEntities.stream()
shopEntities.stream()
.filter(shop -> shop.getShopId().equals(dto.getShopId())) .filter(shop -> shop.getShopId().equals(dto.getShopId()))
.findFirst() .findFirst().orElse(null);
.map(ShopEntity::getShopName) if (shopDo != null) {
.orElse("")) dto.setShopName(shopDo.getShopName());
); dto.setMode(shopDo.getMode());
}
});
return dtoList; return dtoList;
} }