a55a1469 刘嘉

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

1 个父辈 e9a791bb
...@@ -38,70 +38,45 @@ public class SyncStockBizServiceImpl extends AbstractBizService<PineappleSyncSto ...@@ -38,70 +38,45 @@ public class SyncStockBizServiceImpl extends AbstractBizService<PineappleSyncSto
38 params.put("productId",callRequest.getBizModel().getPlatProductID()); 38 params.put("productId",callRequest.getBizModel().getPlatProductID());
39 //先判断SKU在判断产品 39 //先判断SKU在判断产品
40 IMProductBean iMProductBean = pineappleDao.getIMProductBeanByMap(params); 40 IMProductBean iMProductBean = pineappleDao.getIMProductBeanByMap(params);
41 if(!StringUtil.isNull(iMProductBean)){ 41 if(StringUtil.isNull(iMProductBean)){
42 if(callRequest.getBizModel().getQuantity() < 0){ 42 log.error(String.format("菠萝派商城appkey[%s]更新库存失败,没有该商品",callRequest.getRequest().getAppkey()));
43 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())); 43 throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,没有该商品",callRequest.getRequest().getAppkey()));
44 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())); 44 }
45 45 if(callRequest.getBizModel().getQuantity() < 0){
46 } 46 log.error(String.format("菠萝派商城appkey[%s]更新库存失败,库存必须大于或等于0",callRequest.getRequest().getAppkey()));
47 if(!StringUtil.isNull(callRequest.getBizModel().getSkuID()) ) { 47 throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,库存必须大于或等于0",callRequest.getRequest().getAppkey()));
48 params.put("skuId",callRequest.getBizModel().getSkuID()); 48 }
49 //查询该条SKUi 49 if(!StringUtil.isNull(callRequest.getBizModel().getSkuID()) ) {
50 SkuBean skuBean = pineappleDao.getSkuBeanByMap(params); 50 params.put("skuId",callRequest.getBizModel().getSkuID());
51 if(StringUtil.isNull(skuBean)){ 51 //查询该条SKUi
52 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())); 52 SkuBean skuBean = pineappleDao.getSkuBeanByMap(params);
53 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())); 53 if(StringUtil.isNull(skuBean)){
54 } 54 log.error(String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU",callRequest.getRequest().getAppkey()));
55 //更新该条SKU 55 throw new BizException(String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU",callRequest.getRequest().getAppkey()));
56 skuBean.setStockNum(callRequest.getBizModel().getQuantity());
57 if(pineappleDao.updateSku(skuBean) > 0){
58 //根据产品ID获取所有SKU总数
59 List<SkuApiResponse> skuBeanList = pineappleDao.getSkuBeanListByMap(callRequest.getBizModel().getPlatProductID());
60 if(!StringUtil.isNull(skuBeanList)){
61 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()));
62 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()));
63 }
64 //更新SKU缓存
65 RedisProductSkuService.setProductSkuFromRedis(skuBeanList,callRequest.getBizModel().getSkuID());
66 Integer sumStock = skuBeanList.stream().map(s -> s.getStockNum()).reduce(0,(a,b) ->{
67 return a+b;
68 });
69 //更新产品
70 params.put("stockNum",sumStock);
71 if(pineappleDao.updateProduct(params) > 0){
72 //更新产品缓存
73 RedisProductStockService.setProductStock(iMProductBean.getImProductId(), sumStock);
74 //1、更新商品库存
75 IMProductInventory productInventory = new IMProductInventory();
76 productInventory.setImProductId(iMProductBean.getImProductId());
77 productInventory.setStockNum(sumStock);
78 if(pineappleDao.updateProductInventory(productInventory) > 0){
79 //更新缓存
80 pineappleSyncStockResponse.setQuantity(String.valueOf(callRequest.getBizModel().getQuantity()));
81 pineappleSyncStockResponse.setMessage(PineappleEnum.SUCCESS.getMsg());
82 pineappleSyncStockResponse.setCode(PineappleEnum.SUCCESS.getCode());
83 return pineappleSyncStockResponse;
84 }
85 }else{
86 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()));
87 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()));
88 }
89 }
90 } 56 }
91 if(!StringUtil.isNull(callRequest.getBizModel().getPlatProductID())){ 57 //更新该条SKU
58 skuBean.setStockNum(callRequest.getBizModel().getQuantity());
59 if(pineappleDao.updateSku(skuBean) > 0){
60 //根据产品ID获取所有SKU总数
92 List<SkuApiResponse> skuBeanList = pineappleDao.getSkuBeanListByMap(callRequest.getBizModel().getPlatProductID()); 61 List<SkuApiResponse> skuBeanList = pineappleDao.getSkuBeanListByMap(callRequest.getBizModel().getPlatProductID());
93 if(!StringUtil.isNull(skuBeanList) && !skuBeanList.isEmpty()){ 62 if(!StringUtil.isNull(skuBeanList)){
94 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())); 63 log.error(String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU集合",callRequest.getRequest().getAppkey()));
95 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())); 64 throw new BizException((String.format("菠萝派商城appkey[%s]更新库存失败,查询不到该SKU集合",callRequest.getRequest().getAppkey())));
96 } 65 }
97 params.put("stockNum",callRequest.getBizModel().getQuantity()); 66 //更新SKU缓存
67 RedisProductSkuService.setProductSkuFromRedis(skuBeanList,callRequest.getBizModel().getSkuID());
68 Integer sumStock = skuBeanList.stream().map(s -> s.getStockNum()).reduce(0,(a,b) ->{
69 return a+b;
70 });
71 //更新产品
72 params.put("stockNum",sumStock);
98 if(pineappleDao.updateProduct(params) > 0){ 73 if(pineappleDao.updateProduct(params) > 0){
99 //更新产品 74 //更新产品缓存
100 RedisProductStockService.setProductStock(iMProductBean.getImProductId(), callRequest.getBizModel().getQuantity()); 75 RedisProductStockService.setProductStock(iMProductBean.getImProductId(), sumStock);
101 //1、更新商品库存 76 //1、更新商品库存
102 IMProductInventory productInventory = new IMProductInventory(); 77 IMProductInventory productInventory = new IMProductInventory();
103 productInventory.setImProductId(iMProductBean.getImProductId()); 78 productInventory.setImProductId(iMProductBean.getImProductId());
104 productInventory.setStockNum(callRequest.getBizModel().getQuantity()); 79 productInventory.setStockNum(sumStock);
105 if(pineappleDao.updateProductInventory(productInventory) > 0){ 80 if(pineappleDao.updateProductInventory(productInventory) > 0){
106 //更新缓存 81 //更新缓存
107 pineappleSyncStockResponse.setQuantity(String.valueOf(callRequest.getBizModel().getQuantity())); 82 pineappleSyncStockResponse.setQuantity(String.valueOf(callRequest.getBizModel().getQuantity()));
...@@ -109,11 +84,40 @@ public class SyncStockBizServiceImpl extends AbstractBizService<PineappleSyncSto ...@@ -109,11 +84,40 @@ public class SyncStockBizServiceImpl extends AbstractBizService<PineappleSyncSto
109 pineappleSyncStockResponse.setCode(PineappleEnum.SUCCESS.getCode()); 84 pineappleSyncStockResponse.setCode(PineappleEnum.SUCCESS.getCode());
110 return pineappleSyncStockResponse; 85 return pineappleSyncStockResponse;
111 } 86 }
87 }else {
88 log.error(String.format("菠萝派商城appkey[%s]更新库存失败", callRequest.getRequest().getAppkey()));
89 throw new BizException((String.format("菠萝派商城appkey[%s]更新库存失败", callRequest.getRequest().getAppkey())));
90 }
91 }else{
92 log.error(String.format("菠萝派商城appkey[%s]更新sku库存失败", callRequest.getRequest().getAppkey()));
93 throw new BizException((String.format("菠萝派商城appkey[%s]更新sku库存失败", callRequest.getRequest().getAppkey())));
94 }
95 }
96 if(!StringUtil.isNull(callRequest.getBizModel().getPlatProductID())){
97 List<SkuApiResponse> skuBeanList = pineappleDao.getSkuBeanListByMap(callRequest.getBizModel().getPlatProductID());
98 if(!StringUtil.isNull(skuBeanList) && !skuBeanList.isEmpty()){
99 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()));
100 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()));
101 }
102 params.put("stockNum",callRequest.getBizModel().getQuantity());
103 if(pineappleDao.updateProduct(params) > 0){
104 //更新产品
105 RedisProductStockService.setProductStock(iMProductBean.getImProductId(), callRequest.getBizModel().getQuantity());
106 //1、更新商品库存
107 IMProductInventory productInventory = new IMProductInventory();
108 productInventory.setImProductId(iMProductBean.getImProductId());
109 productInventory.setStockNum(callRequest.getBizModel().getQuantity());
110 if(pineappleDao.updateProductInventory(productInventory) > 0){
111 //更新缓存
112 pineappleSyncStockResponse.setQuantity(String.valueOf(callRequest.getBizModel().getQuantity()));
113 pineappleSyncStockResponse.setMessage(PineappleEnum.SUCCESS.getMsg());
114 pineappleSyncStockResponse.setCode(PineappleEnum.SUCCESS.getCode());
115 return pineappleSyncStockResponse;
112 } 116 }
113 } 117 }
114 } 118 }
115 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())); 119 log.error(String.format("菠萝派商城appkey[%s]没有更改到库存", callRequest.getRequest().getAppkey()));
116 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())); 120 throw new BizException((String.format("菠萝派商城appkey[%s]没有更改到库存", callRequest.getRequest().getAppkey())));
117 } 121 }
118 122
119 @Override 123 @Override
......