From bcd7df0394e11865de4ba96a7cf75ba50b71099c Mon Sep 17 00:00:00 2001 From: liyj <1617420630@qq.com> Date: Mon, 28 Jul 2025 18:31:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=89=B9=E9=87=8F=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=A7=84=E6=A0=BC=E4=BB=B7=E6=A0=BC=E5=92=8C=E5=BA=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/ShopProductItemController.java | 13 ++- .../service/ShopProductItemService.java | 2 +- .../impl/ShopProductItemServiceImpl.java | 89 ++++++++++++------- 3 files changed, 62 insertions(+), 42 deletions(-) diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/product/controller/admin/ShopProductItemController.java b/mall-shop/src/main/java/com/suisung/mall/shop/product/controller/admin/ShopProductItemController.java index 4543c88f..81177cd2 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/product/controller/admin/ShopProductItemController.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/product/controller/admin/ShopProductItemController.java @@ -7,10 +7,9 @@ import com.suisung.mall.shop.product.service.ShopProductItemService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; /** *

@@ -87,13 +86,13 @@ public class ShopProductItemController { /** * 编辑库存和价格 - * @param shopProductItem + * @param shopProductItemList * @return */ @ApiOperation(value = "商品表-SKU表 商品名称(产品名称+颜色规格名称) =shop_product_item-编辑", notes = "商品表-SKU表 商品名称(产品名称+颜色规格名称) =shop_product_item-编辑") @RequestMapping(value = "/editQuantity", method = RequestMethod.POST) - public CommonResult editQuantity(ShopProductItem shopProductItem) { - return shopProductItemService.editQuantity(shopProductItem); + public CommonResult editQuantity(@RequestBody List shopProductItemList) { + return shopProductItemService.editQuantity(shopProductItemList); } } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/product/service/ShopProductItemService.java b/mall-shop/src/main/java/com/suisung/mall/shop/product/service/ShopProductItemService.java index 01da4dd6..2aa13002 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/product/service/ShopProductItemService.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/product/service/ShopProductItemService.java @@ -91,5 +91,5 @@ public interface ShopProductItemService extends IBaseService { * 修改item的价格和库存 * @param: ShopProductItem */ - CommonResult editQuantity(ShopProductItem shopProductItem); + CommonResult editQuantity(List shopProductItemList); } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/product/service/impl/ShopProductItemServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/product/service/impl/ShopProductItemServiceImpl.java index 1d78beae..563ab374 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/product/service/impl/ShopProductItemServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/product/service/impl/ShopProductItemServiceImpl.java @@ -2294,46 +2294,67 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl shopProductItemList) { + if(shopProductItemList.isEmpty()){ + return CommonResult.failed("修改数据不能为空"); + } + if(shopProductItemList.size()>10){ + return CommonResult.failed("修改数据不能超过10条"); + } QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("product_id",shopProductItem.getProduct_id()); - List oldShopProductItems= shopProductItemService.list(queryWrapper); - List 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); - if(ObjectUtil.isEmpty(shopProductItem.getItem_quantity())){ - return CommonResult.failed("库存不能为空"); - } - if(ObjectUtil.isEmpty(shopProductItem.getItem_unit_price())){ - return CommonResult.failed("价格不能为空"); - } + List updateShopProductItem=new ArrayList<>(); + List updateShopProductBase=new ArrayList<>(); + List updateShopProductIndex=new ArrayList<>(); + for (ShopProductItem shopProductItem : shopProductItemList) { + queryWrapper.eq("product_id",shopProductItem.getProduct_id()); + List oldShopProductItems= shopProductItemService.list(queryWrapper); + List 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); + if(ObjectUtil.isEmpty(shopProductItem.getItem_quantity())){ + return CommonResult.failed("库存不能为空"); + } + if(ObjectUtil.isEmpty(shopProductItem.getItem_unit_price())){ + return CommonResult.failed("价格不能为空"); + } - BigDecimal item_unit_price =shopProductItem.getItem_unit_price(); - BigDecimal item_unit_price_max =shopProductItem.getItem_unit_price(); + 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()); - shopProductBaseService.updateById(shopProductBase); + 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); + } + oldShopProductItem.setItem_quantity(shopProductItem.getItem_quantity()); + oldShopProductItem.setItem_unit_price(shopProductItem.getItem_unit_price()); + updateShopProductItem.add(oldShopProductItem); + // shopProductItemService.updateById(oldShopProductItem); } - 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(!updateShopProductBase.isEmpty()){ + shopProductBaseService.updateBatchById(updateShopProductBase); } - if(ObjectUtil.isNotEmpty(shopProductIndex.getProduct_id())){ - shopProductIndexService.updateById(shopProductIndex); + if(!updateShopProductIndex.isEmpty()){ + shopProductIndexService.updateBatchById(updateShopProductIndex); } - oldShopProductItem.setItem_quantity(shopProductItem.getItem_quantity()); - oldShopProductItem.setItem_unit_price(shopProductItem.getItem_unit_price()); - shopProductItemService.updateById(oldShopProductItem); + shopProductItemService.updateBatchById(updateShopProductItem); return CommonResult.success(); } }