fix: 修复修改商品库存时,促销商品库存没有同步修改问题

This commit is contained in:
paulGao 2022-12-05 17:17:05 +08:00
parent f3ccabe253
commit ede7a37e37
4 changed files with 31 additions and 2 deletions

View File

@ -508,6 +508,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
List<GoodsSku> goodsSkus = new ArrayList<>(); List<GoodsSku> goodsSkus = new ArrayList<>();
goodsSkus.add(goodsSku); goodsSkus.add(goodsSku);
this.updateGoodsStuck(goodsSkus); this.updateGoodsStuck(goodsSkus);
this.promotionGoodsService.updatePromotionGoodsStock(goodsSku.getId(), quantity);
} }
} }

View File

@ -4,8 +4,7 @@ import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.*;
import lombok.EqualsAndHashCode;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -18,6 +17,9 @@ import java.util.List;
**/ **/
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Data @Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PromotionGoodsSearchParams extends BasePromotionsSearchParams { public class PromotionGoodsSearchParams extends BasePromotionsSearchParams {
@ApiModelProperty(value = "促销活动id") @ApiModelProperty(value = "促销活动id")

View File

@ -137,6 +137,14 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
*/ */
void updatePromotionGoodsStock(List<PromotionGoods> promotionGoodsList); void updatePromotionGoodsStock(List<PromotionGoods> promotionGoodsList);
/**
* 更新促销活动商品库存
*
* @param skuId 商品skuId
* @param quantity 库存
*/
void updatePromotionGoodsStock(String skuId, Integer quantity);
/** /**
* 更新促销活动商品索引 * 更新促销活动商品索引
* *

View File

@ -4,6 +4,7 @@ import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import cn.lili.cache.Cache;
import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.vo.PageVO; import cn.lili.common.vo.PageVO;
import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dos.GoodsSku;
@ -71,6 +72,9 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
@Autowired @Autowired
private EsGoodsIndexService goodsIndexService; private EsGoodsIndexService goodsIndexService;
@Autowired
private Cache cache;
@Override @Override
public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) { public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) {
@ -262,6 +266,20 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
} }
} }
@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);
}
/** /**
* 更新促销活动商品库存 * 更新促销活动商品库存
* *