2 天以前 1ba0dbfde5634c8bf2ec20891d6b226b996f6b59
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/batch/MesWmBatchServiceImpl.java
@@ -423,13 +423,21 @@
        if (proBatch == null || StrUtil.isBlank(proBatch.getCode())) {
            return null;
        }
        // 1. 复用已有仓库批次(同一生产批次号)
        MesWmBatchDO existing = batchMapper.selectByCode(proBatch.getCode());
        // 1. 优先按生产批次 ID 复用,兼容历史数据再按批次号匹配
        MesWmBatchDO existing = batchMapper.selectOne(MesWmBatchDO::getProBatchId, proBatch.getId());
        if (existing == null) {
            existing = batchMapper.selectByCode(proBatch.getCode());
        }
        if (existing != null) {
            if (existing.getProBatchId() == null && proBatch.getId() != null) {
                existing.setProBatchId(proBatch.getId());
                batchMapper.updateById(existing);
            }
            return existing;
        }
        // 2. 新建仓库批次:以生产批次号作为仓库批次号,质量状态置为待检验
        MesWmBatchDO batch = MesWmBatchDO.builder()
                .proBatchId(proBatch.getId())
                .code(proBatch.getCode())
                .itemId(proBatch.getItemId())
                .produceDate(proBatch.getProduceDate())