a55a1469 刘嘉

菠萝派接口- 更改库存接口修改

1 个父辈 e9a791bb
......@@ -38,70 +38,45 @@ public class SyncStockBizServiceImpl extends AbstractBizService<PineappleSyncSto
params.put("productId",callRequest.getBizModel().getPlatProductID());
//先判断SKU在判断产品
IMProductBean iMProductBean = pineappleDao.getIMProductBeanByMap(params);
if(!StringUtil.isNull(iMProductBean)){
if(callRequest.getBizModel().getQuantity() < 0){
log.error(String.format("菠萝派商城appkey[%s]更新库存失败,库存必须大于或等于0,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,库存必须大于或等于0,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
}
if(!StringUtil.isNull(callRequest.getBizModel().getSkuID()) ) {
params.put("skuId",callRequest.getBizModel().getSkuID());
//查询该条SKUi
SkuBean skuBean = pineappleDao.getSkuBeanByMap(params);
if(StringUtil.isNull(skuBean)){
log.error(String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
}
//更新该条SKU
skuBean.setStockNum(callRequest.getBizModel().getQuantity());
if(pineappleDao.updateSku(skuBean) > 0){
//根据产品ID获取所有SKU总数
List<SkuApiResponse> skuBeanList = pineappleDao.getSkuBeanListByMap(callRequest.getBizModel().getPlatProductID());
if(!StringUtil.isNull(skuBeanList)){
log.error(String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU集合,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU集合,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
}
//更新SKU缓存
RedisProductSkuService.setProductSkuFromRedis(skuBeanList,callRequest.getBizModel().getSkuID());
Integer sumStock = skuBeanList.stream().map(s -> s.getStockNum()).reduce(0,(a,b) ->{
return a+b;
});
//更新产品
params.put("stockNum",sumStock);
if(pineappleDao.updateProduct(params) > 0){
//更新产品缓存
RedisProductStockService.setProductStock(iMProductBean.getImProductId(), sumStock);
//1、更新商品库存
IMProductInventory productInventory = new IMProductInventory();
productInventory.setImProductId(iMProductBean.getImProductId());
productInventory.setStockNum(sumStock);
if(pineappleDao.updateProductInventory(productInventory) > 0){
//更新缓存
pineappleSyncStockResponse.setQuantity(String.valueOf(callRequest.getBizModel().getQuantity()));
pineappleSyncStockResponse.setMessage(PineappleEnum.SUCCESS.getMsg());
pineappleSyncStockResponse.setCode(PineappleEnum.SUCCESS.getCode());
return pineappleSyncStockResponse;
}
}else{
log.error(String.format("菠萝派商城appkey[%s]更新库存失败,更新产品库存失败,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,更新产品库存失败,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
}
}
if(StringUtil.isNull(iMProductBean)){
log.error(String.format("菠萝派商城appkey[%s]更新库存失败,没有该商品",callRequest.getRequest().getAppkey()));
throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,没有该商品",callRequest.getRequest().getAppkey()));
}
if(callRequest.getBizModel().getQuantity() < 0){
log.error(String.format("菠萝派商城appkey[%s]更新库存失败,库存必须大于或等于0",callRequest.getRequest().getAppkey()));
throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,库存必须大于或等于0",callRequest.getRequest().getAppkey()));
}
if(!StringUtil.isNull(callRequest.getBizModel().getSkuID()) ) {
params.put("skuId",callRequest.getBizModel().getSkuID());
//查询该条SKUi
SkuBean skuBean = pineappleDao.getSkuBeanByMap(params);
if(StringUtil.isNull(skuBean)){
log.error(String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU",callRequest.getRequest().getAppkey()));
throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU",callRequest.getRequest().getAppkey()));
}
if(!StringUtil.isNull(callRequest.getBizModel().getPlatProductID())){
//更新该条SKU
skuBean.setStockNum(callRequest.getBizModel().getQuantity());
if(pineappleDao.updateSku(skuBean) > 0){
//根据产品ID获取所有SKU总数
List<SkuApiResponse> skuBeanList = pineappleDao.getSkuBeanListByMap(callRequest.getBizModel().getPlatProductID());
if(!StringUtil.isNull(skuBeanList) && !skuBeanList.isEmpty()){
log.error(String.format("菠萝派商城appkey[%s]更新库存失败,该产品有SKU,请指定SKUID,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,该产品有SKU,请指定SKUID,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
if(!StringUtil.isNull(skuBeanList)){
log.error(String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU集合",callRequest.getRequest().getAppkey()));
throw new BizException((String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU集合",callRequest.getRequest().getAppkey())));
}
params.put("stockNum",callRequest.getBizModel().getQuantity());
//更新SKU缓存
RedisProductSkuService.setProductSkuFromRedis(skuBeanList,callRequest.getBizModel().getSkuID());
Integer sumStock = skuBeanList.stream().map(s -> s.getStockNum()).reduce(0,(a,b) ->{
return a+b;
});
//更新产品
params.put("stockNum",sumStock);
if(pineappleDao.updateProduct(params) > 0){
//更新产品
RedisProductStockService.setProductStock(iMProductBean.getImProductId(), callRequest.getBizModel().getQuantity());
//更新产品缓存
RedisProductStockService.setProductStock(iMProductBean.getImProductId(), sumStock);
//1、更新商品库存
IMProductInventory productInventory = new IMProductInventory();
productInventory.setImProductId(iMProductBean.getImProductId());
productInventory.setStockNum(callRequest.getBizModel().getQuantity());
productInventory.setStockNum(sumStock);
if(pineappleDao.updateProductInventory(productInventory) > 0){
//更新缓存
pineappleSyncStockResponse.setQuantity(String.valueOf(callRequest.getBizModel().getQuantity()));
......@@ -109,11 +84,40 @@ public class SyncStockBizServiceImpl extends AbstractBizService<PineappleSyncSto
pineappleSyncStockResponse.setCode(PineappleEnum.SUCCESS.getCode());
return pineappleSyncStockResponse;
}
}else {
log.error(String.format("菠萝派商城appkey[%s]更新库存失败", callRequest.getRequest().getAppkey()));
throw new BizException((String.format("菠萝派商城appkey[%s]更新库存失败", callRequest.getRequest().getAppkey())));
}
}else{
log.error(String.format("菠萝派商城appkey[%s]更新sku库存失败", callRequest.getRequest().getAppkey()));
throw new BizException((String.format("菠萝派商城appkey[%s]更新sku库存失败", callRequest.getRequest().getAppkey())));
}
}
if(!StringUtil.isNull(callRequest.getBizModel().getPlatProductID())){
List<SkuApiResponse> skuBeanList = pineappleDao.getSkuBeanListByMap(callRequest.getBizModel().getPlatProductID());
if(!StringUtil.isNull(skuBeanList) && !skuBeanList.isEmpty()){
log.error(String.format("菠萝派商城appkey[%s]更新库存失败,该产品有SKU,请指定SKUID,method:%s,PlatProductID:%s,SkuID:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID()));
throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,该产品有SKU,请指定SKUID,method:%s,PlatProductID:%s,SkuID:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID()));
}
params.put("stockNum",callRequest.getBizModel().getQuantity());
if(pineappleDao.updateProduct(params) > 0){
//更新产品
RedisProductStockService.setProductStock(iMProductBean.getImProductId(), callRequest.getBizModel().getQuantity());
//1、更新商品库存
IMProductInventory productInventory = new IMProductInventory();
productInventory.setImProductId(iMProductBean.getImProductId());
productInventory.setStockNum(callRequest.getBizModel().getQuantity());
if(pineappleDao.updateProductInventory(productInventory) > 0){
//更新缓存
pineappleSyncStockResponse.setQuantity(String.valueOf(callRequest.getBizModel().getQuantity()));
pineappleSyncStockResponse.setMessage(PineappleEnum.SUCCESS.getMsg());
pineappleSyncStockResponse.setCode(PineappleEnum.SUCCESS.getCode());
return pineappleSyncStockResponse;
}
}
}
log.error(String.format("菠萝派商城appkey[%s]更新库存失败,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,method:%s,PlatProductID:%s,SkuID:s%,Quantity:%s",callRequest.getRequest().getAppkey(),callRequest.getRequest().getMethod(),callRequest.getBizModel().getPlatProductID(),callRequest.getBizModel().getSkuID(),callRequest.getBizModel().getQuantity()));
log.error(String.format("菠萝派商城appkey[%s]没有更改到库存", callRequest.getRequest().getAppkey()));
throw new BizException((String.format("菠萝派商城appkey[%s]没有更改到库存", callRequest.getRequest().getAppkey())));
}
@Override
......