!157 优化修改sku时,如存在sku则不新增

Merge pull request !157 from OceansDeep/feature/pg
This commit is contained in:
OceansDeep 2022-05-13 03:09:18 +00:00 committed by Gitee
commit b683eac996
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 26 additions and 4 deletions

View File

@ -36,4 +36,11 @@ public interface GoodsGalleryService extends IService<GoodsGallery> {
*/
List<GoodsGallery> goodsGalleryList(String goodsId);
/**
* 根据商品 id删除商品相册缩略图
*
* @param goodsId 商品ID
*/
void removeByGoodsId(String goodsId);
}

View File

@ -75,4 +75,14 @@ public class GoodsGalleryServiceImpl extends ServiceImpl<GoodsGalleryMapper, Goo
//根据商品id查询商品相册
return this.baseMapper.selectList(new QueryWrapper<GoodsGallery>().eq("goods_id", goodsId));
}
/**
* 根据商品 id删除商品相册缩略图
*
* @param goodsId 商品ID
*/
@Override
public void removeByGoodsId(String goodsId) {
this.baseMapper.delete(new UpdateWrapper<GoodsGallery>().eq("goods_id", goodsId));
}
}

View File

@ -149,10 +149,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
oldSkuIds.add(goodsSkuVO.getId());
cache.remove(GoodsSkuService.getCacheKeys(goodsSkuVO.getId()));
}
goodsIndexService.deleteIndexByIds(oldSkuIds);
this.removeByIds(oldSkuIds);
//删除sku相册
goodsGalleryService.removeByIds(oldSkuIds);
goodsGalleryService.removeByGoodsId(goods.getId());
// 添加商品sku
newSkuList = this.addGoodsSku(skuList, goods);
@ -162,7 +161,13 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
} else {
newSkuList = new ArrayList<>();
for (Map<String, Object> map : skuList) {
GoodsSku sku = new GoodsSku();
GoodsSku sku = null;
if (map.get("id") != null) {
sku = this.getGoodsSkuByIdFromCache(map.get("id").toString());
}
if (sku == null || map.get("id") == null) {
sku = new GoodsSku();
}
//设置商品信息
goodsInfo(sku, goods);
//设置商品规格信息
@ -627,7 +632,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
skus.add(goodsSku);
cache.put(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity());
}
this.saveBatch(skus);
this.saveOrUpdateBatch(skus);
return skus;
}