Commit d53ae681 by xiaoer.li@freemud.com

Merge remote-tracking branch 'remotes/origin/feature/1.9.26_加车库存校验'

parents cd15f5a5 bc48dd81
......@@ -47,6 +47,12 @@ public class BizExceptionHandler {
return ResponseUtil.error(e.getResult());
}
@ExceptionHandler(BizServiceException.class)
@ResponseStatus(HttpStatus.OK)
public BaseResponse bindException(BizServiceException e) {
return ResponseUtil.error(e.getResult().getCode(), e.getMessage());
}
@ExceptionHandler(ParameterException.class)
@ResponseStatus(HttpStatus.OK)
public BaseResponse bindException(ParameterException e) {
......
package cn.freemud.interceptor;
import cn.freemud.enums.ResponseResult;
import com.freemud.application.sdk.api.exception.IgnoreErrorAnnotation;
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: cn.freemud.interceptor BizServiceException
* @Description: TDO 描述....
* @author: family
* @date: 2020/6/11
* @Copyright: www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
@SuppressWarnings("serial")
@IgnoreErrorAnnotation
public class BizServiceException extends RuntimeException {
private ResponseResult result;
private String message;
public BizServiceException(ResponseResult result) {
this.result = result;
this.message = result.getMessage();
}
public BizServiceException(ResponseResult result, String message) {
this.result = result;
this.message = message;
}
public ResponseResult getResult() {
return result;
}
public void setResult(ResponseResult result) {
this.result = result;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
......@@ -30,6 +30,7 @@ import cn.freemud.entities.dto.user.GetSessionUserInfoDto;
import cn.freemud.entities.vo.*;
import cn.freemud.enums.*;
import cn.freemud.interceptor.ServiceException;
import cn.freemud.interceptor.BizServiceException;
import cn.freemud.service.*;
import cn.freemud.service.thirdparty.*;
import cn.freemud.utils.PromotionFactory;
......@@ -247,8 +248,11 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
if (CollectionUtils.isEmpty(allCartGoodsList)) {
allCartGoodsList = new ArrayList<>();
}
/**
Integer checkQty = allCartGoodsList.indexOf(cartGoods) != -1 ?
allCartGoodsList.get(allCartGoodsList.indexOf(cartGoods)).getQty() + cartGoods.getQty() : cartGoods.getQty();
*/
Integer checkQty = this.checkSkuQty(allCartGoodsList, cartGoods);
//查询多个商品库存信息
queryManyGoodsStocks(addShoppingCartGoodsRequestVo, productIds, productBeanListSpuClass, skuId, checkQty);
......@@ -409,6 +413,10 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
GetProductStockResponseDto availableStocks = stockClient.getAvailableStocks(requestDto);
if ((availableStocks != null) && (ResponseCodeConstant.RESPONSE_SUCCESS_STR.equals(availableStocks.getCode()))) {
if ((CollectionUtils.isEmpty(availableStocks.getResult())) || (qty > availableStocks.getResult().get(0).getQty())) {
Integer stock = 0;
if ((stock = availableStocks.getResult().get(0).getQty()) > 0) {
throw new BizServiceException(ResponseResult.SHOPPING_CART_STOCK_NOT_HAVE, "仅剩" + stock + "件库存了");
}
throw new ServiceException(ResponseResult.SHOPPING_CART_STOCK_NOT_HAVE);
}
}
......@@ -1207,6 +1215,10 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
if (availableStocks != null && ResponseCodeConstant.RESPONSE_SUCCESS_STR.equals(availableStocks.getCode()) &&
(CollectionUtils.isEmpty(availableStocks.getResult()) || availableStocks.getResult().get(0).getQty() == null
|| availableStocks.getResult().get(0).getQty() < qty)) {
Integer stock = 0;
if ((stock = availableStocks.getResult().get(0).getQty()) > 0) {
throw new BizServiceException(ResponseResult.SHOPPING_CART_STOCK_NOT_HAVE, "仅剩" + stock + "件库存了");
}
throw new ServiceException(ResponseResult.SHOPPING_CART_STOCK_NOT_HAVE);
}
}
......@@ -1510,4 +1522,25 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
return sessionUserInfo.getResult();
}
/**
* 检查sku数量
*
* @param allCartGoodsList
* @param cartGoods
* @return
*/
private Integer checkSkuQty(List<CartGoods> allCartGoodsList, CartGoods cartGoods) {
Integer qty = 0;
if (CollectionUtils.isEmpty(allCartGoodsList)) {
qty = cartGoods.getQty();
} else {
qty = cartGoods.getQty();
for (CartGoods goods : allCartGoodsList) {
if (goods.getSkuId().equals(cartGoods.getSkuId()) && goods.getSpuId().equals(cartGoods.getSpuId())) {
qty += goods.getQty();
}
}
}
return qty;
}
}
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