Commit ca1521a4 by 徐康

商品数量校验

parent 451a5627
......@@ -23,6 +23,7 @@ public class ServiceException extends RuntimeException {
public ServiceException(ResponseResult result, String message) {
this.result = result;
this.message = message;
this.result.setMessage(message);
}
public ResponseResult getResult() {
......
......@@ -1535,7 +1535,6 @@ public class ShoppingCartMCoffeeServiceImpl {
return isSpecialGoods;
}
public static void setClassificationAndPrice(CartGoods cartGoods, List<ProductBeanDTO> productBeanListSpuClass) {
if (productBeanListSpuClass == null || productBeanListSpuClass.size() == 0) {
return;
......@@ -1578,15 +1577,15 @@ public class ShoppingCartMCoffeeServiceImpl {
cartGoods.setTaxId(productBeanListSpuClass.get(0).getTaxId());
//套餐固定商品赋值
if (CollectionUtils.isNotEmpty(productBeanListSpuClass.get(0).getProductComboList())){
if (CollectionUtils.isNotEmpty(cartGoods.getProductComboList())){
for (CartGoods.ComboxGoods comboxGoods : cartGoods.getProductComboList()) {
for (ProductBeanDTO.ProductComboType comboType: productBeanListSpuClass.get(0).getProductComboList()){
if (comboxGoods.getGoodsId().equals(comboType.getProductId()) && comboType.getQuantity()>0){
comboxGoods.setQty(comboType.getQuantity());
}
}
}
if (CollectionUtils.isNotEmpty(productBeanListSpuClass.get(0).getProductComboList()) && CollectionUtils.isNotEmpty(cartGoods.getProductComboList())){
Map<String, Integer> productMap = productBeanListSpuClass.get(0).getProductComboList().stream()
.collect(Collectors.toMap(ProductBeanDTO.ProductComboType::getProductId, ProductBeanDTO.ProductComboType::getQuantity, (k1,k2) -> k1+k2));
Map<String, Integer> cartGoodsMap = cartGoods.getProductComboList().stream()
.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