1.修改商品分类同步分类名称 2.修改店铺名称同步对应店铺名称场景
This commit is contained in:
@@ -184,4 +184,10 @@ public interface GoodsService extends IService<Goods> {
|
||||
*/
|
||||
long countStoreGoodsNum(String storeId);
|
||||
|
||||
/**
|
||||
* 同步商品分类名称
|
||||
*
|
||||
* @param categoryId 分类ID
|
||||
*/
|
||||
void categoryGoodsName(String categoryId);
|
||||
}
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新商品状态
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,10 @@ public enum GoodsTagsEnum {
|
||||
* "收藏商品"
|
||||
*/
|
||||
GOODS_COLLECTION("收藏商品"),
|
||||
/**
|
||||
* 同步商品分类名称
|
||||
*/
|
||||
CATEGORY_GOODS_NAME("同步商品分类名称"),
|
||||
/**
|
||||
* "购买商品完成"
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user