1.修改商品分类同步分类名称 2.修改店铺名称同步对应店铺名称场景

This commit is contained in:
17600048398 2023-04-25 11:31:54 +08:00
parent 16608d4950
commit 335d3f7ff1
7 changed files with 267 additions and 3 deletions

View File

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

View File

@ -234,6 +234,12 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
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);

View File

@ -184,4 +184,10 @@ public interface GoodsService extends IService<Goods> {
*/
long countStoreGoodsNum(String storeId);
/**
* 同步商品分类名称
*
* @param categoryId 分类ID
*/
void categoryGoodsName(String categoryId);
}

View File

@ -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<CategoryMapper, Category> i
@Autowired
private CategorySpecificationService categorySpecificationService;
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
/**
* rocketMq
*/
@Autowired
private RocketMQTemplate rocketMQTemplate;
/**
* rocketMq配置
*/
@Autowired
private RocketmqCustomProperties rocketmqCustomProperties;
@Override
public List<Category> dbList(String parentId) {
return this.list(new LambdaQueryWrapper<Category>().eq(Category::getParentId, parentId));
@ -244,6 +263,8 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> 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()));
}

View File

@ -494,6 +494,16 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
.eq(Goods::getMarketEnable, GoodsStatusEnum.UPPER.name()));
}
@Override
public void categoryGoodsName(String categoryId) {
//获取分类下的商品
List<Goods> list = this.list(new LambdaQueryWrapper<Goods>().like(Goods::getCategoryPath,categoryId));
list.parallelStream().forEach(goods->{
//移除redis中商品缓存
cache.remove(CachePrefix.GOODS.getPrefix() + goods.getId());
});
}
/**
* 更新商品状态

View File

@ -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<GoodsSkuMapper, GoodsSku> 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<GoodsSku>().eq(GoodsSku::getId, skuId).set(GoodsSku::getQuantity, quantity));
@ -546,6 +547,16 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> 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<String> goodsIds = new ArrayList<>();
goodsIds.add(goodsSku.getGoodsId());
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("更新商品", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.UPDATE_GOODS_INDEX.name(), goodsIds));
}
}
}

View File

@ -55,6 +55,10 @@ public enum GoodsTagsEnum {
* "收藏商品"
*/
GOODS_COLLECTION("收藏商品"),
/**
* 同步商品分类名称
*/
CATEGORY_GOODS_NAME("同步商品分类名称"),
/**
* "购买商品完成"
*/