Commit ca1521a4 by 徐康

商品数量校验

parent 451a5627
...@@ -23,6 +23,7 @@ public class ServiceException extends RuntimeException { ...@@ -23,6 +23,7 @@ public class ServiceException extends RuntimeException {
public ServiceException(ResponseResult result, String message) { public ServiceException(ResponseResult result, String message) {
this.result = result; this.result = result;
this.message = message; this.message = message;
this.result.setMessage(message);
} }
public ResponseResult getResult() { public ResponseResult getResult() {
......
...@@ -1535,7 +1535,6 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1535,7 +1535,6 @@ public class ShoppingCartMCoffeeServiceImpl {
return isSpecialGoods; return isSpecialGoods;
} }
public static void setClassificationAndPrice(CartGoods cartGoods, List<ProductBeanDTO> productBeanListSpuClass) { public static void setClassificationAndPrice(CartGoods cartGoods, List<ProductBeanDTO> productBeanListSpuClass) {
if (productBeanListSpuClass == null || productBeanListSpuClass.size() == 0) { if (productBeanListSpuClass == null || productBeanListSpuClass.size() == 0) {
return; return;
...@@ -1578,15 +1577,15 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1578,15 +1577,15 @@ public class ShoppingCartMCoffeeServiceImpl {
cartGoods.setTaxId(productBeanListSpuClass.get(0).getTaxId()); cartGoods.setTaxId(productBeanListSpuClass.get(0).getTaxId());
//套餐固定商品赋值 //套餐固定商品赋值
if (CollectionUtils.isNotEmpty(productBeanListSpuClass.get(0).getProductComboList())){ if (CollectionUtils.isNotEmpty(productBeanListSpuClass.get(0).getProductComboList()) && CollectionUtils.isNotEmpty(cartGoods.getProductComboList())){
if (CollectionUtils.isNotEmpty(cartGoods.getProductComboList())){ Map<String, Integer> productMap = productBeanListSpuClass.get(0).getProductComboList().stream()
for (CartGoods.ComboxGoods comboxGoods : cartGoods.getProductComboList()) { .collect(Collectors.toMap(ProductBeanDTO.ProductComboType::getProductId, ProductBeanDTO.ProductComboType::getQuantity, (k1,k2) -> k1+k2));
for (ProductBeanDTO.ProductComboType comboType: productBeanListSpuClass.get(0).getProductComboList()){
if (comboxGoods.getGoodsId().equals(comboType.getProductId()) && comboType.getQuantity()>0){ Map<String, Integer> cartGoodsMap = cartGoods.getProductComboList().stream()
comboxGoods.setQty(comboType.getQuantity()); .collect(Collectors.toMap(CartGoods.ComboxGoods::getGoodsId, CartGoods.ComboxGoods::getQty, (k1, k2) -> k1+k2));
}
} if(productMap.entrySet().stream().filter(o -> o.getValue() != cartGoodsMap.get(o.getKey())).findFirst().isPresent()) {
} throw new ServiceException(ResponseResult.SHOPPING_CART_VERSION_ERROR, "加购套餐子商品数量异常");
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment