From 8f4866cc466d0f5f8b413a1d7fd19a166b408130 Mon Sep 17 00:00:00 2001 From: weizhiqiang <598748873@qq.com> Date: Tue, 17 Sep 2024 10:23:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ShopTradeCartServiceImpl.java | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/store/service/impl/ShopTradeCartServiceImpl.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/store/service/impl/ShopTradeCartServiceImpl.java index a9ce313f..11fae8ad 100644 --- a/skyeye-shop/shop-store/src/main/java/com/skyeye/store/service/impl/ShopTradeCartServiceImpl.java +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/store/service/impl/ShopTradeCartServiceImpl.java @@ -144,26 +144,23 @@ public class ShopTradeCartServiceImpl extends SkyeyeBusinessServiceImpl result = new HashMap<>(); final String[] allPrice = {"0"}; - if (CollectionUtil.isEmpty(beans)) { - result.put("allPrice", Joiner.on(CommonCharConstants.COMMA_MARK).join(allPrice)); - outputObject.setBean(result); - outputObject.settotal(CommonNumConstants.NUM_ONE); - return; + if (CollectionUtil.isNotEmpty(beans)) { + Map countMap = beans.stream().collect(Collectors + .toMap(ShopTradeCart::getNormsId, shopTradeCart -> shopTradeCart.getCount().toString())); + // 收集规格id列表,获得规格信息 + List normsIdList = beans.stream().map(ShopTradeCart::getNormsId).collect(Collectors.toList()); + List> normsListMap = iShopMaterialNormsService + .queryShopMaterialByNormsIdList(Joiner.on(CommonCharConstants.COMMA_MARK).join(normsIdList)); + // 计算价格 + normsListMap.forEach(map -> { + String id = map.get("normsId").toString(); + String count = countMap.get(id); + String salePrice = map.get("salePrice").toString(); + String flagPrice = CalculationUtil.multiply(count, salePrice, CommonNumConstants.NUM_TWO); + allPrice[0] = CalculationUtil.add(allPrice[0], flagPrice); + }); } - Map countMap = beans.stream().collect(Collectors - .toMap(ShopTradeCart::getNormsId, shopTradeCart -> shopTradeCart.getCount().toString())); - // 收集规格id列表,获得规格信息 - List normsIdList = beans.stream().map(ShopTradeCart::getNormsId).collect(Collectors.toList()); - List> normsListMap = iShopMaterialNormsService - .queryShopMaterialByNormsIdList(Joiner.on(CommonCharConstants.COMMA_MARK).join(normsIdList)); - // 计算价格 - normsListMap.forEach(map -> { - String id = map.get("normsId").toString(); - String count = countMap.get(id); - String salePrice = map.get("salePrice").toString(); - String flagPrice = CalculationUtil.multiply(count, salePrice, CommonNumConstants.NUM_TWO); - allPrice[0] = CalculationUtil.add(allPrice[0], flagPrice); - }); + result.put("allPrice", Joiner.on(CommonCharConstants.COMMA_MARK).join(allPrice)); outputObject.setBean(result); outputObject.settotal(CommonNumConstants.NUM_ONE);