From c8610f2b3ed40dd56c5ae59e68df9af892706d47 Mon Sep 17 00:00:00 2001 From: yovinchen Date: Sun, 17 Sep 2023 11:08:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=95=86=E5=93=81sku=E4=BF=A1=E6=81=AF=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E5=88=A0=E9=99=A4es=E4=B8=AD=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/controller/SkuInfoController.java | 4 ++-- .../ssyx/product/service/SkuInfoService.java | 6 ++++++ .../service/impl/SkuInfoServiceImpl.java | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuInfoController.java b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuInfoController.java index 60b6aa0..2f77792 100644 --- a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuInfoController.java +++ b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/controller/SkuInfoController.java @@ -86,7 +86,7 @@ public class SkuInfoController { //TODO 删除es public Result remove(@PathVariable Long id) { try { - skuInfoService.removeById(id); + skuInfoService.deleteById(id); return Result.ok(null); } catch (Exception e) { throw new RuntimeException("删除商品sku信息异常", e); @@ -98,7 +98,7 @@ public class SkuInfoController { //TODO 删除es public Result batchRemove(@RequestBody List idList) { try { - skuInfoService.removeByIds(idList); + skuInfoService.deleteByIds(idList); return Result.ok(null); } catch (Exception e) { throw new RuntimeException("根据id列表删除商品sku信息异常", e); diff --git a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuInfoService.java b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuInfoService.java index a561df1..8ba50a1 100644 --- a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuInfoService.java +++ b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/service/SkuInfoService.java @@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.List; + /** *

* sku信息 服务类 @@ -29,4 +31,8 @@ public interface SkuInfoService extends IService { void publish(Long skuId, Integer status); void isNewPerson(Long skuId, Integer status); + + void deleteByIds(List idList); + + void deleteById(Long id); } diff --git a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuInfoServiceImpl.java b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuInfoServiceImpl.java index b6bf8dd..78792c9 100644 --- a/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuInfoServiceImpl.java +++ b/guigu-ssyx-parent/service/service-product/src/main/java/com/atguigu/ssyx/product/service/impl/SkuInfoServiceImpl.java @@ -202,6 +202,7 @@ public class SkuInfoServiceImpl extends ServiceImpl impl * @param skuId * @param status */ + @Transactional(rollbackFor = {Exception.class}) @Override public void publish(Long skuId, Integer status) { // 更改发布状态 @@ -235,6 +236,24 @@ public class SkuInfoServiceImpl extends ServiceImpl impl baseMapper.updateById(skuInfo); } + @Override + public void deleteByIds(List idList) { + baseMapper.deleteBatchIds(idList); + + //商品下架:发送mq消息同步es + for (Long id : idList) { + rabbitService.sendMessage(MqConst.EXCHANGE_GOODS_DIRECT, MqConst.ROUTING_GOODS_LOWER, id); + } + } + + @Override + public void deleteById(Long id) { + baseMapper.deleteById(id); + + //商品删除:发送mq消息同步es + rabbitService.sendMessage(MqConst.EXCHANGE_GOODS_DIRECT, MqConst.ROUTING_GOODS_LOWER, id); + } + private SkuInfoVo getSkuInfoDB(Long skuId) { SkuInfoVo skuInfoVo = new SkuInfoVo();