|
@@ -133,73 +133,101 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
|
}
|
|
|
List<WmsDocOrderDetails> orderDetails = orderHeader.getWmsDocOrderDetailsList();
|
|
|
for (WmsDocOrderDetails o : orderDetails) {
|
|
|
- wmsDocOrderHeaderService.doAllocationDetails(o);
|
|
|
+ wmsDocOrderHeaderService.doAllocationDetails(orderHeader, o);
|
|
|
}
|
|
|
return AjaxResult.success("分配完成");
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
- public AjaxResult doAllocationDetails(WmsDocOrderDetails details) {
|
|
|
- List<InvLotLocId> invList = invLotLocIdService.queryInvOrderBy(details.getLotnum(), details.getSku(), details.getLocation(), details.getCustomerId());
|
|
|
- //库存可分配数小于订单数
|
|
|
- BigDecimal orderQty = details.getQtyOrdered();
|
|
|
- //判断总数是否足够分配
|
|
|
- double qtySum = invList.stream().mapToDouble(item -> item.getQty().doubleValue() > item.getQtyallocated().doubleValue() ? item.getQty().doubleValue() : 0).sum();
|
|
|
- if (qtySum < orderQty.doubleValue()) {
|
|
|
- return AjaxResult.error("库存不足分配失败");
|
|
|
+ public AjaxResult doAllocation(List<String> orderNoList) {
|
|
|
+ for (String s : orderNoList) {
|
|
|
+ wmsDocOrderHeaderService.doAllocation(s);
|
|
|
}
|
|
|
- for (InvLotLocId inv : invList) {
|
|
|
- if (orderQty.doubleValue() == 0) {
|
|
|
- return AjaxResult.success("分配完成");
|
|
|
+ return AjaxResult.success("分配成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult doAllocationDetails(WmsDocOrderHeader header, WmsDocOrderDetails details) {
|
|
|
+ if (header.getOrderType().equals("")) {
|
|
|
+ List<InvLotLocId> invList = invLotLocIdService.queryInvByFull(header.getOrderNo(), details.getSku());
|
|
|
+ BigDecimal totalQty = BigDecimal.ZERO;
|
|
|
+ for (InvLotLocId inv : invList) {
|
|
|
+ //可以分配的库存
|
|
|
+ inv.setQtyallocated(inv.getQty());
|
|
|
+ inv.setQtyallocatedEach(inv.getQtyEach());
|
|
|
+
|
|
|
+ if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
|
|
|
+ totalQty.add(inv.getQty());
|
|
|
+ //修改出库单状态
|
|
|
+ details.setQtyAllocated(details.getQtyAllocated().add(inv.getQty()));
|
|
|
+ wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
|
+ //生成分配明细
|
|
|
+ return actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), inv.getQty(), details);
|
|
|
+ }
|
|
|
}
|
|
|
- BigDecimal canallocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
|
- if (canallocatedQty.doubleValue() > 0) {
|
|
|
- if (inv.getQty().intValue() > 0) {
|
|
|
- if (inv.getQty().subtract(inv.getQtyallocated()).compareTo(orderQty) == -1) {
|
|
|
- //可以分配的库存
|
|
|
- BigDecimal allocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
|
- inv.setQtyallocated(inv.getQtyallocated().add(allocatedQty));
|
|
|
- inv.setQtyallocatedEach(inv.getQtyallocatedEach().add(allocatedQty));
|
|
|
- if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
|
|
|
- orderQty = orderQty.subtract(allocatedQty);
|
|
|
- //修改出库单状态
|
|
|
- details.setQtyAllocated(details.getQtyAllocated().add(allocatedQty));
|
|
|
- wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
|
-
|
|
|
- //生成分配明细
|
|
|
- return actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details);
|
|
|
- } else {
|
|
|
- continue;
|
|
|
- }
|
|
|
- } else if (inv.getQty().subtract(inv.getQtyallocated()).compareTo(orderQty) == 0) {
|
|
|
- //可以分配的库存
|
|
|
- BigDecimal allocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
|
- inv.setQtyallocated(inv.getQtyallocated().add(allocatedQty));
|
|
|
- inv.setQtyallocatedEach(inv.getQtyallocatedEach().add(allocatedQty));
|
|
|
- if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
|
|
|
- orderQty = orderQty.subtract(allocatedQty);
|
|
|
- //修改出库单状态
|
|
|
- //修改出库单状态
|
|
|
- details.setQtyAllocated(details.getQtyAllocated().add(allocatedQty));
|
|
|
- wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
|
-
|
|
|
- //生成分配明细
|
|
|
- return actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details);
|
|
|
- } else {
|
|
|
- return AjaxResult.error("占用库存分配数失败");
|
|
|
- }
|
|
|
- } else {
|
|
|
- BigDecimal currentQty = orderQty;
|
|
|
- inv.setQtyallocated(inv.getQtyallocated().add(currentQty));
|
|
|
- inv.setQtyallocatedEach(inv.getQtyallocatedEach().add(currentQty));
|
|
|
- if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
|
|
|
- //修改出库单状态
|
|
|
- details.setQtyAllocated(details.getQtyAllocated().add(currentQty));
|
|
|
- wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
|
- //生成分配明细
|
|
|
- return actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), currentQty, details);
|
|
|
+ } else {
|
|
|
+ List<InvLotLocId> invList = invLotLocIdService.queryInvOrderBy(details.getLotnum(), details.getSku(), details.getLocation(), details.getCustomerId());
|
|
|
+ //库存可分配数小于订单数
|
|
|
+ BigDecimal orderQty = details.getQtyOrdered();
|
|
|
+ //判断总数是否足够分配
|
|
|
+ double qtySum = invList.stream().mapToDouble(item -> item.getQty().doubleValue() > item.getQtyallocated().doubleValue() ? item.getQty().doubleValue() : 0).sum();
|
|
|
+ if (qtySum < orderQty.doubleValue()) {
|
|
|
+ return AjaxResult.error("库存不足分配失败");
|
|
|
+ }
|
|
|
+ for (InvLotLocId inv : invList) {
|
|
|
+ if (orderQty.doubleValue() == 0) {
|
|
|
+ return AjaxResult.success("分配完成");
|
|
|
+ }
|
|
|
+ BigDecimal canallocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
|
+ if (canallocatedQty.doubleValue() > 0) {
|
|
|
+ if (inv.getQty().intValue() > 0) {
|
|
|
+ if (inv.getQty().subtract(inv.getQtyallocated()).compareTo(orderQty) == -1) {
|
|
|
+ //可以分配的库存
|
|
|
+ BigDecimal allocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
|
+ inv.setQtyallocated(inv.getQtyallocated().add(allocatedQty));
|
|
|
+ inv.setQtyallocatedEach(inv.getQtyallocatedEach().add(allocatedQty));
|
|
|
+ if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
|
|
|
+ orderQty = orderQty.subtract(allocatedQty);
|
|
|
+ //修改出库单状态
|
|
|
+ details.setQtyAllocated(details.getQtyAllocated().add(allocatedQty));
|
|
|
+ wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
|
+
|
|
|
+ //生成分配明细
|
|
|
+ return actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details);
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } else if (inv.getQty().subtract(inv.getQtyallocated()).compareTo(orderQty) == 0) {
|
|
|
+ //可以分配的库存
|
|
|
+ BigDecimal allocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
|
+ inv.setQtyallocated(inv.getQtyallocated().add(allocatedQty));
|
|
|
+ inv.setQtyallocatedEach(inv.getQtyallocatedEach().add(allocatedQty));
|
|
|
+ if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
|
|
|
+ orderQty = orderQty.subtract(allocatedQty);
|
|
|
+ //修改出库单状态
|
|
|
+ //修改出库单状态
|
|
|
+ details.setQtyAllocated(details.getQtyAllocated().add(allocatedQty));
|
|
|
+ wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
|
+
|
|
|
+ //生成分配明细
|
|
|
+ return actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details);
|
|
|
+ } else {
|
|
|
+ return AjaxResult.error("占用库存分配数失败");
|
|
|
+ }
|
|
|
} else {
|
|
|
- return AjaxResult.error("占用库存分配数失败");
|
|
|
+ BigDecimal currentQty = orderQty;
|
|
|
+ inv.setQtyallocated(inv.getQtyallocated().add(currentQty));
|
|
|
+ inv.setQtyallocatedEach(inv.getQtyallocatedEach().add(currentQty));
|
|
|
+ if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
|
|
|
+ //修改出库单状态
|
|
|
+ details.setQtyAllocated(details.getQtyAllocated().add(currentQty));
|
|
|
+ wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
|
+ //生成分配明细
|
|
|
+ return actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), currentQty, details);
|
|
|
+ } else {
|
|
|
+ return AjaxResult.error("占用库存分配数失败");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|