商品sku列表更新接口优化
This commit is contained in:
parent
816ed381d9
commit
77a994bcfe
@ -2305,49 +2305,81 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
|
||||
List<ShopProductItem> updateShopProductItem=new ArrayList<>();
|
||||
List<ShopProductBase> updateShopProductBase=new ArrayList<>();
|
||||
List<ShopProductIndex> updateShopProductIndex=new ArrayList<>();
|
||||
for (ShopProductItem shopProductItem : shopProductItemList) {
|
||||
queryWrapper.eq("product_id",shopProductItem.getProduct_id());
|
||||
List<ShopProductItem> oldShopProductItems= shopProductItemService.list(queryWrapper);
|
||||
List<ShopProductItem> oldShopProductItemList= oldShopProductItems.stream().filter(s -> s.getItem_id().equals(shopProductItem.getItem_id())).collect(Collectors.toList());
|
||||
if(CollUtil.isEmpty(oldShopProductItemList)){
|
||||
return CommonResult.failed("不存在商品sku");
|
||||
//校验数据
|
||||
Iterator<ShopProductItem> itemIs=shopProductItemList.iterator();
|
||||
StringBuilder ids= new StringBuilder();
|
||||
Long productId=shopProductItemList.get(0).getProduct_id();
|
||||
while (itemIs.hasNext()) {//去重
|
||||
ShopProductItem shopProductItem=itemIs.next();
|
||||
if(ObjectUtil.isEmpty(shopProductItem.getProduct_id())){
|
||||
return CommonResult.failed("产品id不能为空");
|
||||
}
|
||||
if(ObjectUtil.isEmpty(shopProductItem.getItem_id())){
|
||||
return CommonResult.failed("商品sku不能为空");
|
||||
}
|
||||
ShopProductItem oldShopProductItem=oldShopProductItemList.get(0);
|
||||
if(ObjectUtil.isEmpty(shopProductItem.getItem_quantity())){
|
||||
return CommonResult.failed("库存不能为空");
|
||||
}
|
||||
if(ObjectUtil.isEmpty(shopProductItem.getItem_unit_price())){
|
||||
return CommonResult.failed("价格不能为空");
|
||||
}
|
||||
if(!productId.equals(shopProductItem.getProduct_id())){
|
||||
return CommonResult.failed("只能修改相同产品的sku列表");
|
||||
}
|
||||
if(ids.toString().contains(shopProductItem.getItem_id().toString())){
|
||||
itemIs.remove();
|
||||
}else {
|
||||
ids.append(shopProductItem.getItem_id());
|
||||
}
|
||||
}
|
||||
BigDecimal item_unit_price = shopProductItemList.stream().map(ShopProductItem::getItem_unit_price).min(BigDecimal::compareTo).get();
|
||||
BigDecimal item_unit_price_max =shopProductItemList.stream().map(ShopProductItem::getItem_unit_price).max(BigDecimal::compareTo).get();
|
||||
|
||||
BigDecimal item_unit_price =shopProductItem.getItem_unit_price();
|
||||
BigDecimal item_unit_price_max =shopProductItem.getItem_unit_price();
|
||||
|
||||
BigDecimal item_unit_price_old = oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).min(BigDecimal::compareTo).get();
|
||||
ShopProductIndex shopProductIndex=new ShopProductIndex();
|
||||
if(item_unit_price_old.compareTo(item_unit_price)>0){
|
||||
ShopProductBase shopProductBase=new ShopProductBase();
|
||||
shopProductBase.setProduct_id(shopProductItem.getProduct_id());
|
||||
shopProductBase.setProduct_unit_price(item_unit_price);
|
||||
shopProductIndex.setProduct_unit_price(item_unit_price);
|
||||
shopProductIndex.setProduct_id(shopProductItem.getProduct_id());
|
||||
updateShopProductBase.add(shopProductBase);
|
||||
// shopProductBaseService.updateById(shopProductBase);
|
||||
}
|
||||
BigDecimal item_unit_price_max_old=oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).max(BigDecimal::compareTo).get();
|
||||
if(item_unit_price_max.compareTo(item_unit_price_max_old)>0){
|
||||
shopProductIndex.setProduct_id(shopProductItem.getProduct_id());
|
||||
shopProductIndex.setProduct_unit_price_max(item_unit_price_max);
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(shopProductIndex.getProduct_id())){
|
||||
updateShopProductIndex.add(shopProductIndex);
|
||||
//shopProductIndexService.updateById(shopProductIndex);
|
||||
queryWrapper.eq("product_id",productId);
|
||||
List<ShopProductItem> oldShopProductItems= shopProductItemService.list(queryWrapper);
|
||||
BigDecimal item_unit_price_old = oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).min(BigDecimal::compareTo).get();
|
||||
BigDecimal item_unit_price_max_old=oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).max(BigDecimal::compareTo).get();
|
||||
for (ShopProductItem shopProductItem : shopProductItemList) {
|
||||
List<ShopProductItem> oldShopProductItemList= oldShopProductItems.stream().filter(s -> s.getItem_id().equals(shopProductItem.getItem_id())).collect(Collectors.toList());
|
||||
if(CollUtil.isEmpty(oldShopProductItemList)){
|
||||
return CommonResult.failed("不存在商品sku");
|
||||
}
|
||||
ShopProductItem oldShopProductItem=oldShopProductItemList.get(0);
|
||||
oldShopProductItem.setItem_quantity(shopProductItem.getItem_quantity());
|
||||
oldShopProductItem.setItem_unit_price(shopProductItem.getItem_unit_price());
|
||||
updateShopProductItem.add(oldShopProductItem);
|
||||
// shopProductItemService.updateById(oldShopProductItem);
|
||||
}
|
||||
|
||||
ShopProductIndex shopProductIndex=new ShopProductIndex();
|
||||
ShopProductBase shopProductBase=new ShopProductBase();
|
||||
if(item_unit_price_old.compareTo(item_unit_price)>0&&oldShopProductItems.size()>1){
|
||||
shopProductBase.setProduct_id(productId);
|
||||
shopProductBase.setProduct_unit_price(item_unit_price);
|
||||
shopProductIndex.setProduct_unit_price(item_unit_price);
|
||||
shopProductIndex.setProduct_id(productId);
|
||||
updateShopProductBase.add(shopProductBase);
|
||||
}
|
||||
|
||||
|
||||
if(item_unit_price_max.compareTo(item_unit_price_max_old)>0&&oldShopProductItems.size()>1){
|
||||
shopProductIndex.setProduct_id(productId);
|
||||
shopProductIndex.setProduct_unit_price_max(item_unit_price_max);
|
||||
}
|
||||
|
||||
if(oldShopProductItems.size()==1){
|
||||
shopProductBase.setProduct_id(productId);
|
||||
shopProductBase.setProduct_unit_price(item_unit_price);
|
||||
shopProductIndex.setProduct_id(productId);
|
||||
shopProductIndex.setProduct_unit_price(item_unit_price);
|
||||
shopProductIndex.setProduct_unit_price_max(item_unit_price);
|
||||
shopProductIndex.setProduct_id(productId);
|
||||
updateShopProductBase.add(shopProductBase);
|
||||
}
|
||||
|
||||
if(ObjectUtil.isNotEmpty(shopProductIndex.getProduct_id())){
|
||||
updateShopProductIndex.add(shopProductIndex);
|
||||
}
|
||||
if(!updateShopProductBase.isEmpty()){
|
||||
shopProductBaseService.updateBatchById(updateShopProductBase);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user