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);