Skip to content

Commit

Permalink
fix: 修复修改商品库存时,促销商品库存没有同步修改问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LeiGaoRobot committed Dec 5, 2022
1 parent f3ccabe commit ede7a37
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ public void updateStock(String skuId, Integer quantity) {
List<GoodsSku> goodsSkus = new ArrayList<>();
goodsSkus.add(goodsSku);
this.updateGoodsStuck(goodsSkus);
this.promotionGoodsService.updatePromotionGoodsStock(goodsSku.getId(), quantity);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.*;

import java.util.Arrays;
import java.util.List;
Expand All @@ -18,6 +17,9 @@
**/
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PromotionGoodsSearchParams extends BasePromotionsSearchParams {

@ApiModelProperty(value = "促销活动id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ static String getPromotionGoodsStockCacheKey(PromotionTypeEnum typeEnum, String
*/
void updatePromotionGoodsStock(List<PromotionGoods> promotionGoodsList);

/**
* 更新促销活动商品库存
*
* @param skuId 商品skuId
* @param quantity 库存
*/
void updatePromotionGoodsStock(String skuId, Integer quantity);

/**
* 更新促销活动商品索引
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.lili.cache.Cache;
import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.goods.entity.dos.GoodsSku;
Expand Down Expand Up @@ -71,6 +72,9 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
@Autowired
private EsGoodsIndexService goodsIndexService;

@Autowired
private Cache cache;

@Override
public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) {

Expand Down Expand Up @@ -262,6 +266,20 @@ public void updatePromotionGoodsStock(List<PromotionGoods> promotionGoodsList) {
}
}

@Override
public void updatePromotionGoodsStock(String skuId, Integer quantity) {
LambdaQueryWrapper<PromotionGoods> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PromotionGoods::getSkuId, skuId);
this.list(queryWrapper).forEach(promotionGoods -> {
String promotionStockKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(PromotionTypeEnum.valueOf(promotionGoods.getPromotionType()), promotionGoods.getPromotionId(), promotionGoods.getSkuId());
cache.remove(promotionStockKey);
});
LambdaUpdateWrapper<PromotionGoods> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(PromotionGoods::getSkuId, skuId);
updateWrapper.set(PromotionGoods::getQuantity, quantity);
this.update(updateWrapper);
}

/**
* 更新促销活动商品库存
*
Expand Down

0 comments on commit ede7a37

Please sign in to comment.