商品删除,删除分销商品

This commit is contained in:
lifenlong 2021-07-01 14:31:33 +08:00
parent bd13a9b150
commit 92c3c21e32
5 changed files with 88 additions and 35 deletions

View File

@ -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<MessageExt> {
//商品评价
@Autowired
private List<GoodsCommentCompleteEvent> goodsCommentCompleteEvents;
//分销商品
@Autowired
private DistributionGoodsService distributionGoodsService;
//分销员-商品关联表
@Autowired
private DistributionSelectedGoodsService distributionSelectedGoodsService;
@Override
public void onMessage(MessageExt messageExt) {
@ -77,9 +90,10 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
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<MessageExt> {
break;
//购买商品完成
case BUY_GOODS_COMPLETE:
String goodsCompleteMessageStr = new String(messageExt.getBody());
List<GoodsCompleteMessage> 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<Goods> 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<DistributionGoods>()
.eq(DistributionGoods::getGoodsId,goods.getId()));
//删除分销商品绑定关系
distributionSelectedGoodsService.remove(new LambdaQueryWrapper<DistributionSelectedGoods>()
.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<GoodsCompleteMessage> 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<Goods>()
.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() + "的商品不存在,更新商品失败!");
}
}
}
}

View File

@ -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) {

View File

@ -279,7 +279,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> 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;

View File

@ -455,7 +455,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
private void generateEsCheck(Goods goods) {
//如果商品通过审核&&并且已上架
List<GoodsSku> goodsSkuList = this.list(new LambdaQueryWrapper<GoodsSku>().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<EsGoodsIndex> goodsIndices = new ArrayList<>();
for (GoodsSku goodsSku : goodsSkuList) {
EsGoodsIndex esGoodsOld = goodsIndexService.findById(goodsSku.getId());

View File

@ -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;