Commit 7fb3f9857b8672492d56bc61907d4443013d02d3

Authored by puhui999
1 parent 33dc3294

【缺陷修复】商城: spu 更新会重置实际销量和浏览量的问题

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 78 @Transactional(rollbackFor = Exception.class)
79 79 public void updateSpu(ProductSpuSaveReqVO updateReqVO) {
80 80 // 校验 SPU 是否存在
81   - validateSpuExists(updateReqVO.getId());
  81 + ProductSpuDO spu = validateSpuExists(updateReqVO.getId());
82 82 // 校验分类、品牌
83 83 validateCategory(updateReqVO.getCategoryId());
84 84 brandService.validateProductBrand(updateReqVO.getBrandId());
... ... @@ -87,7 +87,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
87 87 productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType());
88 88  
89 89 // 更新 SPU
90   - ProductSpuDO updateObj = BeanUtils.toBean(updateReqVO, ProductSpuDO.class);
  90 + ProductSpuDO updateObj = BeanUtils.toBean(updateReqVO, ProductSpuDO.class).setStatus(spu.getStatus());
91 91 initSpuFromSkus(updateObj, skuSaveReqList);
92 92 productSpuMapper.updateById(updateObj);
93 93 // 批量更新 SKU
... ... @@ -176,10 +176,12 @@ public class ProductSpuServiceImpl implements ProductSpuService {
176 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 182 throw exception(SPU_NOT_EXISTS);
182 183 }
  184 + return spuDO;
183 185 }
184 186  
185 187 @Override
... ...