|
@@ -225,7 +225,8 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
if (orderHeader == null) {
|
|
if (orderHeader == null) {
|
|
return AjaxResult.error("没有查询到订单");
|
|
return AjaxResult.error("没有查询到订单");
|
|
}
|
|
}
|
|
- if (!orderHeader.getOrderStatus().equals("00")) {
|
|
|
|
|
|
+ // TODO 改成可以部分分配
|
|
|
|
+ if (!orderHeader.getOrderStatus().equals(Constant.ORDER_STS.STS00.getValue())) {
|
|
return AjaxResult.error("出库单为创建状态才可以分配");
|
|
return AjaxResult.error("出库单为创建状态才可以分配");
|
|
}
|
|
}
|
|
boolean isbf = false;
|
|
boolean isbf = false;
|
|
@@ -233,7 +234,7 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
BigDecimal total = BigDecimal.ZERO;
|
|
BigDecimal total = BigDecimal.ZERO;
|
|
List<WmsDocOrderDetails> orderDetails = orderHeader.getWmsDocOrderDetailsList();
|
|
List<WmsDocOrderDetails> orderDetails = orderHeader.getWmsDocOrderDetailsList();
|
|
for (WmsDocOrderDetails o : orderDetails) {
|
|
for (WmsDocOrderDetails o : orderDetails) {
|
|
- total = total.add(o.getQtyOrdered());
|
|
|
|
|
|
+ total = total.add(o.getQtyOrdered().subtract(o.getQtyAllocated()));
|
|
}
|
|
}
|
|
for (WmsDocOrderDetails o : orderDetails) {
|
|
for (WmsDocOrderDetails o : orderDetails) {
|
|
AjaxResult result = wmsDocOrderHeaderService.doAllocationDetails(orderHeader, o);
|
|
AjaxResult result = wmsDocOrderHeaderService.doAllocationDetails(orderHeader, o);
|
|
@@ -249,12 +250,13 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (isbf) {
|
|
if (isbf) {
|
|
- orderHeader.setOrderStatus("10");
|
|
|
|
|
|
+ orderHeader.setOrderStatus(Constant.ORDER_STS.STS10.getValue());
|
|
wmsDocOrderHeaderService.updateWmsDocOrderHeader(orderHeader);
|
|
wmsDocOrderHeaderService.updateWmsDocOrderHeader(orderHeader);
|
|
|
|
+ // TODO 改成可以部分分配
|
|
throw new ServiceException("库存数量不足,分配失败!" + orderNo);
|
|
throw new ServiceException("库存数量不足,分配失败!" + orderNo);
|
|
}
|
|
}
|
|
if (isAllocation) {
|
|
if (isAllocation) {
|
|
- orderHeader.setOrderStatus("20");
|
|
|
|
|
|
+ orderHeader.setOrderStatus(Constant.ORDER_STS.STS20.getValue());
|
|
wmsDocOrderHeaderService.updateWmsDocOrderHeader(orderHeader);
|
|
wmsDocOrderHeaderService.updateWmsDocOrderHeader(orderHeader);
|
|
return AjaxResult.success("分配成功");
|
|
return AjaxResult.success("分配成功");
|
|
} else {
|
|
} else {
|
|
@@ -278,10 +280,18 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
return AjaxResult.success("分配成功");
|
|
return AjaxResult.success("分配成功");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 每次分配只能进入一条线程
|
|
|
|
+ *
|
|
|
|
+ * @param header
|
|
|
|
+ * @param details
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
- public AjaxResult doAllocationDetails(WmsDocOrderHeader header, WmsDocOrderDetails details) {
|
|
|
|
- if (!details.getLineStatus().equals("00")) {
|
|
|
|
|
|
+ public synchronized AjaxResult doAllocationDetails(WmsDocOrderHeader header, WmsDocOrderDetails details) {
|
|
|
|
+ // TODO 改成可以部分分配
|
|
|
|
+ if (!details.getLineStatus().equals(Constant.ORDER_STS.STS00.getValue())) {
|
|
return AjaxResult.error("出库明细为创建状态才可以分配!");
|
|
return AjaxResult.error("出库明细为创建状态才可以分配!");
|
|
}
|
|
}
|
|
LotattDTO lotattDTO = new LotattDTO();
|
|
LotattDTO lotattDTO = new LotattDTO();
|
|
@@ -290,16 +300,17 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
lotattDTO.setLotatt14(header.getOrderNo());
|
|
lotattDTO.setLotatt14(header.getOrderNo());
|
|
}
|
|
}
|
|
List<InvLotLocId> invList = invLotLocIdService.queryInvOrderBy(details.getLotnum(), details.getSku(), details.getLocation(), Constant.CUSTOMER_ID, lotattDTO);
|
|
List<InvLotLocId> invList = invLotLocIdService.queryInvOrderBy(details.getLotnum(), details.getSku(), details.getLocation(), Constant.CUSTOMER_ID, lotattDTO);
|
|
- // 原始订单数
|
|
|
|
- BigDecimal originalOrderQty = details.getQtyOrdered();
|
|
|
|
- //库存可分配数小于订单数
|
|
|
|
- BigDecimal orderQty = details.getQtyOrdered();
|
|
|
|
- //判断总数是否足够分配
|
|
|
|
|
|
+ // 原始订单需分配数
|
|
|
|
+ BigDecimal originalOrderQty = details.getQtyOrdered().subtract(details.getQtyAllocated());
|
|
|
|
+ // 订单需分配数
|
|
|
|
+ BigDecimal orderQty = details.getQtyOrdered().subtract(details.getQtyAllocated());
|
|
|
|
+ // 判断匹配库存总数是否足够分配
|
|
double qtySum = invList.stream()
|
|
double qtySum = invList.stream()
|
|
.mapToDouble(item -> item.getQty().doubleValue() > item.getQtyallocated().doubleValue()
|
|
.mapToDouble(item -> item.getQty().doubleValue() > item.getQtyallocated().doubleValue()
|
|
? item.getQty().doubleValue() - item.getQtyallocated().doubleValue() : 0)
|
|
? item.getQty().doubleValue() - item.getQtyallocated().doubleValue() : 0)
|
|
.sum();
|
|
.sum();
|
|
if (qtySum < orderQty.doubleValue()) {
|
|
if (qtySum < orderQty.doubleValue()) {
|
|
|
|
+ // TODO 改成可以部分分配
|
|
return AjaxResult.error("库存不足分配失败");
|
|
return AjaxResult.error("库存不足分配失败");
|
|
}
|
|
}
|
|
for (InvLotLocId inv : invList) {
|
|
for (InvLotLocId inv : invList) {
|
|
@@ -315,6 +326,7 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
BigDecimal canallocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
BigDecimal canallocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
if (canallocatedQty.doubleValue() > 0) {
|
|
if (canallocatedQty.doubleValue() > 0) {
|
|
if (inv.getQty().intValue() > 0) {
|
|
if (inv.getQty().intValue() > 0) {
|
|
|
|
+ // 当前库存可分配数量 < 订单需分配数
|
|
if (inv.getQty().subtract(inv.getQtyallocated()).compareTo(orderQty) == -1) {
|
|
if (inv.getQty().subtract(inv.getQtyallocated()).compareTo(orderQty) == -1) {
|
|
//可以分配的库存
|
|
//可以分配的库存
|
|
BigDecimal allocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
BigDecimal allocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
@@ -325,16 +337,15 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
//修改出库单状态
|
|
//修改出库单状态
|
|
details.setQtyAllocated(details.getQtyAllocated().add(allocatedQty));
|
|
details.setQtyAllocated(details.getQtyAllocated().add(allocatedQty));
|
|
details.setQtyAllocatedEach(details.getQtyAllocated());
|
|
details.setQtyAllocatedEach(details.getQtyAllocated());
|
|
- details.setLineStatus("20");
|
|
|
|
|
|
+ details.setLineStatus(Constant.ORDER_STS.STS10.getValue());
|
|
wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
-
|
|
|
|
-// header.setOrderStatus("10");
|
|
|
|
-// wmsDocOrderHeaderService.updateWmsDocOrderHeader(header);
|
|
|
|
//生成分配明细
|
|
//生成分配明细
|
|
- actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details, "20");
|
|
|
|
|
|
+ actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details
|
|
|
|
+ , Constant.ORDER_STS.STS20.getValue());
|
|
} else {
|
|
} else {
|
|
throw new ServiceException("占用库存分配数失败");
|
|
throw new ServiceException("占用库存分配数失败");
|
|
}
|
|
}
|
|
|
|
+ // 当前库存可分配数量 = 订单需分配数
|
|
} else if (inv.getQty().subtract(inv.getQtyallocated()).compareTo(orderQty) == 0) {
|
|
} else if (inv.getQty().subtract(inv.getQtyallocated()).compareTo(orderQty) == 0) {
|
|
//可以分配的库存
|
|
//可以分配的库存
|
|
BigDecimal allocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
BigDecimal allocatedQty = inv.getQty().subtract(inv.getQtyallocated());
|
|
@@ -343,34 +354,31 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
|
|
if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
|
|
orderQty = orderQty.subtract(allocatedQty);
|
|
orderQty = orderQty.subtract(allocatedQty);
|
|
//修改出库单状态
|
|
//修改出库单状态
|
|
- //修改出库单状态
|
|
|
|
- details.setLineStatus("20");
|
|
|
|
|
|
+ details.setLineStatus(Constant.ORDER_STS.STS20.getValue());
|
|
details.setQtyAllocated(details.getQtyAllocated().add(allocatedQty));
|
|
details.setQtyAllocated(details.getQtyAllocated().add(allocatedQty));
|
|
details.setQtyAllocatedEach(details.getQtyAllocatedEach().add(allocatedQty));
|
|
details.setQtyAllocatedEach(details.getQtyAllocatedEach().add(allocatedQty));
|
|
wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
-
|
|
|
|
-// header.setOrderStatus("20");
|
|
|
|
-// wmsDocOrderHeaderService.updateWmsDocOrderHeader(header);
|
|
|
|
//生成分配明细
|
|
//生成分配明细
|
|
- actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details, "20");
|
|
|
|
|
|
+ actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details
|
|
|
|
+ , Constant.ORDER_STS.STS20.getValue());
|
|
return AjaxResult.success("分配完成", originalOrderQty);
|
|
return AjaxResult.success("分配完成", originalOrderQty);
|
|
} else {
|
|
} else {
|
|
throw new ServiceException("占用库存分配数失败");
|
|
throw new ServiceException("占用库存分配数失败");
|
|
}
|
|
}
|
|
|
|
+ // 当前库存可分配数量 > 订单需分配数
|
|
} else {
|
|
} else {
|
|
BigDecimal currentQty = orderQty;
|
|
BigDecimal currentQty = orderQty;
|
|
inv.setQtyallocated(inv.getQtyallocated().add(currentQty));
|
|
inv.setQtyallocated(inv.getQtyallocated().add(currentQty));
|
|
inv.setQtyallocatedEach(inv.getQtyallocatedEach().add(currentQty));
|
|
inv.setQtyallocatedEach(inv.getQtyallocatedEach().add(currentQty));
|
|
- details.setQtyAllocatedEach(details.getQtyAllocatedEach().add(currentQty));
|
|
|
|
if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
|
|
if (invLotLocIdService.updateInvLotLocId(inv) > 0) {
|
|
//修改出库单状态
|
|
//修改出库单状态
|
|
- details.setLineStatus("20");
|
|
|
|
|
|
+ details.setLineStatus(Constant.ORDER_STS.STS20.getValue());
|
|
details.setQtyAllocated(details.getQtyAllocated().add(currentQty));
|
|
details.setQtyAllocated(details.getQtyAllocated().add(currentQty));
|
|
|
|
+ details.setQtyAllocatedEach(details.getQtyAllocatedEach().add(currentQty));
|
|
wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(details);
|
|
-// header.setOrderStatus("20");
|
|
|
|
-// wmsDocOrderHeaderService.updateWmsDocOrderHeader(header);
|
|
|
|
//生成分配明细
|
|
//生成分配明细
|
|
- actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), currentQty, details, "10");
|
|
|
|
|
|
+ actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), currentQty, details
|
|
|
|
+ , Constant.ORDER_STS.STS20.getValue());
|
|
return AjaxResult.success("分配完成", originalOrderQty);
|
|
return AjaxResult.success("分配完成", originalOrderQty);
|
|
|
|
|
|
} else {
|
|
} else {
|