移除已经迁移的商城代码
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
### /product/spu/get 获得商品 SPU
|
||||
GET http://localhost:38082/product/spu/get?productSpuId=32
|
||||
###
|
||||
|
||||
### /product/spu/get 获得商品 SPU
|
||||
GET http://localhost:38082/product/spu/lislistProductSpuIdst?lastSpuId=30&limit=10
|
||||
###
|
||||
|
||||
|
||||
### /product/spu/get 获得商品 SPU
|
||||
GET http://localhost:38082/product/spu/getProductSpuDetail?productSpuId=32&fields=attr,sku
|
||||
###
|
||||
|
||||
@@ -31,24 +31,6 @@ public class ProductSpuController {
|
||||
return success(productSpuManager.getProductSpu(productSpuId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品 SPU
|
||||
*
|
||||
* @param updateDTO 更新商品 SPU DTO
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("更新商品 SPU")
|
||||
public CommonResult<Boolean> updateProductSpu(@Valid @RequestBody ProductSpuAndSkuUpdateReqDTO updateDTO) {
|
||||
productSpuManager.updateProductSpu(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建商品 SPU")
|
||||
public CommonResult<Integer> createProductSpu(@Valid @RequestBody ProductSpuAndSkuCreateReqDTO createDTO) {
|
||||
return success(productSpuManager.createProductSpu(createDTO));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得商品 SPU 列表")
|
||||
@ApiImplicitParam(name = "productSpuIds", value = "商品 SPU 编号列表", required = true)
|
||||
|
||||
@@ -51,69 +51,6 @@ public class ProductSpuManager {
|
||||
@Autowired
|
||||
private ProductMQProducer productMQProducer;
|
||||
|
||||
private static ProductSpuManager self() {
|
||||
return (ProductSpuManager) AopContext.currentProxy();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品 SPU 和 SKU
|
||||
*
|
||||
* @param createDTO 创建商品 SPU 和 SKU DTO
|
||||
* @return 商品 SPU
|
||||
*/
|
||||
public Integer createProductSpu(ProductSpuAndSkuCreateReqDTO createDTO) {
|
||||
// 创建商品 SPU 和 SKU。注意,这里要调用 self() 方法,因为需要创建事务,否则会失效
|
||||
Integer spuId = self().createProductSpu0(createDTO);
|
||||
// 发送商品创建的 MQ 消息
|
||||
productMQProducer.sendProductUpdateMessage(spuId);
|
||||
return spuId;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Integer createProductSpu0(ProductSpuAndSkuCreateReqDTO createDTO) {
|
||||
// 校验商品分类是否合法
|
||||
this.checkProductCategory(createDTO.getCid());
|
||||
// 创建商品 SKU 对象,并进行校验
|
||||
List<ProductSkuCreateOrUpdateBO> skuBOs = ProductSpuConvert.INSTANCE.convert(createDTO.getSkus());
|
||||
this.checkProductAttr(skuBOs);
|
||||
// 插入商品 SPU 记录
|
||||
ProductSpuCreateBO spuCreateBO = ProductSpuConvert.INSTANCE.convert(createDTO).setSort(0);
|
||||
spuCreateBO.setPrice(skuBOs.stream().min(Comparator.comparing(ProductSkuCreateOrUpdateBO::getPrice)).get().getPrice()); // 求最小价格
|
||||
spuCreateBO.setQuantity(skuBOs.stream().mapToInt(ProductSkuCreateOrUpdateBO::getQuantity).sum()); // 求库存之和
|
||||
ProductSpuBO spuBO = productSpuService.createProductSpu(spuCreateBO);
|
||||
// 插入商品 SKU 记录
|
||||
productSkuService.createProductSkus(spuBO.getId(), skuBOs);
|
||||
return spuBO.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品 SPU
|
||||
*
|
||||
* @param updateDTO 更新商品 SPU DTO
|
||||
*/
|
||||
public void updateProductSpu(ProductSpuAndSkuUpdateReqDTO updateDTO) {
|
||||
// 更新商品 SPU 和 SKU。注意,这里要调用 self() 方法,因为需要创建事务,否则会失效
|
||||
self().updateProductSpu0(updateDTO);
|
||||
// 发送商品创建的 MQ 消息
|
||||
productMQProducer.sendProductUpdateMessage(updateDTO.getId());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateProductSpu0(ProductSpuAndSkuUpdateReqDTO updateDTO) {
|
||||
// 校验商品分类是否合法
|
||||
this.checkProductCategory(updateDTO.getCid());
|
||||
// 创建商品 SKU 对象,并进行校验
|
||||
List<ProductSkuCreateOrUpdateBO> skuBOs = ProductSpuConvert.INSTANCE.convert02(updateDTO.getSkus());
|
||||
this.checkProductAttr(skuBOs);
|
||||
// 更新商品 SPU 记录
|
||||
ProductSpuUpdateBO spuUpdateBO = ProductSpuConvert.INSTANCE.convert(updateDTO);
|
||||
spuUpdateBO.setPrice(skuBOs.stream().min(Comparator.comparing(ProductSkuCreateOrUpdateBO::getPrice)).get().getPrice()); // 求最小价格
|
||||
spuUpdateBO.setQuantity(skuBOs.stream().mapToInt(ProductSkuCreateOrUpdateBO::getQuantity).sum()); // 求库存之和
|
||||
productSpuService.updateProductSpu(spuUpdateBO);
|
||||
// 更新商品 SKU 记录
|
||||
productSkuService.updateProductSkus(updateDTO.getId(), skuBOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品 SPU
|
||||
*
|
||||
|
||||
@@ -31,44 +31,6 @@ public class ProductSkuService {
|
||||
productSkuMapper.insertList(skus);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateProductSkus(Integer spuId, List<ProductSkuCreateOrUpdateBO> skuUpdateBOs) {
|
||||
List<ProductSkuDO> existsSkus = productSkuMapper.selectListBySpuIdAndStatus(spuId,
|
||||
CommonStatusEnum.ENABLE.getValue());
|
||||
List<ProductSkuDO> insertSkus = new ArrayList<>(); // 1、找不到,进行插入
|
||||
List<Integer> deleteSkus = new ArrayList<>(); // 2、多余的,删除
|
||||
List<ProductSkuDO> updateSkus = new ArrayList<>(); // 3、找的到,进行更新。
|
||||
for (ProductSkuCreateOrUpdateBO skuUpdateDTO : skuUpdateBOs) {
|
||||
ProductSkuDO existsSku = findProductSku(skuUpdateDTO.getAttrValueIds(), existsSkus);
|
||||
// 3、找的到,进行更新。
|
||||
if (existsSku != null) {
|
||||
// 移除
|
||||
existsSkus.remove(existsSku);
|
||||
// 创建 ProductSkuDO
|
||||
updateSkus.add(ProductSkuConvert.INSTANCE.convert(skuUpdateDTO).setId(existsSku.getId()));
|
||||
continue;
|
||||
}
|
||||
// 1、找不到,进行插入
|
||||
ProductSkuDO insertSku = ProductSkuConvert.INSTANCE.convert(skuUpdateDTO)
|
||||
.setSpuId(spuId).setStatus(CommonStatusEnum.ENABLE.getValue());
|
||||
insertSkus.add(insertSku);
|
||||
}
|
||||
// 2、多余的,删除
|
||||
if (!existsSkus.isEmpty()) {
|
||||
deleteSkus.addAll(existsSkus.stream().map(ProductSkuDO::getId).collect(Collectors.toList()));
|
||||
}
|
||||
// 执行修改 Sku
|
||||
if (!insertSkus.isEmpty()) {
|
||||
productSkuMapper.insertList(insertSkus);
|
||||
}
|
||||
if (!updateSkus.isEmpty()) {
|
||||
updateSkus.forEach(productSkuDO -> productSkuMapper.updateById(productSkuDO));
|
||||
}
|
||||
if (!deleteSkus.isEmpty()) {
|
||||
productSkuMapper.deleteBatchIds(deleteSkus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 sku 数组中,指定规格的 sku
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user