|
@@ -222,84 +222,82 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
|
|
|
@Override
|
|
|
public void checkProductStock(Long productId, Long productAttrValueId) {
|
|
|
IErpGoodsService goodsService = getErpService();
|
|
|
- if(goodsService == null){
|
|
|
- log.info("未找到erp服务");
|
|
|
- throw new CustomException("未找到erp服务");
|
|
|
- }
|
|
|
- log.info("检查库存 {} {}",productId,productAttrValueId);
|
|
|
- FsStoreProductAttrValueScrm productAttrValue=valueMapper.selectFsStoreProductAttrValueById(productAttrValueId);
|
|
|
- if(StringUtils.isEmpty(productAttrValue.getGroupBarCode())){
|
|
|
- //单品
|
|
|
- ErpGoodsStockQueryRequert queryRequert = new ErpGoodsStockQueryRequert();
|
|
|
- queryRequert.setBarcode(productAttrValue.getBarCode());
|
|
|
- ErpGoodsStockQueryResponse goodsStock = goodsService.getGoodsStock(queryRequert);
|
|
|
- if(goodsStock != null && goodsStock.getStocks() != null && !goodsStock.getStocks().isEmpty()){
|
|
|
-
|
|
|
- int stocks = Integer.valueOf(goodsStock.getStocks().get(0).getSalable_qty());
|
|
|
-
|
|
|
- if(stocks<=0){
|
|
|
- productAttrValue.setStock(0);
|
|
|
- valueMapper.updateFsStoreProductAttrValue(productAttrValue);
|
|
|
- fsStoreProductMapper.updateStock(productId);
|
|
|
- throw new CustomException("库存不足");
|
|
|
+ if(goodsService != null){
|
|
|
+ log.info("检查库存 {} {}",productId,productAttrValueId);
|
|
|
+ FsStoreProductAttrValueScrm productAttrValue=valueMapper.selectFsStoreProductAttrValueById(productAttrValueId);
|
|
|
+ if(StringUtils.isEmpty(productAttrValue.getGroupBarCode())){
|
|
|
+ //单品
|
|
|
+ ErpGoodsStockQueryRequert queryRequert = new ErpGoodsStockQueryRequert();
|
|
|
+ queryRequert.setBarcode(productAttrValue.getBarCode());
|
|
|
+ ErpGoodsStockQueryResponse goodsStock = goodsService.getGoodsStock(queryRequert);
|
|
|
+ if(goodsStock != null && goodsStock.getStocks() != null && !goodsStock.getStocks().isEmpty()){
|
|
|
+
|
|
|
+ int stocks = Integer.valueOf(goodsStock.getStocks().get(0).getSalable_qty());
|
|
|
+
|
|
|
+ if(stocks<=0){
|
|
|
+ productAttrValue.setStock(0);
|
|
|
+ valueMapper.updateFsStoreProductAttrValue(productAttrValue);
|
|
|
+ fsStoreProductMapper.updateStock(productId);
|
|
|
+ throw new CustomException("库存不足");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ //更新库存
|
|
|
+ productAttrValue.setStock(stocks);
|
|
|
+ valueMapper.updateFsStoreProductAttrValue(productAttrValue);
|
|
|
+ fsStoreProductMapper.updateStock(productId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
else{
|
|
|
- //更新库存
|
|
|
- productAttrValue.setStock(stocks);
|
|
|
- valueMapper.updateFsStoreProductAttrValue(productAttrValue);
|
|
|
- fsStoreProductMapper.updateStock(productId);
|
|
|
- return;
|
|
|
+ throw new CustomException("未获取到库存");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else{
|
|
|
- throw new CustomException("未获取到库存");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else{
|
|
|
- //组合码
|
|
|
- FsStoreProductGroupScrm group=productGroupMapper.selectFsStoreProductGroupByBarCode(productAttrValue.getGroupBarCode());
|
|
|
- if(group!=null){
|
|
|
- Integer totalStock=0;
|
|
|
- JSONArray jsonArray= JSONUtil.parseArray(group.getProducts());
|
|
|
- List<StoreProductGroupDTO> productGroupDTOS=JSONUtil.toList(jsonArray, StoreProductGroupDTO.class);
|
|
|
- if(productGroupDTOS!=null){
|
|
|
- for(StoreProductGroupDTO dto:productGroupDTOS){
|
|
|
- FsStoreProductAttrValueScrm attrValue=valueMapper.selectFsStoreProductAttrValueById(dto.getId());
|
|
|
- ErpGoodsStockQueryRequert queryRequert = new ErpGoodsStockQueryRequert();
|
|
|
- queryRequert.setBarcode(attrValue.getGroupBarCode());
|
|
|
- ErpGoodsStockQueryResponse goodsStock = goodsService.getGoodsStock(queryRequert);
|
|
|
- if(goodsStock != null && goodsStock.getStocks() != null && !goodsStock.getStocks().isEmpty()){
|
|
|
- int stocks = Integer.valueOf(goodsStock.getStocks().get(0).getSalable_qty());
|
|
|
-
|
|
|
-
|
|
|
- if(stocks<=0){
|
|
|
- attrValue.setStock(0);
|
|
|
- valueMapper.updateFsStoreProductAttrValue(attrValue);
|
|
|
- fsStoreProductMapper.updateStock(productId);
|
|
|
- throw new CustomException("库存不足");
|
|
|
+ //组合码
|
|
|
+ FsStoreProductGroupScrm group=productGroupMapper.selectFsStoreProductGroupByBarCode(productAttrValue.getGroupBarCode());
|
|
|
+ if(group!=null){
|
|
|
+ Integer totalStock=0;
|
|
|
+ JSONArray jsonArray= JSONUtil.parseArray(group.getProducts());
|
|
|
+ List<StoreProductGroupDTO> productGroupDTOS=JSONUtil.toList(jsonArray, StoreProductGroupDTO.class);
|
|
|
+ if(productGroupDTOS!=null){
|
|
|
+ for(StoreProductGroupDTO dto:productGroupDTOS){
|
|
|
+ FsStoreProductAttrValueScrm attrValue=valueMapper.selectFsStoreProductAttrValueById(dto.getId());
|
|
|
+ ErpGoodsStockQueryRequert queryRequert = new ErpGoodsStockQueryRequert();
|
|
|
+ queryRequert.setBarcode(attrValue.getGroupBarCode());
|
|
|
+ ErpGoodsStockQueryResponse goodsStock = goodsService.getGoodsStock(queryRequert);
|
|
|
+ if(goodsStock != null && goodsStock.getStocks() != null && !goodsStock.getStocks().isEmpty()){
|
|
|
+ int stocks = Integer.valueOf(goodsStock.getStocks().get(0).getSalable_qty());
|
|
|
+
|
|
|
+
|
|
|
+ if(stocks<=0){
|
|
|
+ attrValue.setStock(0);
|
|
|
+ valueMapper.updateFsStoreProductAttrValue(attrValue);
|
|
|
+ fsStoreProductMapper.updateStock(productId);
|
|
|
+ throw new CustomException("库存不足");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ //更新库存
|
|
|
+ attrValue.setStock(stocks);
|
|
|
+ valueMapper.updateFsStoreProductAttrValue(attrValue);
|
|
|
+ fsStoreProductMapper.updateStock(productId);
|
|
|
+ }
|
|
|
+ totalStock+=stocks;
|
|
|
}
|
|
|
- else{
|
|
|
- //更新库存
|
|
|
- attrValue.setStock(stocks);
|
|
|
- valueMapper.updateFsStoreProductAttrValue(attrValue);
|
|
|
- fsStoreProductMapper.updateStock(productId);
|
|
|
- }
|
|
|
- totalStock+=stocks;
|
|
|
}
|
|
|
}
|
|
|
+ productAttrValue.setStock(totalStock);
|
|
|
+ valueMapper.updateFsStoreProductAttrValue(productAttrValue);
|
|
|
+ fsStoreProductMapper.updateStock(productId);
|
|
|
}
|
|
|
- productAttrValue.setStock(totalStock);
|
|
|
- valueMapper.updateFsStoreProductAttrValue(productAttrValue);
|
|
|
- fsStoreProductMapper.updateStock(productId);
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int stock=valueMapper.selectFsStoreProductStockById(productAttrValueId);
|
|
|
+ if (stock < 1) {
|
|
|
+ throw new CustomException("库存不足");
|
|
|
}
|
|
|
-// int stock=valueMapper.selectFsStoreProductStockById(productAttrValueId);
|
|
|
-// if (stock < cartNum) {
|
|
|
-// throw new CustomException(product.getProductName() + "库存不足");
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
|