删除权限注解,出入库移库
This commit is contained in:
@@ -14,6 +14,12 @@ import com.klp.domain.vo.WmsStockIoVo;
|
||||
import com.klp.domain.WmsStockIo;
|
||||
import com.klp.mapper.WmsStockIoMapper;
|
||||
import com.klp.service.IWmsStockIoService;
|
||||
import com.klp.domain.WmsStockIoDetail;
|
||||
import com.klp.domain.WmsStock;
|
||||
import com.klp.mapper.WmsStockIoDetailMapper;
|
||||
import com.klp.mapper.WmsStockMapper;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -30,6 +36,8 @@ import java.util.Collection;
|
||||
public class WmsStockIoServiceImpl implements IWmsStockIoService {
|
||||
|
||||
private final WmsStockIoMapper baseMapper;
|
||||
private final WmsStockIoDetailMapper stockIoDetailMapper;
|
||||
private final WmsStockMapper stockMapper;
|
||||
|
||||
/**
|
||||
* 查询出入库单主
|
||||
@@ -109,4 +117,81 @@ public class WmsStockIoServiceImpl implements IWmsStockIoService {
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核出入库/移库单,变更库存,含库存校验
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean auditStockIo(Long stockIoId) {
|
||||
WmsStockIo stockIo = baseMapper.selectById(stockIoId);
|
||||
if (stockIo == null || stockIo.getStatus() == null || stockIo.getStatus() != 1) {
|
||||
// 只允许审核“已提交”状态的单据
|
||||
throw new RuntimeException("单据不存在或状态不允许审核");
|
||||
}
|
||||
List<WmsStockIoDetail> details = stockIoDetailMapper.selectList(
|
||||
Wrappers.<WmsStockIoDetail>lambdaQuery().eq(WmsStockIoDetail::getStockIoId, stockIoId)
|
||||
);
|
||||
if (details == null || details.isEmpty()) {
|
||||
throw new RuntimeException("单据明细不能为空");
|
||||
}
|
||||
for (WmsStockIoDetail detail : details) {
|
||||
String ioType = stockIo.getIoType();
|
||||
if ("in".equals(ioType)) {
|
||||
// 入库:目标库位库存增加
|
||||
changeStock(detail.getWarehouseId(), detail.getItemType(), detail.getItemId(), detail.getBatchNo(), detail.getQuantity(), true, detail.getUnit());
|
||||
} else if ("out".equals(ioType)) {
|
||||
// 出库:目标库位库存减少
|
||||
changeStock(detail.getWarehouseId(), detail.getItemType(), detail.getItemId(), detail.getBatchNo(), detail.getQuantity(), false, detail.getUnit());
|
||||
} else if ("transfer".equals(ioType)) {
|
||||
// 移库:fromWarehouseId减少,warehouseId增加
|
||||
if (detail.getFromWarehouseId() == null) {
|
||||
throw new RuntimeException("移库明细缺少源库位ID");
|
||||
}
|
||||
// 先减少源库位
|
||||
changeStock(detail.getFromWarehouseId(), detail.getItemType(), detail.getItemId(), detail.getBatchNo(), detail.getQuantity(), false, detail.getUnit());
|
||||
// 再增加目标库位
|
||||
changeStock(detail.getWarehouseId(), detail.getItemType(), detail.getItemId(), detail.getBatchNo(), detail.getQuantity(), true, detail.getUnit());
|
||||
} else {
|
||||
throw new RuntimeException("未知的出入库类型");
|
||||
}
|
||||
}
|
||||
// 更新单据状态为已审核(2)
|
||||
stockIo.setStatus(2);
|
||||
baseMapper.updateById(stockIo);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 库存增减,isAdd=true为增加,false为减少,减少时校验库存是否足够
|
||||
*/
|
||||
private void changeStock(Long warehouseId, String itemType, Long itemId, String batchNo, BigDecimal quantity, boolean isAdd, String unit) {
|
||||
WmsStock stock = stockMapper.selectOne(Wrappers.<WmsStock>lambdaQuery()
|
||||
.eq(WmsStock::getWarehouseId, warehouseId)
|
||||
.eq(WmsStock::getItemType, itemType)
|
||||
.eq(WmsStock::getItemId, itemId)
|
||||
.eq(WmsStock::getBatchNo, batchNo)
|
||||
.last("limit 1"));
|
||||
if (stock == null) {
|
||||
if (!isAdd) {
|
||||
throw new RuntimeException("库存不足,无法出库/移库");
|
||||
}
|
||||
// 新增库存记录
|
||||
stock = new WmsStock();
|
||||
stock.setWarehouseId(warehouseId);
|
||||
stock.setItemType(itemType);
|
||||
stock.setItemId(itemId);
|
||||
stock.setBatchNo(batchNo);
|
||||
stock.setQuantity(quantity);
|
||||
stock.setUnit(unit);
|
||||
stockMapper.insert(stock);
|
||||
} else {
|
||||
BigDecimal newQty = isAdd ? stock.getQuantity().add(quantity) : stock.getQuantity().subtract(quantity);
|
||||
if (newQty.compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("库存不足,无法出库/移库");
|
||||
}
|
||||
stock.setQuantity(newQty);
|
||||
stockMapper.updateById(stock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user