|
@@ -236,7 +236,6 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
|
for (WmsDocOrderDetails o : orderDetails) {
|
|
|
total = total.add(o.getQtyOrdered().subtract(o.getQtyAllocated()));
|
|
|
}
|
|
|
- String sku = "";
|
|
|
for (WmsDocOrderDetails o : orderDetails) {
|
|
|
AjaxResult result = wmsDocOrderHeaderService.doAllocationDetails(orderHeader, o);
|
|
|
if ((int) result.get(AjaxResult.CODE_TAG) != 500) {
|
|
@@ -244,7 +243,6 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
|
BigDecimal current = new BigDecimal(result.get(AjaxResult.DATA_TAG).toString());
|
|
|
total = total.subtract(current);
|
|
|
if (total.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
- sku = o.getSku();
|
|
|
isbf = true;
|
|
|
} else {
|
|
|
isbf = false;
|
|
@@ -255,7 +253,7 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
|
orderHeader.setOrderStatus(Constant.ORDER_STS.STS10.getValue());
|
|
|
wmsDocOrderHeaderService.updateWmsDocOrderHeader(orderHeader);
|
|
|
// TODO 改成可以部分分配
|
|
|
- throw new ServiceException("库存数量不足,分配失败!" + orderNo + ",品号:" + sku);
|
|
|
+ throw new ServiceException("库存数量不足,分配失败!" + orderNo);
|
|
|
}
|
|
|
if (isAllocation) {
|
|
|
orderHeader.setOrderStatus(Constant.ORDER_STS.STS20.getValue());
|
|
@@ -266,12 +264,89 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 备货分配
|
|
|
+ *
|
|
|
+ * @param orderNo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
|
+ @Override
|
|
|
+ public AjaxResult doAllocationBH(String orderNo) {
|
|
|
+ WmsDocOrderHeader orderHeader = wmsDocOrderHeaderMapper.selectWmsDocOrderHeaderByOrderNo(orderNo);
|
|
|
+ // 为了可以重复下任务
|
|
|
+ if (StringUtils.isEmpty(orderHeader.getUserdefine6())) {
|
|
|
+ orderHeader.setUserdefine6("N");
|
|
|
+ }
|
|
|
+ if (orderHeader == null) {
|
|
|
+ return AjaxResult.error("没有查询到订单");
|
|
|
+ }
|
|
|
+ if (!orderHeader.getOrderStatus().equals(Constant.ORDER_STS.STS23.getValue())) {
|
|
|
+ return AjaxResult.error("出库单为备货完成才可以分配");
|
|
|
+ }
|
|
|
+ // 是否已经生成分配明细
|
|
|
+ ActAllocationDetails allocationDetailsQuery = new ActAllocationDetails();
|
|
|
+ allocationDetailsQuery.setOrderNo(orderNo);
|
|
|
+ allocationDetailsQuery.setStatus(Constant.ORDER_STS.STS20.getValue());
|
|
|
+ List<ActAllocationDetails> actAllocationDetailsList = actAllocationDetailsService.selectActAllocationDetailsList(allocationDetailsQuery);
|
|
|
+ if (actAllocationDetailsList.size() > 0) {
|
|
|
+ return AjaxResult.error("出库单已经生成分配明细!");
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean isbf = false;
|
|
|
+ boolean isAllocation = false;
|
|
|
+ BigDecimal total = BigDecimal.ZERO;
|
|
|
+ List<WmsDocOrderDetails> orderDetails = orderHeader.getWmsDocOrderDetailsList();
|
|
|
+ for (WmsDocOrderDetails o : orderDetails) {
|
|
|
+ total = total.add(o.getQtyOrdered());
|
|
|
+ }
|
|
|
+ for (WmsDocOrderDetails o : orderDetails) {
|
|
|
+ AjaxResult result = wmsDocOrderHeaderService.doAllocationDetailsBH(orderHeader, o);
|
|
|
+ if ((int) result.get(AjaxResult.CODE_TAG) != 500) {
|
|
|
+ isAllocation = true;
|
|
|
+ BigDecimal current = new BigDecimal(result.get(AjaxResult.DATA_TAG).toString());
|
|
|
+ total = total.subtract(current);
|
|
|
+ if (total.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ isbf = true;
|
|
|
+ } else {
|
|
|
+ isbf = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isbf) {
|
|
|
+ orderHeader.setOrderStatus(Constant.ORDER_STS.STS22.getValue());
|
|
|
+ wmsDocOrderHeaderService.updateWmsDocOrderHeader(orderHeader);
|
|
|
+ if (!orderHeader.getUserdefine6().equals("Y")) {
|
|
|
+ throw new ServiceException("库存数量不足,分配失败!" + orderNo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isAllocation) {
|
|
|
+ orderHeader.setOrderStatus(Constant.ORDER_STS.STS23.getValue());
|
|
|
+ // 偷懒 卡个bug
|
|
|
+ orderHeader.setUserdefine6("Y"); // 代表已经校验成功
|
|
|
+ wmsDocOrderHeaderService.updateWmsDocOrderHeader(orderHeader);
|
|
|
+ return AjaxResult.success("分配成功");
|
|
|
+ } else {
|
|
|
+ return AjaxResult.error("分配失败,没有可用的库存");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public AjaxResult doAllocation(List<String> orderNoList) {
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
for (String s : orderNoList) {
|
|
|
- // 同一个类事务会失效 通过重新注入自己解决事务失效问题
|
|
|
- AjaxResult ajaxResult = wmsDocOrderHeaderService.doAllocation(s);
|
|
|
+ AjaxResult ajaxResult = null;
|
|
|
+ WmsDocOrderHeader header = wmsDocOrderHeaderService.selectWmsDocOrderHeaderByOrderNo(s);
|
|
|
+ // 判断是否是已经备货完成的备货单
|
|
|
+ if (header.getOrderType().equals(Constant.ORDER_TYP.BH.getValue())
|
|
|
+ && header.getOrderStatus().equals(Constant.ORDER_STS.STS23.getValue())) {
|
|
|
+ // 同一个类事务会失效 通过重新注入自己解决事务失效问题
|
|
|
+ ajaxResult = wmsDocOrderHeaderService.doAllocationBH(s);
|
|
|
+ } else {
|
|
|
+ // 同一个类事务会失效 通过重新注入自己解决事务失效问题
|
|
|
+ ajaxResult = wmsDocOrderHeaderService.doAllocation(s);
|
|
|
+ }
|
|
|
if (!ajaxResult.isSuccess()) {
|
|
|
builder.append(s).append(":").append(ajaxResult.getMsg()).append(";");
|
|
|
}
|
|
@@ -395,6 +470,80 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
|
return AjaxResult.success("库存数不足,部分分配", originalOrderQty.subtract(orderQty));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每次分配只能进入一条线程
|
|
|
+ *
|
|
|
+ * @param header
|
|
|
+ * @param details
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public synchronized AjaxResult doAllocationDetailsBH(WmsDocOrderHeader header, WmsDocOrderDetails details) {
|
|
|
+ if (!details.getLineStatus().equals(Constant.ORDER_STS.STS23.getValue())) {
|
|
|
+ return AjaxResult.error("出库明细为备货完成状态才可以分配!");
|
|
|
+ }
|
|
|
+ LotattDTO lotattDTO = new LotattDTO();
|
|
|
+ // 备货对应的出库单库存
|
|
|
+ lotattDTO.setLotatt14(header.getOrderNo());
|
|
|
+ List<InvLotLocId> invList = invLotLocIdService.queryInvOrderBy(details.getLotnum(), details.getSku(), details.getLocation(), Constant.CUSTOMER_ID, lotattDTO);
|
|
|
+ // 原始订单需分配数
|
|
|
+ BigDecimal originalOrderQty = details.getQtyOrdered();
|
|
|
+ // 订单需分配数
|
|
|
+ BigDecimal orderQty = details.getQtyOrdered();
|
|
|
+ // 判断匹配库存总数是否足够分配
|
|
|
+ double qtySum = invList.stream()
|
|
|
+ .mapToDouble(item -> item.getQty().doubleValue())
|
|
|
+ .sum();
|
|
|
+ if (qtySum < orderQty.doubleValue() && !header.getUserdefine6().equals("Y")) {
|
|
|
+ return AjaxResult.error("库存不足分配失败");
|
|
|
+ }
|
|
|
+ for (InvLotLocId inv : invList) {
|
|
|
+ if (orderQty.doubleValue() == 0) {
|
|
|
+ return AjaxResult.success("分配完成", originalOrderQty);
|
|
|
+ }
|
|
|
+ //可以叫料且合格的库存
|
|
|
+ InvLotAtt lotAtt = invLotAttMapper.selectInvLotAttByLotnum(inv.getLotnum());
|
|
|
+ if (!lotAtt.getLotatt05().equals("90") || !lotAtt.getLotatt12().equals("Y")) {
|
|
|
+// continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal canallocatedQty = inv.getQty();
|
|
|
+ if (canallocatedQty.doubleValue() > 0) {
|
|
|
+ if (inv.getQty().intValue() > 0) {
|
|
|
+ // 当前库存可分配数量 < 订单需分配数
|
|
|
+ if (inv.getQty().compareTo(orderQty) == -1) {
|
|
|
+ //可以分配的库存
|
|
|
+ BigDecimal allocatedQty = inv.getQty();
|
|
|
+ orderQty = orderQty.subtract(allocatedQty);
|
|
|
+ //生成分配明细
|
|
|
+ actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details
|
|
|
+ , Constant.ORDER_STS.STS20.getValue());
|
|
|
+
|
|
|
+ // 当前库存可分配数量 = 订单需分配数
|
|
|
+ } else if (inv.getQty().compareTo(orderQty) == 0) {
|
|
|
+ //可以分配的库存
|
|
|
+ BigDecimal allocatedQty = inv.getQty();
|
|
|
+ //生成分配明细
|
|
|
+ actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), allocatedQty, details
|
|
|
+ , Constant.ORDER_STS.STS20.getValue());
|
|
|
+ return AjaxResult.success("分配完成", originalOrderQty);
|
|
|
+
|
|
|
+ // 当前库存可分配数量 > 订单需分配数
|
|
|
+ } else {
|
|
|
+ BigDecimal currentQty = orderQty;
|
|
|
+ //生成分配明细
|
|
|
+ actAllocationDetailsService.addActAllocationDetails(inv.getLotnum(), inv.getLocationId(), currentQty, details
|
|
|
+ , Constant.ORDER_STS.STS20.getValue());
|
|
|
+ return AjaxResult.success("分配完成", originalOrderQty);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return AjaxResult.success("库存数不足,部分分配", originalOrderQty.subtract(orderQty));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<PickingListVO> pickingList(String palletNo) {
|
|
|
List<PickingListVO> pickingListVOS = new ArrayList<>();
|
|
@@ -512,64 +661,82 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
|
return wmsDocOrderHeaderMapper.selectCheckOutList(orderNoList);
|
|
|
}
|
|
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
|
@Override
|
|
|
- public AjaxResult doCheckout(CheckOutForm checkOutForm) {
|
|
|
- for (CheckOutInfoForm check : checkOutForm.getCheckOutInfoFormList()) {
|
|
|
-
|
|
|
- //生成任务呼叫到接驳位
|
|
|
- BaseLocationInfo baseLocationInfo = baseLocationInfoService.selectBaseLocationInfoByIdOrNo(check.getLocationNo(), Constant.WAREHOUSE_ID);
|
|
|
- FlowConfigHeaderVO flowConfigHeaderVO = flowConfigHeaderService.selectFlowConfigHeaderById(6L);
|
|
|
- AgvCallDTO agvCallDTO = new AgvCallDTO();
|
|
|
- agvCallDTO.setId(flowConfigHeaderVO.getId());
|
|
|
- agvCallDTO.setLocationFrom(baseLocationInfo.getId().toString());
|
|
|
- agvCallDTO.setLocationTo(null);
|
|
|
- agvCallDTO.setPalletNo(check.getPalletNo());
|
|
|
- agvCallDTO.setWarehouseId(Constant.WAREHOUSE_ID);
|
|
|
- // 参数内容过长无法添加
|
|
|
- agvCallDTO.setExtParam("");
|
|
|
- AjaxResult result = businessService.agvCall(flowConfigHeaderVO, agvCallDTO);
|
|
|
- if ((int) result.get(AjaxResult.CODE_TAG) == 500) {
|
|
|
- throw new ServiceException("任务生成失败:" + result.getMsg() + ",库位:" + baseLocationInfo.getLocationNo());
|
|
|
- }
|
|
|
+ public AjaxResult doCheckout(CheckOutInfoForm check) {
|
|
|
+ //生成任务呼叫到接驳位
|
|
|
+ BaseLocationInfo baseLocationInfo = baseLocationInfoService.selectBaseLocationInfoByIdOrNo(check.getLocationNo(), Constant.WAREHOUSE_ID);
|
|
|
+ FlowConfigHeaderVO flowConfigHeaderVO = flowConfigHeaderService.selectFlowConfigHeaderById(6L);
|
|
|
+ AgvCallDTO agvCallDTO = new AgvCallDTO();
|
|
|
+ agvCallDTO.setId(flowConfigHeaderVO.getId());
|
|
|
+ agvCallDTO.setLocationFrom(baseLocationInfo.getId().toString());
|
|
|
+ agvCallDTO.setLocationTo(null);
|
|
|
+ agvCallDTO.setPalletNo(check.getPalletNo());
|
|
|
+ agvCallDTO.setWarehouseId(Constant.WAREHOUSE_ID);
|
|
|
+ // 参数内容过长无法添加
|
|
|
+ agvCallDTO.setExtParam("");
|
|
|
+ AjaxResult result = businessService.agvCall(flowConfigHeaderVO, agvCallDTO);
|
|
|
+ if ((int) result.get(AjaxResult.CODE_TAG) == 500) {
|
|
|
+ throw new ServiceException("任务生成失败:" + result.getMsg() + ",库位:" + baseLocationInfo.getLocationNo());
|
|
|
+ }
|
|
|
|
|
|
- // 将分配明细由分配完成改为任务生成
|
|
|
- ActAllocationDetails actAllocationDetails = new ActAllocationDetails();
|
|
|
- actAllocationDetails.setOrderNo(check.getOrderNo());
|
|
|
- actAllocationDetails.setLocationId(baseLocationInfo.getId());
|
|
|
- List<ActAllocationDetails> actAllocationDetailsList = actAllocationDetailsService.selectActAllocationDetailsList(actAllocationDetails);
|
|
|
- for (ActAllocationDetails allocationDetails : actAllocationDetailsList) {
|
|
|
- ActAllocationDetails allocationDetailsUpdate = new ActAllocationDetails();
|
|
|
- allocationDetailsUpdate.setAllocationId(allocationDetails.getAllocationId());
|
|
|
- allocationDetailsUpdate.setStatus(Constant.ORDER_STS.STS21.getValue());
|
|
|
- actAllocationDetailsService.updateActAllocationDetails(allocationDetailsUpdate);
|
|
|
- }
|
|
|
- // 库内理货 修改出库单为完成
|
|
|
- WmsDocOrderHeader header = wmsDocOrderHeaderService.selectWmsDocOrderHeaderByOrderNo(check.getOrderNo());
|
|
|
- if (header != null && header.getOrderType().equals(Constant.ORDER_TYP.LH.getValue())) {
|
|
|
- WmsDocOrderHeader docOrderHeader = new WmsDocOrderHeader();
|
|
|
- docOrderHeader.setOrderNo(check.getOrderNo());
|
|
|
- docOrderHeader.setOrderStatus(Constant.ORDER_STS.STS99.getValue());
|
|
|
- wmsDocOrderHeaderMapper.updateWmsDocOrderHeader(docOrderHeader);
|
|
|
+ // 将分配明细由分配完成改为任务生成
|
|
|
+ ActAllocationDetails actAllocationDetails = new ActAllocationDetails();
|
|
|
+ actAllocationDetails.setOrderNo(check.getOrderNo());
|
|
|
+ actAllocationDetails.setLocationId(baseLocationInfo.getId());
|
|
|
+ actAllocationDetails.setStatus(Constant.ORDER_STS.STS20.getValue());
|
|
|
+ List<ActAllocationDetails> actAllocationDetailsList = actAllocationDetailsService.selectActAllocationDetailsList(actAllocationDetails);
|
|
|
+ for (ActAllocationDetails allocationDetails : actAllocationDetailsList) {
|
|
|
+ ActAllocationDetails allocationDetailsUpdate = new ActAllocationDetails();
|
|
|
+ allocationDetailsUpdate.setAllocationId(allocationDetails.getAllocationId());
|
|
|
+ allocationDetailsUpdate.setStatus(Constant.ORDER_STS.STS21.getValue());
|
|
|
+ actAllocationDetailsService.updateActAllocationDetails(allocationDetailsUpdate);
|
|
|
+ }
|
|
|
+ // 库内理货 修改出库单为完成
|
|
|
+ WmsDocOrderHeader header = wmsDocOrderHeaderService.selectWmsDocOrderHeaderByOrderNo(check.getOrderNo());
|
|
|
+ if (header != null && header.getOrderType().equals(Constant.ORDER_TYP.LH.getValue())) {
|
|
|
+ WmsDocOrderHeader docOrderHeader = new WmsDocOrderHeader();
|
|
|
+ docOrderHeader.setOrderNo(check.getOrderNo());
|
|
|
+ docOrderHeader.setOrderStatus(Constant.ORDER_STS.STS99.getValue());
|
|
|
+ wmsDocOrderHeaderMapper.updateWmsDocOrderHeader(docOrderHeader);
|
|
|
+ // 明细
|
|
|
+ List<WmsDocOrderDetails> wmsDocOrderDetailsList = wmsDocOrderDetailsMapper.selectWmsDocOrderDetailsByOrderNo(header.getOrderNo());
|
|
|
+ for (WmsDocOrderDetails d : wmsDocOrderDetailsList) {
|
|
|
WmsDocOrderDetails wmsDocOrderDetails = new WmsDocOrderDetails();
|
|
|
- wmsDocOrderDetails.setOrderNo(check.getOrderNo());
|
|
|
+ wmsDocOrderDetails.setOrderNo(d.getOrderNo());
|
|
|
+ wmsDocOrderDetails.setOrderLineNo(d.getOrderLineNo());
|
|
|
wmsDocOrderDetails.setLineStatus(Constant.ORDER_STS.STS99.getValue());
|
|
|
wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(wmsDocOrderDetails);
|
|
|
}
|
|
|
- // 备货 修改出库单为备货状态
|
|
|
+ }
|
|
|
+ // 备货 修改出库单为备货状态
|
|
|
// if (header != null && header.getOrderType().equals(Constant.ORDER_TYP.BH.getValue())) {
|
|
|
-// WmsDocOrderHeader docOrderHeader = new WmsDocOrderHeader();
|
|
|
-// docOrderHeader.setOrderNo(check.getOrderNo());
|
|
|
-// docOrderHeader.setOrderStatus(Constant.ORDER_STS.STS99.getValue());
|
|
|
-// wmsDocOrderHeaderMapper.updateWmsDocOrderHeader(docOrderHeader);
|
|
|
+// if (!header.getOrderStatus().equals(Constant.ORDER_STS.STS23)) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// // 是否已经生成分配明细
|
|
|
+// ActAllocationDetails allocationDetailsQuery = new ActAllocationDetails();
|
|
|
+// allocationDetailsQuery.setOrderNo(header.getOrderNo());
|
|
|
+// allocationDetailsQuery.setStatus(Constant.ORDER_STS.STS20.getValue());
|
|
|
+// List<ActAllocationDetails> allocationDetails = actAllocationDetailsService.selectActAllocationDetailsList(allocationDetailsQuery);
|
|
|
+// if (allocationDetails.size() > 1) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// WmsDocOrderHeader docOrderHeader = new WmsDocOrderHeader();
|
|
|
+// docOrderHeader.setOrderNo(check.getOrderNo());
|
|
|
+// docOrderHeader.setOrderStatus(Constant.ORDER_STS.STS99.getValue());
|
|
|
+// wmsDocOrderHeaderMapper.updateWmsDocOrderHeader(docOrderHeader);
|
|
|
+// // 明细
|
|
|
+// List<WmsDocOrderDetails> wmsDocOrderDetailsList = wmsDocOrderDetailsMapper.selectWmsDocOrderDetailsByOrderNo(header.getOrderNo());
|
|
|
+// for (WmsDocOrderDetails d : wmsDocOrderDetailsList) {
|
|
|
// WmsDocOrderDetails wmsDocOrderDetails = new WmsDocOrderDetails();
|
|
|
-// wmsDocOrderDetails.setOrderNo(check.getOrderNo());
|
|
|
+// wmsDocOrderDetails.setOrderNo(d.getOrderNo());
|
|
|
+// wmsDocOrderDetails.setOrderLineNo(d.getOrderLineNo());
|
|
|
// wmsDocOrderDetails.setLineStatus(Constant.ORDER_STS.STS99.getValue());
|
|
|
// wmsDocOrderDetailsMapper.updateWmsDocOrderDetails(wmsDocOrderDetails);
|
|
|
+// }
|
|
|
// }
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
return AjaxResult.success("操作成功");
|
|
|
}
|
|
|
|