| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.itemreceipt.MesWmItemReceiptLineDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.wm.itemreceipt.MesWmItemReceiptMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.MesBizTypeConstants; |
| | | import cn.iocoder.yudao.module.mes.enums.qc.MesQcCheckResultEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmItemReceiptStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmTransactionTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.service.qc.iqc.MesQcIqcService; |
| | |
| | | } |
| | | } |
| | | } else if (receipt.getNoticeId() != null) { |
| | | // 兜底:入库行为空时,从到货通知单行回写入库数量 |
| | | // 兜底:入库行为空时,从到货通知单中可入库的行回写入库数量 |
| | | List<MesWmArrivalNoticeLineDO> noticeLines = arrivalNoticeLineService |
| | | .getArrivalNoticeLineListByNoticeId(receipt.getNoticeId()); |
| | | for (MesWmArrivalNoticeLineDO noticeLine : noticeLines) { |
| | | if (noticeLine.getPurchaseOrderItemId() != null) { |
| | | // 使用合格数量(有 IQC 时为合格数量,否则为到货数量) |
| | | BigDecimal qty = noticeLine.getQualifiedQuantity() != null |
| | | ? noticeLine.getQualifiedQuantity() : noticeLine.getArrivalQuantity(); |
| | | if (qty != null && qty.compareTo(BigDecimal.ZERO) > 0) { |
| | | purchaseOrderApi.updateOrderItemInCount(noticeLine.getPurchaseOrderItemId(), qty); |
| | | } |
| | | if (noticeLine.getPurchaseOrderItemId() == null) { |
| | | continue; |
| | | } |
| | | BigDecimal qty = calculateInboundQuantity(noticeLine); |
| | | if (qty != null && qty.compareTo(BigDecimal.ZERO) > 0) { |
| | | purchaseOrderApi.updateOrderItemInCount(noticeLine.getPurchaseOrderItemId(), qty); |
| | | } |
| | | } |
| | | } |
| | |
| | | throw exception(WM_ITEM_RECEIPT_ALREADY_EXISTS); |
| | | } |
| | | |
| | | // 3. 获取到货通知单行 |
| | | // 3. 获取到货通知单行,仅保留可入库的行(未启用来料检验的行按到货数量入库;检验行须合格或特采) |
| | | List<MesWmArrivalNoticeLineDO> lines = arrivalNoticeLineService.getArrivalNoticeLineListByNoticeId(arrivalNoticeId); |
| | | if (CollUtil.isEmpty(lines)) { |
| | | throw exception(WM_ARRIVAL_NOTICE_NO_LINE); |
| | | } |
| | | List<MesWmArrivalNoticeLineDO> inboundLines = new ArrayList<>(); |
| | | for (MesWmArrivalNoticeLineDO line : lines) { |
| | | BigDecimal inboundQuantity = calculateInboundQuantity(line); |
| | | if (inboundQuantity != null && inboundQuantity.compareTo(BigDecimal.ZERO) > 0) { |
| | | inboundLines.add(line); |
| | | } |
| | | } |
| | | if (CollUtil.isEmpty(inboundLines)) { |
| | | throw exception(WM_ARRIVAL_NOTICE_NO_INBOUND_LINE); |
| | | } |
| | | |
| | | // 4. 生成入库单编码 |
| | |
| | | receipt.setStatus(MesWmItemReceiptStatusEnum.PREPARE.getStatus()); |
| | | itemReceiptMapper.insert(receipt); |
| | | |
| | | // 6. 遍历行创建入库单行 |
| | | for (MesWmArrivalNoticeLineDO noticeLine : lines) { |
| | | // 6. 遍历可入库的行创建入库单行 |
| | | for (MesWmArrivalNoticeLineDO noticeLine : inboundLines) { |
| | | MesWmItemReceiptLineDO receiptLine = new MesWmItemReceiptLineDO(); |
| | | receiptLine.setReceiptId(receipt.getId()); |
| | | receiptLine.setArrivalNoticeLineId(noticeLine.getId()); |
| | | receiptLine.setPurchaseOrderItemId(noticeLine.getPurchaseOrderItemId()); |
| | | receiptLine.setItemId(noticeLine.getItemId()); |
| | | // 使用合格数量(如果有 IQC 则是合格数量,否则是到货数量) |
| | | receiptLine.setReceivedQuantity(noticeLine.getQualifiedQuantity() != null ? noticeLine.getQualifiedQuantity() : noticeLine.getArrivalQuantity()); |
| | | receiptLine.setReceivedQuantity(calculateInboundQuantity(noticeLine)); |
| | | itemReceiptLineService.createItemReceiptLineFromArrivalNoticeLine(receiptLine); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 计算到货通知单行的可入库数量 |
| | | * |
| | | * <p>未启用来料检验的行按到货数量入库;启用来料检验的行只有合格/特采才可入库, |
| | | * 退货/报废返回 {@code null},避免生成零数量或错误数量的入库单行。 |
| | | */ |
| | | private BigDecimal calculateInboundQuantity(MesWmArrivalNoticeLineDO noticeLine) { |
| | | if (Boolean.TRUE.equals(noticeLine.getIqcCheckFlag()) |
| | | && !MesQcCheckResultEnum.canInbound(noticeLine.getIqcCheckResult())) { |
| | | return null; |
| | | } |
| | | return noticeLine.getQualifiedQuantity() != null |
| | | ? noticeLine.getQualifiedQuantity() : noticeLine.getArrivalQuantity(); |
| | | } |
| | | |
| | | /** |
| | | * 生成入库单编码 |
| | | */ |
| | | private String generateItemReceiptCode() { |