From 335d3f7ff10c7b6e0da0a5ee9c91b6af4a498b28 Mon Sep 17 00:00:00 2001 From: 17600048398 <277692624@qq.com> Date: Tue, 25 Apr 2023 11:31:54 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E5=90=8C=E6=AD=A5=E5=88=86=E7=B1=BB=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=20=202.=E4=BF=AE=E6=94=B9=E5=BA=97=E9=93=BA=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=AF=B9=E5=BA=94=E5=BA=97=E9=93=BA=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/lili/event/impl/StoreChangeEvent.java | 206 ++++++++++++++++++ .../lili/listener/GoodsMessageListener.java | 6 + .../modules/goods/service/GoodsService.java | 6 + .../serviceimpl/CategoryServiceImpl.java | 21 ++ .../goods/serviceimpl/GoodsServiceImpl.java | 10 + .../serviceimpl/GoodsSkuServiceImpl.java | 17 +- .../cn/lili/rocketmq/tags/GoodsTagsEnum.java | 4 + 7 files changed, 267 insertions(+), 3 deletions(-) create mode 100644 consumer/src/main/java/cn/lili/event/impl/StoreChangeEvent.java diff --git a/consumer/src/main/java/cn/lili/event/impl/StoreChangeEvent.java b/consumer/src/main/java/cn/lili/event/impl/StoreChangeEvent.java new file mode 100644 index 000000000..af500156e --- /dev/null +++ b/consumer/src/main/java/cn/lili/event/impl/StoreChangeEvent.java @@ -0,0 +1,206 @@ +package cn.lili.event.impl; + +import cn.lili.event.StoreSettingChangeEvent; +import cn.lili.modules.distribution.service.DistributionGoodsService; +import cn.lili.modules.distribution.service.DistributionOrderService; +import cn.lili.modules.goods.service.DraftGoodsService; +import cn.lili.modules.member.service.MemberEvaluationService; +import cn.lili.modules.message.service.StoreMessageService; +import cn.lili.modules.order.aftersale.service.AfterSaleService; +import cn.lili.modules.order.order.service.OrderComplaintService; +import cn.lili.modules.order.order.service.OrderService; +import cn.lili.modules.order.order.service.ReceiptService; +import cn.lili.modules.order.order.service.StoreFlowService; +import cn.lili.modules.promotion.service.*; +import cn.lili.modules.store.entity.dos.Store; +import cn.lili.modules.store.service.BillService; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author ftyy + * @description: 店铺名称修改同步对应场景 + * @date 2023/4/24 + */ +@Service +public class StoreChangeEvent implements StoreSettingChangeEvent { + /** + * 优惠券活动表 + */ + @Autowired + private CouponActivityService couponActivityService; + + /** + * 砍价活动商品 + */ + @Autowired + private KanjiaActivityGoodsService kanjiaActivityGoodsService; + + /** + * 积分商品 + */ + @Autowired + private PointsGoodsService pointsGoodsService; + + /** + * 促销商品 + */ + @Autowired + private PromotionGoodsService promotionGoodsService; + + /** + * 秒杀活动活动 + */ + @Autowired + private SeckillService seckillService; + + /** + * 优惠券 + */ + @Autowired + private CouponService couponService; + + /** + * 满优惠活动 + */ + @Autowired + private FullDiscountService fullDiscountService; + + /** + * 拼团 + */ + @Autowired + private PintuanService pintuanService; + + /** + * 秒杀活动 + */ + @Autowired + private SeckillApplyService seckillApplyService; + /** + * 订单 + */ + @Autowired + private OrderService orderService; + + /** + * 店铺流水 + */ + @Autowired + private StoreFlowService storeFlowService; + + /** + * 售后 + */ + @Autowired + private AfterSaleService afterSaleService; + + /** + * 订单投诉 + */ + @Autowired + private OrderComplaintService orderComplaintService; + /** + * 发票 + */ + @Autowired + private ReceiptService receiptService; + + /** + * 会员优惠券 + */ + @Autowired + private MemberCouponService memberCouponService; + + /** + * 店铺消息 + */ + @Autowired + private StoreMessageService storeMessageService; + + /** + * 会员评价 + */ + @Autowired + private MemberEvaluationService memberEvaluationService; + + /** + * 结算单 + */ + @Autowired + private BillService billService; + /** + * 分销商品 + */ + @Autowired + private DistributionGoodsService distributionGoodsService; + /** + * 分销订单 + */ + @Autowired + private DistributionOrderService distributionOrderService; + + /** + * 草稿商品 + */ + @Autowired + private DraftGoodsService draftGoodsService; + + + /** + * 店铺名称修改 同步更新相关店铺名称 + * + * @param store 店铺信息 + */ + @Override + public void storeSettingChange(Store store) { + + UpdateWrapper updateWrapper = new UpdateWrapper<>() + .eq("store_id", store.getId()) + .set("store_name", store.getStoreName()); + + //修改会员优惠券中店铺名称 + memberCouponService.update(updateWrapper); + //修改优惠券活动中店铺名称 + couponActivityService.update(updateWrapper); + //修改砍价活动商品中店铺名称 + kanjiaActivityGoodsService.update(updateWrapper); + //修改积分商品中店铺名称 + pointsGoodsService.update(updateWrapper); + //修改促销商品中店铺名称 + promotionGoodsService.update(updateWrapper); + //修改秒杀活动活动中店铺名称 + seckillService.update(updateWrapper); + //修改优惠券中店铺名称 + couponService.update(updateWrapper); + //修改满优惠活动中店铺名称 + fullDiscountService.update(updateWrapper); + //修改拼团中店铺名称 + pintuanService.update(updateWrapper); + //修改秒杀活动中店铺名称 + seckillApplyService.update(updateWrapper); + //修改发票中店铺名称 + receiptService.update(updateWrapper); + //修改订单中的店铺名称 + orderService.update(updateWrapper); + //修改店铺流水中店铺名称 + storeFlowService.update(updateWrapper); + //修改售后中店铺名称 + afterSaleService.update(updateWrapper); + //修改订单投诉中店铺名称 + orderComplaintService.update(updateWrapper); + //修改店铺消息中的店铺名称 + storeMessageService.update(updateWrapper); + //修改会员评价中店铺名称 + memberEvaluationService.update(updateWrapper); + //修改结算单中店铺名称 + billService.update(updateWrapper); + //修改分销订单中店铺名称 + distributionOrderService.update(updateWrapper); + //修改分销商品中店铺名称 + distributionGoodsService.update(updateWrapper); + //修改草稿商品中店铺名称 + draftGoodsService.update(updateWrapper); + } +} diff --git a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java index e89499151..8661814dc 100644 --- a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java +++ b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java @@ -234,6 +234,12 @@ public class GoodsMessageListener implements RocketMQListener { log.error("删除店铺商品索引事件执行异常,商品信息: " + new String(messageExt.getBody()), e); } break; + //同步商品分类名称 + case CATEGORY_GOODS_NAME: + //分类ID + String id = new String(messageExt.getBody()); + goodsService.categoryGoodsName(id); + break; //商品评价 case GOODS_COMMENT_COMPLETE: MemberEvaluation memberEvaluation = JSONUtil.toBean(new String(messageExt.getBody()), MemberEvaluation.class); diff --git a/framework/src/main/java/cn/lili/modules/goods/service/GoodsService.java b/framework/src/main/java/cn/lili/modules/goods/service/GoodsService.java index 7757a7daa..165d1d611 100644 --- a/framework/src/main/java/cn/lili/modules/goods/service/GoodsService.java +++ b/framework/src/main/java/cn/lili/modules/goods/service/GoodsService.java @@ -184,4 +184,10 @@ public interface GoodsService extends IService { */ long countStoreGoodsNum(String storeId); + /** + * 同步商品分类名称 + * + * @param categoryId 分类ID + */ + void categoryGoodsName(String categoryId); } diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryServiceImpl.java index 8410e4145..1095544a4 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/CategoryServiceImpl.java @@ -4,7 +4,9 @@ import cn.hutool.core.text.CharSequenceUtil; import cn.lili.cache.Cache; import cn.lili.cache.CachePrefix; import cn.lili.common.enums.ResultCode; +import cn.lili.common.event.TransactionCommitSendMQEvent; import cn.lili.common.exception.ServiceException; +import cn.lili.common.properties.RocketmqCustomProperties; import cn.lili.modules.goods.entity.dos.Category; import cn.lili.modules.goods.entity.vos.CategoryVO; import cn.lili.modules.goods.mapper.CategoryMapper; @@ -12,16 +14,19 @@ import cn.lili.modules.goods.service.CategoryBrandService; import cn.lili.modules.goods.service.CategoryParameterGroupService; import cn.lili.modules.goods.service.CategoryService; import cn.lili.modules.goods.service.CategorySpecificationService; +import cn.lili.rocketmq.tags.GoodsTagsEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -55,6 +60,20 @@ public class CategoryServiceImpl extends ServiceImpl i @Autowired private CategorySpecificationService categorySpecificationService; + @Autowired + private ApplicationEventPublisher applicationEventPublisher; + + /** + * rocketMq + */ + @Autowired + private RocketMQTemplate rocketMQTemplate; + /** + * rocketMq配置 + */ + @Autowired + private RocketmqCustomProperties rocketmqCustomProperties; + @Override public List dbList(String parentId) { return this.list(new LambdaQueryWrapper().eq(Category::getParentId, parentId)); @@ -244,6 +263,8 @@ public class CategoryServiceImpl extends ServiceImpl i updateWrapper.eq("id", category.getId()); this.baseMapper.update(category, updateWrapper); removeCache(); + applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("同步商品分类名称", + rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.CATEGORY_GOODS_NAME.name(), category.getId())); } diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java index c1ae964b3..5bd264f0d 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java @@ -494,6 +494,16 @@ public class GoodsServiceImpl extends ServiceImpl implements .eq(Goods::getMarketEnable, GoodsStatusEnum.UPPER.name())); } + @Override + public void categoryGoodsName(String categoryId) { + //获取分类下的商品 + List list = this.list(new LambdaQueryWrapper().like(Goods::getCategoryPath,categoryId)); + list.parallelStream().forEach(goods->{ + //移除redis中商品缓存 + cache.remove(CachePrefix.GOODS.getPrefix() + goods.getId()); + }); + } + /** * 更新商品状态 diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index 209624227..1c9c134f1 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -3,6 +3,7 @@ package cn.lili.modules.goods.serviceimpl; import cn.hutool.core.map.MapUtil; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import cn.lili.cache.Cache; @@ -529,9 +530,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl i public void updateStock(String skuId, Integer quantity) { GoodsSku goodsSku = getGoodsSkuByIdFromCache(skuId); if (goodsSku != null) { - if (quantity <= 0) { - goodsIndexService.deleteIndexById(goodsSku.getId()); - } + //判断商品sku是否已经下架(修改商品库存为0时 会自动下架商品),再次更新商品库存时 需更新商品索引 + Boolean isFlag = goodsSku.getQuantity()<= 0; + goodsSku.setQuantity(quantity); boolean update = this.update(new LambdaUpdateWrapper().eq(GoodsSku::getId, skuId).set(GoodsSku::getQuantity, quantity)); @@ -546,6 +547,16 @@ public class GoodsSkuServiceImpl extends ServiceImpl i goodsSkus.add(goodsSku); this.updateGoodsStuck(goodsSkus); this.promotionGoodsService.updatePromotionGoodsStock(goodsSku.getId(), quantity); + //商品库存为0是删除商品索引 + if (quantity <= 0) { + goodsIndexService.deleteIndexById(goodsSku.getId()); + } + //商品SKU库存为0并且商品sku状态为上架时更新商品库存 + if(isFlag && StrUtil.equals(goodsSku.getMarketEnable(),GoodsStatusEnum.UPPER.name())) { + List goodsIds = new ArrayList<>(); + goodsIds.add(goodsSku.getGoodsId()); + applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("更新商品", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.UPDATE_GOODS_INDEX.name(), goodsIds)); + } } } diff --git a/framework/src/main/java/cn/lili/rocketmq/tags/GoodsTagsEnum.java b/framework/src/main/java/cn/lili/rocketmq/tags/GoodsTagsEnum.java index 9aa013fca..86ef5c8b5 100644 --- a/framework/src/main/java/cn/lili/rocketmq/tags/GoodsTagsEnum.java +++ b/framework/src/main/java/cn/lili/rocketmq/tags/GoodsTagsEnum.java @@ -55,6 +55,10 @@ public enum GoodsTagsEnum { * "收藏商品" */ GOODS_COLLECTION("收藏商品"), + /** + * 同步商品分类名称 + */ + CATEGORY_GOODS_NAME("同步商品分类名称"), /** * "购买商品完成" */