From 92c3c21e32f14819cc919b9961a0b02a8cbd8ba1 Mon Sep 17 00:00:00 2001 From: lifenlong Date: Thu, 1 Jul 2021 14:31:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=A0=E9=99=A4=EF=BC=8C?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=88=86=E9=94=80=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lili/listener/GoodsMessageListener.java | 112 +++++++++++++----- .../entity/dos/DistributionSelectedGoods.java | 2 +- .../goods/serviceimpl/GoodsServiceImpl.java | 2 +- .../serviceimpl/GoodsSkuServiceImpl.java | 4 +- update-sql/version4.1to4.2.sql | 3 + 5 files changed, 88 insertions(+), 35 deletions(-) diff --git a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java index fa4132d0..16dd44dc 100644 --- a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java +++ b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java @@ -3,6 +3,10 @@ package cn.lili.listener; import cn.hutool.json.JSONUtil; import cn.lili.common.rocketmq.tags.GoodsTagsEnum; import cn.lili.event.GoodsCommentCompleteEvent; +import cn.lili.modules.distribution.entity.dos.DistributionGoods; +import cn.lili.modules.distribution.entity.dos.DistributionSelectedGoods; +import cn.lili.modules.distribution.service.DistributionGoodsService; +import cn.lili.modules.distribution.service.DistributionSelectedGoodsService; import cn.lili.modules.goods.entity.dos.Goods; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dto.GoodsCompleteMessage; @@ -15,6 +19,8 @@ import cn.lili.modules.member.service.GoodsCollectionService; import cn.lili.modules.search.entity.dos.EsGoodsIndex; import cn.lili.modules.search.service.EsGoodsIndexService; import cn.lili.modules.store.service.StoreService; +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 lombok.extern.slf4j.Slf4j; import org.apache.rocketmq.common.message.MessageExt; @@ -57,6 +63,13 @@ public class GoodsMessageListener implements RocketMQListener { //商品评价 @Autowired private List goodsCommentCompleteEvents; + //分销商品 + @Autowired + private DistributionGoodsService distributionGoodsService; + //分销员-商品关联表 + @Autowired + private DistributionSelectedGoodsService distributionSelectedGoodsService; + @Override public void onMessage(MessageExt messageExt) { @@ -77,9 +90,10 @@ public class GoodsMessageListener implements RocketMQListener { break; //审核商品 case GOODS_AUDIT: + break; //删除商品 case GOODS_DELETE: - storeService.updateStoreGoodsNum(new String(messageExt.getBody())); + deleteGoods(messageExt); break; //规格删除 case SKU_DELETE: @@ -107,38 +121,72 @@ public class GoodsMessageListener implements RocketMQListener { break; //购买商品完成 case BUY_GOODS_COMPLETE: - String goodsCompleteMessageStr = new String(messageExt.getBody()); - List goodsCompleteMessageList = JSONUtil.toList(JSONUtil.parseArray(goodsCompleteMessageStr), GoodsCompleteMessage.class); - for (GoodsCompleteMessage goodsCompleteMessage : goodsCompleteMessageList) { - Goods goods = goodsService.getById(goodsCompleteMessage.getGoodsId()); - if (goods != null) { - //更新商品购买数量 - if (goods.getBuyCount() == null) { - goods.setBuyCount(0); - } - int buyCount = goods.getBuyCount() + goodsCompleteMessage.getBuyNum(); - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(Goods::getId, goodsCompleteMessage.getGoodsId()); - updateWrapper.set(Goods::getBuyCount, buyCount); - goodsService.update(updateWrapper); - } else { - log.error("商品Id为[" + goodsCompleteMessage.getGoodsId() + "的商品不存在,更新商品失败!"); - } - GoodsSku goodsSku = goodsSkuService.getById(goodsCompleteMessage.getSkuId()); - if (goodsSku != null) { - //更新商品购买数量 - if (goodsSku.getBuyCount() == null) { - goodsSku.setBuyCount(0); - } - int buyCount = goodsSku.getBuyCount() + goodsCompleteMessage.getBuyNum(); - goodsSku.setBuyCount(buyCount); - goodsSkuService.update(goodsSku); - goodsIndexService.updateIndexBuyNum(goodsCompleteMessage.getSkuId(), buyCount); - } else { - log.error("商品SkuId为[" + goodsCompleteMessage.getGoodsId() + "的商品不存在,更新商品失败!"); - } - } + this.goodsBuyComplete(messageExt); break; } } + + /** + * 删除商品 + * 1.更新店铺的商品数量 + * 2.删除分销员-分销商品绑定关系 + * 3.删除分销商品 + * @param messageExt 消息 + */ + private void deleteGoods(MessageExt messageExt){ + Goods goods=JSONUtil.toBean(new String(messageExt.getBody()),Goods.class); + //更新店铺商品数量 + storeService.updateStoreGoodsNum(goods.getStoreId()); + + //删除获取分销商品 + DistributionGoods distributionGoods=distributionGoodsService.getOne(new LambdaQueryWrapper() + .eq(DistributionGoods::getGoodsId,goods.getId())); + + //删除分销商品绑定关系 + distributionSelectedGoodsService.remove(new LambdaQueryWrapper() + .eq(DistributionSelectedGoods::getDistributionGoodsId,distributionGoods.getId())); + + //删除分销商品 + distributionGoodsService.removeById(distributionGoods.getId()); + } + + /** + * 商品购买完成 + * 1.更新商品购买数量 + * 2.更新SKU购买数量 + * 3.更新索引购买数量 + * @param messageExt + */ + private void goodsBuyComplete(MessageExt messageExt){ + String goodsCompleteMessageStr = new String(messageExt.getBody()); + List goodsCompleteMessageList = JSONUtil.toList(JSONUtil.parseArray(goodsCompleteMessageStr), GoodsCompleteMessage.class); + for (GoodsCompleteMessage goodsCompleteMessage : goodsCompleteMessageList) { + Goods goods = goodsService.getById(goodsCompleteMessage.getGoodsId()); + if (goods != null) { + //更新商品购买数量 + if (goods.getBuyCount() == null) { + goods.setBuyCount(0); + } + int buyCount = goods.getBuyCount() + goodsCompleteMessage.getBuyNum(); + goodsService.update(new LambdaUpdateWrapper() + .eq(Goods::getId, goodsCompleteMessage.getGoodsId()) + .set(Goods::getBuyCount, buyCount)); + } else { + log.error("商品Id为[" + goodsCompleteMessage.getGoodsId() + "的商品不存在,更新商品失败!"); + } + GoodsSku goodsSku = goodsSkuService.getById(goodsCompleteMessage.getSkuId()); + if (goodsSku != null) { + //更新商品购买数量 + if (goodsSku.getBuyCount() == null) { + goodsSku.setBuyCount(0); + } + int buyCount = goodsSku.getBuyCount() + goodsCompleteMessage.getBuyNum(); + goodsSku.setBuyCount(buyCount); + goodsSkuService.update(goodsSku); + goodsIndexService.updateIndexBuyNum(goodsCompleteMessage.getSkuId(), buyCount); + } else { + log.error("商品SkuId为[" + goodsCompleteMessage.getGoodsId() + "的商品不存在,更新商品失败!"); + } + } + } } diff --git a/framework/src/main/java/cn/lili/modules/distribution/entity/dos/DistributionSelectedGoods.java b/framework/src/main/java/cn/lili/modules/distribution/entity/dos/DistributionSelectedGoods.java index 5174ad08..620f6e90 100644 --- a/framework/src/main/java/cn/lili/modules/distribution/entity/dos/DistributionSelectedGoods.java +++ b/framework/src/main/java/cn/lili/modules/distribution/entity/dos/DistributionSelectedGoods.java @@ -38,7 +38,7 @@ public class DistributionSelectedGoods { @ApiModelProperty(value = "分销员ID") private String distributionId; - @ApiModelProperty(value = "分销员品ID") + @ApiModelProperty(value = "分销商品ID") private String distributionGoodsId; public DistributionSelectedGoods(String distributionId, String distributionGoodsId) { 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 86023b2b..9b15e69d 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 @@ -279,7 +279,7 @@ public class GoodsServiceImpl extends ServiceImpl implements //商品删除消息 String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name(); //发送mq消息 - rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goods.getStoreId()), RocketmqSendCallbackBuilder.commonCallback()); + rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goods), RocketmqSendCallbackBuilder.commonCallback()); } return true; 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 153dba54..cd9dabe1 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 @@ -455,7 +455,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl i private void generateEsCheck(Goods goods) { //如果商品通过审核&&并且已上架 List goodsSkuList = this.list(new LambdaQueryWrapper().eq(GoodsSku::getGoodsId, goods.getId())); - if (goods.getIsAuth().equals(GoodsAuthEnum.PASS.name()) && goods.getMarketEnable().equals(GoodsStatusEnum.UPPER.name()) && Boolean.FALSE.equals(goods.getDeleteFlag())) { + if (goods.getIsAuth().equals(GoodsAuthEnum.PASS.name()) + && goods.getMarketEnable().equals(GoodsStatusEnum.UPPER.name()) + && Boolean.FALSE.equals(goods.getDeleteFlag())) { List goodsIndices = new ArrayList<>(); for (GoodsSku goodsSku : goodsSkuList) { EsGoodsIndex esGoodsOld = goodsIndexService.findById(goodsSku.getId()); diff --git a/update-sql/version4.1to4.2.sql b/update-sql/version4.1to4.2.sql index f5f7ae33..40296ccc 100644 --- a/update-sql/version4.1to4.2.sql +++ b/update-sql/version4.1to4.2.sql @@ -2,3 +2,6 @@ ALTER TABLE li_distribution ADD settlement_bank_account_name varchar ( 200 ); ALTER TABLE li_distribution ADD settlement_bank_account_num varchar ( 200 ); ALTER TABLE li_distribution ADD settlement_bank_branch_name varchar ( 200 ); + +/** 文章分类添加默认值**/ +ALTER TABLE li_article_category alter column sort set default 0; \ No newline at end of file