一键清库存

This commit is contained in:
zhangji committed 2025-09-17 16:55:29 +08:00
1 parent f2ea57a57b
commit d199edb5ee
3 files changed
+51

No files matched your search

@@ -169,4 +169,12 @@ public class ProductSpuController {
return success(true);
}
@PutMapping("/one-click-clear")
@Operation(summary = "一键清空 SPU Stock")
@PreAuthorize("@ss.hasPermission('product:spu:update')")
public CommonResult<Boolean> oneClickClear(@RequestParam("deviceId") String deviceId) {
productSpuService.oneClickClear(deviceId);
return success(true);
}
}
@@ -154,4 +154,6 @@ public interface ProductSpuService {
List<ProductSpuDO> getSpuListByDeviceid(String deviceId);
void oneClickReplenishment(String deviceId);
void oneClickClear(String deviceId);
}
@@ -265,6 +265,47 @@ public class ProductSpuServiceImpl implements ProductSpuService {
}
}
@Override
public void oneClickClear(String deviceId) {
//商品列表
List<ProductSpuDO> spuList = productSpuMapper.getSpuListByDeviceid(deviceId);
if (spuList == null|| spuList.isEmpty()) {
throw exception(SKU_NOT_EXISTS);
}
for (ProductSpuDO spu : spuList) {
List<ProductSkuDO> skuListBySpuId = productSkuService.getSkuListBySpuId(spu.getId());
if (skuListBySpuId == null|| skuListBySpuId.isEmpty()){
throw exception(SKU_NOT_EXISTS);
}
ProductSkuUpdateStockReqVO updateSpuReqVO= new ProductSkuUpdateStockReqVO();
updateSpuReqVO.setId(spu.getId());
updateSpuReqVO.setStock(0);
// 更新 SPU 库存
int ispu = productSpuMapper.updateSpuStockById(updateSpuReqVO);
if (ispu>0) {
for (ProductSkuDO sku : skuListBySpuId) {
// 更新 SKU 库存
ProductSkuUpdateStockReqVO updateSkuReqVO = new ProductSkuUpdateStockReqVO();
updateSkuReqVO.setId(sku.getId());
updateSkuReqVO.setStock(0);
int isku = productSkuService.updateSkuStockById(updateSkuReqVO);
if (isku > 0) {
//添加库存log
StockLogSaveReqVO stockLogSaveReqVO = new StockLogSaveReqVO();
stockLogSaveReqVO.setDeviceId(spu.getDeviceId());
stockLogSaveReqVO.setSpuName(spu.getName());
stockLogSaveReqVO.setBarCode(sku.getBarCode());
stockLogSaveReqVO.setCabinetChannel(sku.getCabinetChannel());
stockLogSaveReqVO.setCount(updateSkuReqVO.getStock());
stockLogSaveReqVO.setOldStock(sku.getStock());
stockLogSaveReqVO.setNewStock(updateSkuReqVO.getStock());
stockLogService.createStockLog(stockLogSaveReqVO);
}
}
}
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteSpu(Long id) {