Commit 7fb3f9857b8672492d56bc61907d4443013d02d3
1 parent
33dc3294
【缺陷修复】商城: spu 更新会重置实际销量和浏览量的问题
Showing
1 changed file
with
6 additions
and
4 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| @@ -78,7 +78,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -78,7 +78,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 78 | @Transactional(rollbackFor = Exception.class) | 78 | @Transactional(rollbackFor = Exception.class) |
| 79 | public void updateSpu(ProductSpuSaveReqVO updateReqVO) { | 79 | public void updateSpu(ProductSpuSaveReqVO updateReqVO) { |
| 80 | // 校验 SPU 是否存在 | 80 | // 校验 SPU 是否存在 |
| 81 | - validateSpuExists(updateReqVO.getId()); | 81 | + ProductSpuDO spu = validateSpuExists(updateReqVO.getId()); |
| 82 | // 校验分类、品牌 | 82 | // 校验分类、品牌 |
| 83 | validateCategory(updateReqVO.getCategoryId()); | 83 | validateCategory(updateReqVO.getCategoryId()); |
| 84 | brandService.validateProductBrand(updateReqVO.getBrandId()); | 84 | brandService.validateProductBrand(updateReqVO.getBrandId()); |
| @@ -87,7 +87,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -87,7 +87,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 87 | productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType()); | 87 | productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType()); |
| 88 | 88 | ||
| 89 | // 更新 SPU | 89 | // 更新 SPU |
| 90 | - ProductSpuDO updateObj = BeanUtils.toBean(updateReqVO, ProductSpuDO.class); | 90 | + ProductSpuDO updateObj = BeanUtils.toBean(updateReqVO, ProductSpuDO.class).setStatus(spu.getStatus()); |
| 91 | initSpuFromSkus(updateObj, skuSaveReqList); | 91 | initSpuFromSkus(updateObj, skuSaveReqList); |
| 92 | productSpuMapper.updateById(updateObj); | 92 | productSpuMapper.updateById(updateObj); |
| 93 | // 批量更新 SKU | 93 | // 批量更新 SKU |
| @@ -176,10 +176,12 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -176,10 +176,12 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 176 | productSkuService.deleteSkuBySpuId(id); | 176 | productSkuService.deleteSkuBySpuId(id); |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | - private void validateSpuExists(Long id) { | ||
| 180 | - if (productSpuMapper.selectById(id) == null) { | 179 | + private ProductSpuDO validateSpuExists(Long id) { |
| 180 | + ProductSpuDO spuDO = productSpuMapper.selectById(id); | ||
| 181 | + if (spuDO == null) { | ||
| 181 | throw exception(SPU_NOT_EXISTS); | 182 | throw exception(SPU_NOT_EXISTS); |
| 182 | } | 183 | } |
| 184 | + return spuDO; | ||
| 183 | } | 185 | } |
| 184 | 186 | ||
| 185 | @Override | 187 | @Override |