| | |
| | | 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; |
| | |
| | | // 校验物料批次管理:如果物料开启批次管理,则明细的批次号不能为空 |
| | | validateBatchManagement(lines); |
| | | |
| | | // 校验审批配置已启用且配置了有效审核人(未配置时抛出带明确提示的业务异常) |
| | | approvalConfigApi.validateApprovalEnabledAndGetApprovers(ITEM_RECEIPT_APPROVE_BIZ_TYPE); |
| | | |
| | | // 提交(草稿 → 待上架),并清空上一轮审核结果 |
| | | itemReceiptMapper.submitAndResetAuditInfo(id, MesWmItemReceiptStatusEnum.APPROVING.getStatus()); |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void stockItemReceipt(Long id) { |
| | | // 校验存在 |
| | | // 校验存在 + 待上架 |
| | | MesWmItemReceiptDO receipt = validateItemReceiptExists(id); |
| | | if (ObjUtil.notEqual(MesWmItemReceiptStatusEnum.APPROVING.getStatus(), receipt.getStatus())) { |
| | | throw exception(WM_ITEM_RECEIPT_STATUS_ERROR); |
| | |
| | | throw exception(WM_ITEM_RECEIPT_DETAIL_QUANTITY_MISMATCH); |
| | | } |
| | | } |
| | | |
| | | // 执行上架(待上架 → 待入库) |
| | | // 上架完成(待上架 → 待执行入库) |
| | | itemReceiptMapper.updateById(new MesWmItemReceiptDO() |
| | | .setId(id).setStatus(MesWmItemReceiptStatusEnum.APPROVED.getStatus())); |
| | | } |
| | |
| | | } |
| | | } |
| | | } 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public MesWmItemReceiptDO validateItemReceiptEditable(Long id) { |
| | | // 草稿与待上架状态允许编辑上架明细:提交后仓库执行上架时录入库位/批次 |
| | | MesWmItemReceiptDO receipt = validateItemReceiptExists(id); |
| | | if (ObjUtil.notEqual(receipt.getStatus(), MesWmItemReceiptStatusEnum.PREPARE.getStatus()) |
| | | && ObjUtil.notEqual(receipt.getStatus(), MesWmItemReceiptStatusEnum.APPROVING.getStatus())) { |
| | | if (ObjUtil.notEqual(MesWmItemReceiptStatusEnum.PREPARE.getStatus(), receipt.getStatus()) |
| | | && ObjUtil.notEqual(MesWmItemReceiptStatusEnum.APPROVING.getStatus(), receipt.getStatus())) { |
| | | throw exception(WM_ITEM_RECEIPT_STATUS_NOT_PREPARE); |
| | | } |
| | | return receipt; |
| | | } |
| | | |
| | | @Override |
| | | public MesWmItemReceiptDO validateItemReceiptLineEditable(Long id) { |
| | | // 行数据仅草稿可改:提交后行数据锁定,避免上架阶段改动入库数量 |
| | | return validateItemReceiptExistsAndDraft(id); |
| | | } |
| | | |
| | | private MesWmItemReceiptDO validateItemReceiptExists(Long id) { |
| | |
| | | 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() { |