| | |
| | | import cn.iocoder.yudao.module.erp.api.purchase.dto.ErpPurchaseOrderRespDTO; |
| | | import cn.iocoder.yudao.module.erp.api.purchase.dto.ErpPurchaseOrderItemRespDTO; |
| | | import cn.iocoder.yudao.module.mes.service.mdm.MesMdmItemService; |
| | | import cn.iocoder.yudao.module.mes.service.qc.iqc.MesQcIqcService; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | |
| | | |
| | | @Resource |
| | | private MesMdmItemService mdmItemService; |
| | | |
| | | @Resource |
| | | @Lazy |
| | | private MesQcIqcService iqcService; |
| | | |
| | | @Override |
| | | public Long createArrivalNotice(MesWmArrivalNoticeSaveReqVO createReqVO) { |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void submitArrivalNotice(Long id) { |
| | | // 1.1 校验存在 + 草稿状态 |
| | | validateArrivalNoticeExistsAndDraft(id); |
| | | MesWmArrivalNoticeDO notice = validateArrivalNoticeExistsAndDraft(id); |
| | | // 1.2 检查是否有行项目 |
| | | List<MesWmArrivalNoticeLineDO> lines = arrivalNoticeLineService.getArrivalNoticeLineListByNoticeId(id); |
| | | if (CollUtil.isEmpty(lines)) { |
| | |
| | | boolean needCheck = CollectionUtils.anyMatch(lines, |
| | | line -> Boolean.TRUE.equals(line.getIqcCheckFlag())); |
| | | if (needCheck) { |
| | | // 需要检验,进入待质检 |
| | | // 2.1 需要检验,进入待质检 |
| | | arrivalNoticeMapper.updateById(new MesWmArrivalNoticeDO() |
| | | .setId(id).setStatus(MesWmArrivalNoticeStatusEnum.PENDING_QC.getStatus())); |
| | | // 2.2 为需要质检的行自动创建 IQC 检验单 |
| | | for (MesWmArrivalNoticeLineDO line : lines) { |
| | | if (Boolean.TRUE.equals(line.getIqcCheckFlag()) && line.getIqcId() == null) { |
| | | try { |
| | | Long iqcId = iqcService.createIqcFromArrivalNotice( |
| | | id, line, notice.getCode(), notice.getVendorId()); |
| | | // 更新行上的 iqcId |
| | | arrivalNoticeLineService.updateArrivalNoticeLineIqcId(line.getId(), iqcId); |
| | | log.info("[submitArrivalNotice][到货通知单({}) 行({}) 自动创建 IQC 检验单({})]", |
| | | id, line.getId(), iqcId); |
| | | } catch (Exception e) { |
| | | log.warn("[submitArrivalNotice][到货通知单({}) 行({}) 创建 IQC 失败: {}]", |
| | | id, line.getId(), e.getMessage()); |
| | | // 继续处理其他行,不中断流程 |
| | | } |
| | | } |
| | | } |
| | | return; |
| | | } |
| | | // 不需要检验,直接进入待入库 |
| | |
| | | // 注意:这里需要根据 ERP 产品 ID 映射到 MES 物料 ID |
| | | // 实际项目中需要通过映射服务处理,这里暂时留空让用户手动选择 |
| | | line.setArrivalQuantity(item.getCount() != null ? item.getCount().subtract(item.getInCount() != null ? item.getInCount() : BigDecimal.ZERO) : BigDecimal.ZERO); |
| | | line.setIqcCheckFlag(false); // 默认不需要检验,用户可修改 |
| | | // 从采购订单明细带入质检标识 |
| | | line.setIqcCheckFlag(Boolean.TRUE.equals(item.getQcCheckFlag())); |
| | | arrivalNoticeLineService.createArrivalNoticeLineFromPurchaseOrderItem(line); |
| | | } |
| | | |