商品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<ShopProductItem> updateShopProductItem=new ArrayList<>();
|
||||||
List<ShopProductBase> updateShopProductBase=new ArrayList<>();
|
List<ShopProductBase> updateShopProductBase=new ArrayList<>();
|
||||||
List<ShopProductIndex> updateShopProductIndex=new ArrayList<>();
|
List<ShopProductIndex> updateShopProductIndex=new ArrayList<>();
|
||||||
for (ShopProductItem shopProductItem : shopProductItemList) {
|
//校验数据
|
||||||
queryWrapper.eq("product_id",shopProductItem.getProduct_id());
|
Iterator<ShopProductItem> itemIs=shopProductItemList.iterator();
|
||||||
List<ShopProductItem> oldShopProductItems= shopProductItemService.list(queryWrapper);
|
StringBuilder ids= new StringBuilder();
|
||||||
List<ShopProductItem> oldShopProductItemList= oldShopProductItems.stream().filter(s -> s.getItem_id().equals(shopProductItem.getItem_id())).collect(Collectors.toList());
|
Long productId=shopProductItemList.get(0).getProduct_id();
|
||||||
if(CollUtil.isEmpty(oldShopProductItemList)){
|
while (itemIs.hasNext()) {//去重
|
||||||
return CommonResult.failed("不存在商品sku");
|
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())){
|
if(ObjectUtil.isEmpty(shopProductItem.getItem_quantity())){
|
||||||
return CommonResult.failed("库存不能为空");
|
return CommonResult.failed("库存不能为空");
|
||||||
}
|
}
|
||||||
if(ObjectUtil.isEmpty(shopProductItem.getItem_unit_price())){
|
if(ObjectUtil.isEmpty(shopProductItem.getItem_unit_price())){
|
||||||
return CommonResult.failed("价格不能为空");
|
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();
|
queryWrapper.eq("product_id",productId);
|
||||||
BigDecimal item_unit_price_max =shopProductItem.getItem_unit_price();
|
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_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();
|
||||||
ShopProductIndex shopProductIndex=new ShopProductIndex();
|
for (ShopProductItem shopProductItem : shopProductItemList) {
|
||||||
if(item_unit_price_old.compareTo(item_unit_price)>0){
|
List<ShopProductItem> oldShopProductItemList= oldShopProductItems.stream().filter(s -> s.getItem_id().equals(shopProductItem.getItem_id())).collect(Collectors.toList());
|
||||||
ShopProductBase shopProductBase=new ShopProductBase();
|
if(CollUtil.isEmpty(oldShopProductItemList)){
|
||||||
shopProductBase.setProduct_id(shopProductItem.getProduct_id());
|
return CommonResult.failed("不存在商品sku");
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
ShopProductItem oldShopProductItem=oldShopProductItemList.get(0);
|
||||||
oldShopProductItem.setItem_quantity(shopProductItem.getItem_quantity());
|
oldShopProductItem.setItem_quantity(shopProductItem.getItem_quantity());
|
||||||
oldShopProductItem.setItem_unit_price(shopProductItem.getItem_unit_price());
|
oldShopProductItem.setItem_unit_price(shopProductItem.getItem_unit_price());
|
||||||
updateShopProductItem.add(oldShopProductItem);
|
updateShopProductItem.add(oldShopProductItem);
|
||||||
// shopProductItemService.updateById(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()){
|
if(!updateShopProductBase.isEmpty()){
|
||||||
shopProductBaseService.updateBatchById(updateShopProductBase);
|
shopProductBaseService.updateBatchById(updateShopProductBase);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user