| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.salesnotice.MesWmSalesNoticeLineDO; |
| | | import cn.iocoder.yudao.module.mes.service.wm.salesnotice.MesWmSalesNoticeLineService; |
| | | import cn.iocoder.yudao.module.mes.service.qc.oqc.MesQcOqcService; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.annotation.Lazy; |
| | |
| | | @Resource |
| | | @Lazy |
| | | private MesWmSalesNoticeLineService salesNoticeLineService; |
| | | @Resource |
| | | @Lazy |
| | | private MesQcOqcService oqcService; |
| | | |
| | | @Override |
| | | public Long createProductSalesLine(MesWmProductSalesLineSaveReqVO createReqVO) { |
| | |
| | | // 更新 |
| | | MesWmProductSalesLineDO updateObj = BeanUtils.toBean(updateReqVO, MesWmProductSalesLineDO.class); |
| | | productSalesLineMapper.updateById(updateObj); |
| | | |
| | | // 检查是否需要创建 OQC 检验单:从不需要检验变为需要检验 |
| | | if (Boolean.TRUE.equals(updateReqVO.getOqcCheckFlag()) |
| | | && !Boolean.TRUE.equals(oldLine.getOqcCheckFlag())) { |
| | | // 获取出库单信息 |
| | | MesWmProductSalesDO sales = productSalesService.getProductSales(updateReqVO.getSalesId()); |
| | | if (sales == null) { |
| | | log.warn("[updateProductSalesLine] 出库单不存在,salesId={}", updateReqVO.getSalesId()); |
| | | return; |
| | | } |
| | | |
| | | // 构建出库明细 DO |
| | | MesWmProductSalesLineDO line = new MesWmProductSalesLineDO(); |
| | | line.setId(updateReqVO.getId()); |
| | | line.setItemId(updateReqVO.getItemId()); |
| | | line.setBatchCode(updateReqVO.getBatchCode()); |
| | | line.setQuantity(updateReqVO.getQuantity()); |
| | | |
| | | // 创建 OQC 检验单,让异常抛出 |
| | | Long oqcId = oqcService.createOqcFromProductSales( |
| | | sales.getId(), line, sales.getCode(), sales.getClientId()); |
| | | |
| | | // 更新出库明细的 oqcId 和质量状态 |
| | | productSalesLineMapper.updateById(new MesWmProductSalesLineDO() |
| | | .setId(updateReqVO.getId()) |
| | | .setOqcId(oqcId) |
| | | .setQualityStatus(MesWmQualityStatusEnum.PENDING.getStatus())); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | MesWmSalesNoticeLineDO noticeLine = salesNoticeLineService.validateSalesNoticeLineExists( |
| | | noticeLineId, sales.getNoticeId()); |
| | | // 校验关键字段一致性:物料、数量、批次号、OQC 检验标识 |
| | | // 校验关键字段一致性:物料、数量、批次号 |
| | | // 注:OQC 检验标识允许在出库时独立设置,不强制与通知单一致 |
| | | if (ObjUtil.notEqual(reqVO.getItemId(), noticeLine.getItemId())) { |
| | | throw exception(WM_PRODUCT_SALES_LINE_NOTICE_LINE_ITEM_MISMATCH); |
| | | } |
| | |
| | | if (StrUtil.isNotBlank(noticeLine.getBatchCode()) |
| | | && ObjUtil.notEqual(reqVO.getBatchCode(), noticeLine.getBatchCode())) { |
| | | throw exception(WM_PRODUCT_SALES_LINE_NOTICE_LINE_BATCH_MISMATCH); |
| | | } |
| | | if (noticeLine.getOqcCheckFlag() != null |
| | | && ObjUtil.notEqual(reqVO.getOqcCheckFlag(), noticeLine.getOqcCheckFlag())) { |
| | | throw exception(WM_PRODUCT_SALES_LINE_NOTICE_LINE_OQC_MISMATCH); |
| | | } |
| | | return; |
| | | } |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateProductSalesLineWhenOqcFinish(Long id, Long oqcId, Integer checkResult) { |
| | | // 1. 更新行的 oqcId + qualityStatus |
| | | Integer qualityStatus = Objects.equals(checkResult, MesQcCheckResultEnum.PASS.getType()) |
| | | Integer qualityStatus = Objects.equals(checkResult, MesQcCheckResultEnum.QUALIFIED.getType()) |
| | | ? MesWmQualityStatusEnum.PASS.getStatus() : MesWmQualityStatusEnum.FAIL.getStatus(); |
| | | productSalesLineMapper.updateById(new MesWmProductSalesLineDO() |
| | | .setId(id).setOqcId(oqcId).setQualityStatus(qualityStatus)); |