refactor(wms): 优化退库操作功能

- 修改退库操作接口路径,简化为 /returnStock
- 移除退库操作日志记录功能
This commit is contained in:
2025-08-12 10:50:12 +08:00
parent 5b4948c346
commit 1b5e4b4957
2 changed files with 16 additions and 26 deletions

View File

@@ -174,7 +174,7 @@ public class WmsStockIoController extends BaseController {
}
}
//退库操作
@PostMapping("/scanReturnStock")
@PostMapping("/returnStock")
public R<Void> scanReturnStock(@RequestBody WmsStockIoBo bo) {
try {
boolean result = iWmsStockIoService.scanReturnStockByBo(bo);

View File

@@ -195,31 +195,31 @@ public class WmsStockIoServiceImpl implements IWmsStockIoService {
if (bo.getStockIoId() == null) {
throw new ServiceException("退库单ID不能为空");
}
// 1. 获取退库单主表信息
WmsStockIo returnStockIo = baseMapper.selectById(bo.getStockIoId());
if (returnStockIo == null || returnStockIo.getParentId() == null) {
throw new ServiceException("退库单不存在或未关联原出库单");
}
// 2. 获取退库单明细列表
List<WmsStockIoDetail> returnDetails = stockIoDetailMapper.selectList(
Wrappers.<WmsStockIoDetail>lambdaQuery().eq(WmsStockIoDetail::getStockIoId, bo.getStockIoId())
);
if (returnDetails == null || returnDetails.isEmpty()) {
throw new ServiceException("退库单明细不能为空");
}
// 3. 获取原出库单明细列表
List<WmsStockIoDetail> originalOutDetails = stockIoDetailMapper.selectList(
Wrappers.<WmsStockIoDetail>lambdaQuery().eq(WmsStockIoDetail::getStockIoId, returnStockIo.getParentId())
);
if (originalOutDetails == null || originalOutDetails.isEmpty()) {
throw new ServiceException("原出库单明细不存在");
}
// 4. 遍历退库明细,验证数量并执行退库
for (WmsStockIoDetail returnDetail : returnDetails) {
// 查找对应的原出库明细
@@ -229,11 +229,11 @@ public class WmsStockIoServiceImpl implements IWmsStockIoService {
detail.getWarehouseId().equals(returnDetail.getWarehouseId()))
.findFirst()
.orElse(null);
if (originalOutDetail == null) {
throw new ServiceException("未找到对应的原出库明细:" + returnDetail.getItemType() + "-" + returnDetail.getItemId());
}
// 验证退库数量不能超过原出库数量
BigDecimal totalReturnedQty = baseMapper.selectList(
Wrappers.<WmsStockIo>lambdaQuery()
@@ -250,14 +250,14 @@ public class WmsStockIoServiceImpl implements IWmsStockIoService {
).stream())
.map(WmsStockIoDetail::getQuantity)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal remainingQty = originalOutDetail.getQuantity().subtract(totalReturnedQty);
if (returnDetail.getQuantity().compareTo(remainingQty) > 0) {
throw new ServiceException("退库数量超过原出库数量,物品:" + returnDetail.getItemType() + "-" + returnDetail.getItemId() +
",原出库数量:" + originalOutDetail.getQuantity() + ",已退库数量:" + totalReturnedQty +
throw new ServiceException("退库数量超过原出库数量,物品:" + returnDetail.getItemType() + "-" + returnDetail.getItemId() +
",原出库数量:" + originalOutDetail.getQuantity() + ",已退库数量:" + totalReturnedQty +
",剩余可退数量:" + remainingQty + ",本次退库数量:" + returnDetail.getQuantity());
}
// 执行退库操作(增加库存)
String unit = returnDetail.getUnit();
if (unit == null || unit.trim().isEmpty()) {
@@ -269,22 +269,12 @@ public class WmsStockIoServiceImpl implements IWmsStockIoService {
unit = r != null ? r.getUnit() : "";
}
}
// 执行入库操作(退库就是入库)
changeStock(returnDetail.getWarehouseId(), returnDetail.getItemType(),
changeStock(returnDetail.getWarehouseId(), returnDetail.getItemType(),
returnDetail.getItemId(), returnDetail.getQuantity(), true, unit);
// 记录退库操作日志
WmsStockLog returnLog = new WmsStockLog();
returnLog.setWarehouseId(returnDetail.getWarehouseId());
returnLog.setItemType(returnDetail.getItemType());
returnLog.setItemId(returnDetail.getItemId());
returnLog.setChangeQty(returnDetail.getQuantity());
returnLog.setChangeType("退库");
returnLog.setChangeTime(new Date());
stockLogMapper.insert(returnLog);
}
return true;
}