|
|
@@ -328,17 +328,25 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
* @param dto 商品创建DTO
|
|
|
*/
|
|
|
private void saveProductSpecsAndSkus(Long productId, ProductCreateDTO dto) {
|
|
|
- List<ProductSpecDTO> specList = dto.getSpecList();
|
|
|
- List<ProductSkuDTO> skuList = dto.getSkuList();
|
|
|
+ //根据商品编号更新规格表中的商品ID
|
|
|
+ ProductSpec productSpec = new ProductSpec();
|
|
|
+ productSpec.setProductId(productId);
|
|
|
+ int update = productSpecMapper.update(productSpec, new LambdaQueryWrapper<ProductSpec>().eq(ProductSpec::getProductNo, dto.getProductNo()));
|
|
|
+ if (update == 0) {
|
|
|
+ throw new RuntimeException("商品规格更新失败");
|
|
|
+ }
|
|
|
|
|
|
- if (CollectionUtils.isEmpty(specList) || CollectionUtils.isEmpty(skuList)) {
|
|
|
- throw new RuntimeException("商品必须包含规格和SKU信息");
|
|
|
+ //根据商品编号更新规格值表中的商品ID
|
|
|
+ ProductSpecValue productSpecValue = new ProductSpecValue();
|
|
|
+ productSpecValue.setProductId(productId);
|
|
|
+ int update1 = productSpecValueMapper.update(productSpecValue, new LambdaQueryWrapper<ProductSpecValue>().eq(ProductSpecValue::getProductNo, dto.getProductNo()));
|
|
|
+ if (update1 == 0) {
|
|
|
+ throw new RuntimeException("商品规格值更新失败");
|
|
|
}
|
|
|
|
|
|
// 保存规格名和规格值
|
|
|
AtomicInteger specIndex = new AtomicInteger(0);
|
|
|
-
|
|
|
- for (ProductSpecDTO specDTO : specList) {
|
|
|
+ /*for (ProductSpecDTO specDTO : specList) {
|
|
|
// 保存规格名
|
|
|
ProductSpec spec = new ProductSpec();
|
|
|
spec.setProductId(productId);
|
|
|
@@ -365,8 +373,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
}
|
|
|
}
|
|
|
specIndex.getAndIncrement();
|
|
|
- }
|
|
|
-
|
|
|
+ }*/
|
|
|
+ List<ProductSkuDTO> skuList = dto.getSkuList();
|
|
|
// 保存SKU
|
|
|
for (ProductSkuDTO skuDTO : skuList) {
|
|
|
ProductSku sku = new ProductSku();
|
|
|
@@ -405,6 +413,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
if (StringUtils.isBlank(dto.getProductNo())) {
|
|
|
throw new RuntimeException("商品编号不能为空");
|
|
|
}
|
|
|
+ //删除商品规格
|
|
|
+ productSpecMapper.delete(new LambdaQueryWrapper<ProductSpec>().eq(ProductSpec::getProductNo, dto.getProductNo()));
|
|
|
+ //删除商品规格值
|
|
|
+ productSpecValueMapper.delete(new LambdaQueryWrapper<ProductSpecValue>().eq(ProductSpecValue::getProductNo, dto.getProductNo()));
|
|
|
+
|
|
|
// 保存新的规格
|
|
|
if (!CollectionUtils.isEmpty(dto.getSpecList())) {
|
|
|
AtomicInteger specIndex = new AtomicInteger(0);
|