xiaoyi
20 小时以前 4bec63c802692a402039f0d99eae068d26d63c55
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/api/item/MesMdItemApiImpl.java
@@ -18,9 +18,11 @@
import org.springframework.validation.annotation.Validated;
import java.util.Collection;
import java.util.Objects;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.invalidParamException;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
/**
@@ -50,6 +52,7 @@
    @Override
    public Long createItem(MesMdItemSyncReqDTO syncReqDTO) {
        log.info("[createItem] 同步创建 MES 物料产品,code={}, mdmItemId={}", syncReqDTO.getCode(), syncReqDTO.getMdmItemId());
        validateSharedId(syncReqDTO);
        MesMdItemSaveReqVO saveReqVO = buildSaveReqVO(syncReqDTO);
        // 使用 MDM 物料 ID 作为 MES 物料 ID
        if (syncReqDTO.getMdmItemId() != null) {
@@ -64,6 +67,7 @@
    @Override
    public void updateItem(MesMdItemSyncReqDTO syncReqDTO) {
        log.info("[updateItem] 同步更新 MES 物料产品,code={}, mdmItemId={}", syncReqDTO.getCode(), syncReqDTO.getMdmItemId());
        validateSharedId(syncReqDTO);
        MesMdItemSaveReqVO saveReqVO = buildSaveReqVO(syncReqDTO);
        // 使用 MDM 物料 ID 作为 MES 物料 ID
        if (syncReqDTO.getMdmItemId() != null) {
@@ -91,6 +95,17 @@
//        saveBatchConfig(itemId, syncReqDTO);
    }
    private void validateSharedId(MesMdItemSyncReqDTO syncReqDTO) {
        if (syncReqDTO.getMdmItemId() == null) {
            return;
        }
        MesMdItemDO existing = itemMapper.selectAnyById(syncReqDTO.getMdmItemId());
        if (existing != null && !Objects.equals(existing.getCode(), syncReqDTO.getCode())
                && !Objects.equals(existing.getCode(), syncReqDTO.getPreviousCode())) {
            throw invalidParamException("同步失败:生产物料编号已被其他编码占用,请核对两套物料数据后再操作");
        }
    }
    /**
     * 将同步 DTO 转换为 MES 物料产品 SaveReqVO,并按 code 解析单位/分类 id
     */