fix: 足迹为空展示空信息问题,商品库存回滚数量错误问题
This commit is contained in:
parent
794fa63302
commit
bda72da679
@ -153,9 +153,8 @@ public interface GoodsService extends IService<Goods> {
|
||||
* 修改商品库存数量
|
||||
*
|
||||
* @param goodsId 商品ID
|
||||
* @param quantity 库存数量
|
||||
*/
|
||||
void updateStock(String goodsId, Integer quantity);
|
||||
void updateStock(String goodsId);
|
||||
|
||||
/**
|
||||
* 更新商品评价数量
|
||||
|
@ -271,4 +271,12 @@ public interface GoodsSkuService extends IService<GoodsSku> {
|
||||
* @param commentNum 评论数量
|
||||
*/
|
||||
void updateGoodsSkuGrade(String goodsId, double grade,int commentNum);
|
||||
|
||||
/**
|
||||
* 获取最新商品库存
|
||||
*
|
||||
* @param goodsId 商品ID
|
||||
* @return 库存数量
|
||||
*/
|
||||
Integer getGoodsStock(String goodsId);
|
||||
}
|
@ -441,10 +441,11 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
@SystemLogPoint(description = "修改商品库存", customerLog = "'操作的商品ID:['+#goodsId+'],修改后的库存:['+#quantity+']'")
|
||||
public void updateStock(String goodsId, Integer quantity) {
|
||||
@SystemLogPoint(description = "同步商品库存", customerLog = "'同步商品商品ID的库存:['+#goodsId+']'")
|
||||
public void updateStock(String goodsId) {
|
||||
LambdaUpdateWrapper<Goods> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
||||
lambdaUpdateWrapper.set(Goods::getQuantity, quantity);
|
||||
Integer stock = goodsSkuService.getGoodsStock(goodsId);
|
||||
lambdaUpdateWrapper.set(Goods::getQuantity, stock);
|
||||
lambdaUpdateWrapper.eq(Goods::getId, goodsId);
|
||||
cache.remove(CachePrefix.GOODS.getPrefix() + goodsId);
|
||||
this.update(lambdaUpdateWrapper);
|
||||
|
@ -519,16 +519,13 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
//统计每个商品的库存
|
||||
for (Map.Entry<String, List<GoodsSkuStockDTO>> entry : groupByGoodsIds.entrySet()) {
|
||||
//库存
|
||||
Integer quantity = 0;
|
||||
for (GoodsSkuStockDTO goodsSku : entry.getValue()) {
|
||||
goodsSkuStockDTOS.stream().filter(i -> i.getSkuId().equals(goodsSku.getSkuId())).findFirst().ifPresent(i -> goodsSku.setQuantity(i.getQuantity()));
|
||||
if (entry.getKey().equals(goodsSku.getGoodsId())) {
|
||||
quantity += goodsSku.getQuantity();
|
||||
}
|
||||
|
||||
this.updateStock(goodsSku.getSkuId(), goodsSku.getQuantity());
|
||||
}
|
||||
//保存商品库存结果
|
||||
goodsService.updateStock(entry.getKey(), quantity);
|
||||
goodsService.updateStock(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@ -588,7 +585,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
if (isFlag && CharSequenceUtil.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));
|
||||
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("更新商品", rocketmqCustomProperties.getGoodsTopic(),
|
||||
GoodsTagsEnum.UPDATE_GOODS_INDEX.name(), goodsIds));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -622,7 +620,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
this.updateStock(goodsSku.getId(), goodsSku.getQuantity());
|
||||
}
|
||||
//保存商品库存结果
|
||||
goodsService.updateStock(goodsId, quantity);
|
||||
goodsService.updateStock(goodsId);
|
||||
}
|
||||
|
||||
|
||||
@ -656,7 +654,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
public Long countSkuNum(String storeId) {
|
||||
LambdaQueryWrapper<GoodsSku> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
queryWrapper.eq(GoodsSku::getStoreId, storeId).eq(GoodsSku::getDeleteFlag, Boolean.FALSE).eq(GoodsSku::getAuthFlag, GoodsAuthEnum.PASS.name()).eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name());
|
||||
queryWrapper.eq(GoodsSku::getStoreId, storeId).eq(GoodsSku::getDeleteFlag, Boolean.FALSE).eq(GoodsSku::getAuthFlag,
|
||||
GoodsAuthEnum.PASS.name()).eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name());
|
||||
return this.count(queryWrapper);
|
||||
}
|
||||
|
||||
@ -695,6 +694,19 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
this.getSkuIdsByGoodsId(goodsId).forEach(this::clearCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getGoodsStock(String goodsId) {
|
||||
List<String> skuIds = this.getSkuIdsByGoodsId(goodsId);
|
||||
|
||||
Integer stock = 0;
|
||||
|
||||
for (String skuId : skuIds) {
|
||||
stock += this.getStock(skuId);
|
||||
}
|
||||
return stock;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染商品sku
|
||||
*
|
||||
|
@ -85,17 +85,16 @@ public class FootprintServiceImpl extends ServiceImpl<FootprintMapper, FootPrint
|
||||
List<EsGoodsIndex> collect = IntStream.range(0, goodsSkuByIdFromCache.size())
|
||||
.mapToObj(i -> {
|
||||
if (goodsSkuByIdFromCache.get(i) == null) {
|
||||
EsGoodsIndex esGoodsIndex = new EsGoodsIndex();
|
||||
FootPrint footPrint = footPrintPages.getRecords().get(i);
|
||||
esGoodsIndex.setGoodsId(footPrint.getGoodsId());
|
||||
esGoodsIndex.setId(footPrint.getSkuId());
|
||||
esGoodsIndex.setReleaseTime(footPrintPages.getRecords().get(i).getCreateTime().getTime());
|
||||
return esGoodsIndex;
|
||||
return null;
|
||||
}
|
||||
Optional<FootPrint> first = footPrintPages.getRecords().stream().filter(j -> j.getSkuId().equals(goodsSkuByIdFromCache.get(i).getId())).findFirst();
|
||||
Optional<FootPrint> first =
|
||||
footPrintPages.getRecords().stream().filter(j -> j.getSkuId().equals(goodsSkuByIdFromCache.get(i).getId())).findFirst();
|
||||
return first.map(footPrint -> new EsGoodsIndex(goodsSkuByIdFromCache.get(i), footPrint.getCreateTime())).orElseGet(() -> new EsGoodsIndex(goodsSkuByIdFromCache.get(i)));
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
collect.removeIf(Objects::isNull);
|
||||
|
||||
esGoodsIndexIPage.setPages(footPrintPages.getPages());
|
||||
esGoodsIndexIPage.setRecords(collect);
|
||||
esGoodsIndexIPage.setTotal(footPrintPages.getTotal());
|
||||
|
Loading…
x
Reference in New Issue
Block a user