云
2026-10-26 63ba72f5d65a3a4dcd56d9228582042448af61d7
feat(mdm): 统一物料分类管理并迁移至MDM模块

- 在MdmItemCategoryApi中新增获取全部分类列表、创建、更新、删除物料分类接口
- 实现MdmItemCategoryApiImpl中的新增接口方法,包括全量查询、CRUD操作
- 扩展MdmItemCategoryRespDTO添加remark和createTime字段
- 在MdmItemCategoryService中新增getItemCategoryAllList方法
- 实现MdmItemCategoryServiceImpl中的全量查询方法
- 修改MesMdItemTypeServiceImpl将底层存储切换至MDM分类API
- 移除MES模块中本地数据库操作,全部通过MDM API进行分类管理
- 更新导入功能适配新的MDM分类API调用方式
- 添加MdmItemCategorySaveReqDTO传输对象支持分类增改操作
已添加1个文件
已修改6个文件
353 ■■■■■ 文件已修改
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApi.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApiImpl.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategoryRespDTO.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategorySaveReqDTO.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java 239 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApi.java
@@ -2,6 +2,7 @@
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategoryRespDTO;
import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategorySaveReqDTO;
import java.util.Collection;
import java.util.List;
@@ -55,4 +56,33 @@
     */
    CommonResult<MdmItemCategoryRespDTO> getItemCategoryByItemOrProduct(String itemOrProduct);
    /**
     * èŽ·å–å…¨éƒ¨åˆ†ç±»åˆ—è¡¨ï¼ˆå«ç¦ç”¨ï¼‰
     *
     * @return åˆ†ç±»åˆ—表
     */
    CommonResult<List<MdmItemCategoryRespDTO>> getItemCategoryAllList();
    /**
     * åˆ›å»ºç‰©æ–™åˆ†ç±»
     *
     * @param createReqDTO åˆ›å»ºä¿¡æ¯
     * @return åˆ†ç±»ç¼–号
     */
    CommonResult<Long> createItemCategory(MdmItemCategorySaveReqDTO createReqDTO);
    /**
     * æ›´æ–°ç‰©æ–™åˆ†ç±»
     *
     * @param updateReqDTO æ›´æ–°ä¿¡æ¯
     */
    CommonResult<Boolean> updateItemCategory(MdmItemCategorySaveReqDTO updateReqDTO);
    /**
     * åˆ é™¤ç‰©æ–™åˆ†ç±»
     *
     * @param id åˆ†ç±»ç¼–号
     */
    CommonResult<Boolean> deleteItemCategory(Long id);
}
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/MdmItemCategoryApiImpl.java
@@ -3,6 +3,8 @@
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategoryRespDTO;
import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategorySaveReqDTO;
import cn.iocoder.yudao.module.mdm.controller.admin.category.vo.MdmItemCategorySaveReqVO;
import cn.iocoder.yudao.module.mdm.dal.dataobject.category.MdmItemCategoryDO;
import cn.iocoder.yudao.module.mdm.service.category.MdmItemCategoryService;
import jakarta.annotation.Resource;
@@ -58,4 +60,29 @@
        return success(BeanUtils.toBean(itemCategory, MdmItemCategoryRespDTO.class));
    }
    @Override
    public CommonResult<List<MdmItemCategoryRespDTO>> getItemCategoryAllList() {
        List<MdmItemCategoryDO> list = itemCategoryService.getItemCategoryAllList();
        return success(BeanUtils.toBean(list, MdmItemCategoryRespDTO.class));
    }
    @Override
    public CommonResult<Long> createItemCategory(MdmItemCategorySaveReqDTO createReqDTO) {
        MdmItemCategorySaveReqVO reqVO = BeanUtils.toBean(createReqDTO, MdmItemCategorySaveReqVO.class);
        return success(itemCategoryService.createItemCategory(reqVO));
    }
    @Override
    public CommonResult<Boolean> updateItemCategory(MdmItemCategorySaveReqDTO updateReqDTO) {
        MdmItemCategorySaveReqVO reqVO = BeanUtils.toBean(updateReqDTO, MdmItemCategorySaveReqVO.class);
        itemCategoryService.updateItemCategory(reqVO);
        return success(true);
    }
    @Override
    public CommonResult<Boolean> deleteItemCategory(Long id) {
        itemCategoryService.deleteItemCategory(id);
        return success(true);
    }
}
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategoryRespDTO.java
@@ -3,6 +3,8 @@
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "RPC æœåŠ¡ - MDM ç‰©æ–™åˆ†ç±» Response DTO")
@Data
public class MdmItemCategoryRespDTO {
@@ -31,4 +33,10 @@
    @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
    private Integer status;
    @Schema(description = "备注", example = "备注信息")
    private String remark;
    @Schema(description = "创建时间")
    private LocalDateTime createTime;
}
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/api/category/dto/MdmItemCategorySaveReqDTO.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.mdm.api.category.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "RPC æœåŠ¡ - MDM ç‰©æ–™åˆ†ç±»æ–°å¢ž/修改 Request DTO")
@Data
public class MdmItemCategorySaveReqDTO {
    @Schema(description = "分类编号(新增时为空)", example = "1")
    private Long id;
    @Schema(description = "父分类编号(根节点=0)", example = "0")
    private Long parentId;
    @Schema(description = "分类编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "CAT001")
    private String code;
    @Schema(description = "分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "五金配件")
    private String name;
    @Schema(description = "物料类型:1物料、2产品、3半成品、NULL全部", example = "1")
    private Integer itemType;
    @Schema(description = "物料/产品标识(兼容MES)", example = "ITEM")
    private String itemOrProduct;
    @Schema(description = "排序", example = "1")
    private Integer sort;
    @Schema(description = "状态:0启用、1禁用", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
    private Integer status;
    @Schema(description = "备注", example = "备注信息")
    private String remark;
}
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryService.java
@@ -90,6 +90,13 @@
    List<MdmItemCategoryDO> getItemCategoryList(Collection<Long> ids);
    /**
     * èŽ·å¾—å…¨éƒ¨åˆ†ç±»åˆ—è¡¨ï¼ˆå«ç¦ç”¨ï¼‰
     *
     * @return åˆ†ç±»åˆ—表
     */
    List<MdmItemCategoryDO> getItemCategoryAllList();
    /**
     * èŽ·å¾—ç‰©æ–™åˆ†ç±» Map
     *
     * @param ids ç¼–号数组
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/category/MdmItemCategoryServiceImpl.java
@@ -133,6 +133,11 @@
    }
    @Override
    public List<MdmItemCategoryDO> getItemCategoryAllList() {
        return itemCategoryMapper.selectList(new MdmItemCategoryDO());
    }
    @Override
    public List<MdmItemCategoryDO> getItemCategoryChildrenList(Long id) {
        List<MdmItemCategoryDO> result = new ArrayList<>();
        // æ·»åŠ è‡ªå·±
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java
@@ -4,16 +4,16 @@
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mdm.api.category.MdmItemCategoryApi;
import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategoryRespDTO;
import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategorySaveReqDTO;
import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeImportExcelVO;
import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeImportRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeListReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemTypeDO;
import cn.iocoder.yudao.module.mes.dal.mysql.md.item.MesMdItemTypeMapper;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@@ -29,8 +29,8 @@
/**
 * MES ç‰©æ–™äº§å“åˆ†ç±» Service å®žçŽ°ç±»
 *
 * å…¼å®¹å±‚实现:数据存储在 mes_md_item_type è¡¨ï¼Œä½†ä¼˜å…ˆä»Ž MDM åˆ†ç±» API èŽ·å–
 * å®žé™…分类数据已迁移到 mdm_item_category è¡¨
 * ç‰©æ–™åˆ†ç±»å·²ç»Ÿä¸€ç”± MDM ç®¡ç†ï¼Œæ•°æ®å­˜å‚¨åœ¨ mdm_item_category è¡¨ã€‚
 * æœ¬æœåŠ¡ä¿ç•™ MES çš„分类接口,底层全部通过 {@link MdmItemCategoryApi} è¯»å†™ MDM åˆ†ç±»ã€‚
 *
 * @author è¶…级管理员
 */
@@ -38,73 +38,82 @@
@Validated
public class MesMdItemTypeServiceImpl implements MesMdItemTypeService {
    @Resource
    private MdmItemCategoryApi mdmItemCategoryApi;
    /** MDM ç‰©æ–™ç±»åž‹ï¼šç‰©æ–™ */
    private static final Integer MDM_ITEM_TYPE_MATERIAL = 1;
    /** MDM ç‰©æ–™ç±»åž‹ï¼šäº§å“ */
    private static final Integer MDM_ITEM_TYPE_PRODUCT = 2;
    /** MES ç‰©æ–™/产品标识:产品 */
    private static final String ITEM_OR_PRODUCT_PRODUCT = "PRODUCT";
    @Resource
    private MesMdItemTypeMapper itemTypeMapper;
    private MdmItemCategoryApi mdmItemCategoryApi;
    @Resource
    @Lazy
    private MesMdItemService itemService;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long createItemType(MesMdItemTypeSaveReqVO createReqVO) {
        // æ ¡éªŒæ•°æ®
        validateItemTypeSaveData(createReqVO);
        // æ’入到本地表(保持兼容)
        MesMdItemTypeDO itemType = BeanUtils.toBean(createReqVO, MesMdItemTypeDO.class);
        itemTypeMapper.insert(itemType);
        return itemType.getId();
        // æ ¡éªŒçˆ¶åˆ†ç±»
        validateParentItemType(createReqVO.getId(), createReqVO.getParentId());
        // å†™å…¥ MDM åˆ†ç±»è¡¨
        CommonResult<Long> result = mdmItemCategoryApi.createItemCategory(buildSaveDTO(createReqVO));
        return result.getData();
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateItemType(MesMdItemTypeSaveReqVO updateReqVO) {
        // æ ¡éªŒå­˜åœ¨
        validateItemTypeExists(updateReqVO.getId());
        // æ ¡éªŒæ•°æ®
        validateItemTypeSaveData(updateReqVO);
        // æ›´æ–°æœ¬åœ°è¡¨
        MesMdItemTypeDO updateObj = BeanUtils.toBean(updateReqVO, MesMdItemTypeDO.class);
        itemTypeMapper.updateById(updateObj);
        // æ ¡éªŒçˆ¶åˆ†ç±»
        validateParentItemType(updateReqVO.getId(), updateReqVO.getParentId());
        // æ›´æ–° MDM åˆ†ç±»è¡¨
        MdmItemCategorySaveReqDTO updateDTO = buildSaveDTO(updateReqVO);
        updateDTO.setId(updateReqVO.getId());
        mdmItemCategoryApi.updateItemCategory(updateDTO);
    }
    private void validateItemTypeSaveData(MesMdItemTypeSaveReqVO reqVO) {
        // æ ¡éªŒçˆ¶åˆ†ç±»ç¼–号的有效性
        validateParentItemType(reqVO.getId(), reqVO.getParentId());
        // æ ¡éªŒåˆ†ç±»åç§°çš„唯一性
        validateItemTypeNameUnique(reqVO.getId(), reqVO.getParentId(), reqVO.getName());
        // æ ¡éªŒåˆ†ç±»ç¼–码的唯一性
        validateItemTypeCodeUnique(reqVO.getId(), reqVO.getParentId(), reqVO.getCode());
    private MdmItemCategorySaveReqDTO buildSaveDTO(MesMdItemTypeSaveReqVO reqVO) {
        MdmItemCategorySaveReqDTO dto = new MdmItemCategorySaveReqDTO();
        dto.setParentId(ObjUtil.defaultIfNull(reqVO.getParentId(), MesMdItemTypeDO.PARENT_ID_ROOT));
        dto.setCode(reqVO.getCode());
        dto.setName(reqVO.getName());
        dto.setItemOrProduct(reqVO.getItemOrProduct());
        dto.setItemType(convertMdmItemType(reqVO.getItemOrProduct()));
        dto.setSort(ObjUtil.defaultIfNull(reqVO.getSort(), 0));
        dto.setStatus(ObjUtil.defaultIfNull(reqVO.getStatus(), CommonStatusEnum.ENABLE.getStatus()));
        dto.setRemark(reqVO.getRemark());
        return dto;
    }
    /**
     * MES ç‰©æ–™/产品标识 -> MDM ç‰©æ–™ç±»åž‹
     */
    private Integer convertMdmItemType(String itemOrProduct) {
        if (StrUtil.isBlank(itemOrProduct)) {
            return null;
        }
        return ITEM_OR_PRODUCT_PRODUCT.equalsIgnoreCase(itemOrProduct)
                ? MDM_ITEM_TYPE_PRODUCT : MDM_ITEM_TYPE_MATERIAL;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteItemType(Long id) {
        // 1.1 æ ¡éªŒå­˜åœ¨
        validateItemTypeExists(id);
        // 1.2 æ ¡éªŒæ˜¯å¦æœ‰å­åˆ†ç±»
        if (itemTypeMapper.selectCountByParentId(id) > 0) {
            throw exception(MD_ITEM_TYPE_EXITS_CHILDREN);
        }
        // 1.3 æ ¡éªŒæ˜¯å¦æœ‰ç‰©æ–™
        // 1.2 æ ¡éªŒæ˜¯å¦æœ‰ç‰©æ–™
        if (itemService.getItemCountByItemTypeId(id) > 0) {
            throw exception(MD_ITEM_TYPE_EXITS_ITEM);
        }
        // 2. åˆ é™¤
        itemTypeMapper.deleteById(id);
        // 2. åˆ é™¤ï¼ˆå­åˆ†ç±»ã€MDM ç‰©æ–™å¼•用由 MDM ä¾§æ ¡éªŒï¼‰
        mdmItemCategoryApi.deleteItemCategory(id);
    }
    private void validateItemTypeExists(Long id) {
        // ä¼˜å…ˆä»Ž MDM èŽ·å–
        CommonResult<MdmItemCategoryRespDTO> result = mdmItemCategoryApi.getItemCategory(id);
        if (result.isSuccess() && result.getData() != null) {
            return;
        }
        // å›žé€€åˆ°æœ¬åœ°è¡¨
        if (itemTypeMapper.selectById(id) == null) {
        if (getItemType(id) == null) {
            throw exception(MD_ITEM_TYPE_NOT_EXISTS);
        }
    }
@@ -117,14 +126,8 @@
        if (Objects.equals(id, parentId)) {
            throw exception(MD_ITEM_TYPE_PARENT_ERROR);
        }
        // 2. çˆ¶åˆ†ç±»ä¸å­˜åœ¨ - ä¼˜å…ˆä»Ž MDM èŽ·å–
        CommonResult<MdmItemCategoryRespDTO> result = mdmItemCategoryApi.getItemCategory(parentId);
        MesMdItemTypeDO parentItemType = null;
        if (result.isSuccess() && result.getData() != null) {
            parentItemType = convertToMesDO(result.getData());
        } else {
            parentItemType = itemTypeMapper.selectById(parentId);
        }
        // 2. çˆ¶åˆ†ç±»ä¸å­˜åœ¨
        MesMdItemTypeDO parentItemType = getItemType(parentId);
        if (parentItemType == null) {
            throw exception(MD_ITEM_TYPE_PARENT_NOT_EXITS);
        }
@@ -140,60 +143,35 @@
            if (parentId == null || MesMdItemTypeDO.PARENT_ID_ROOT.equals(parentId)) {
                break;
            }
            // ç»§ç»­æŸ¥æ‰¾çˆ¶çº§
            CommonResult<MdmItemCategoryRespDTO> parentResult = mdmItemCategoryApi.getItemCategory(parentId);
            if (parentResult.isSuccess() && parentResult.getData() != null) {
                parentItemType = convertToMesDO(parentResult.getData());
            } else {
                parentItemType = itemTypeMapper.selectById(parentId);
            }
            parentItemType = getItemType(parentId);
            if (parentItemType == null) {
                break;
            }
        }
    }
    private void validateItemTypeNameUnique(Long id, Long parentId, String name) {
        MesMdItemTypeDO itemType = itemTypeMapper.selectByParentIdAndName(parentId, name);
        if (itemType == null) {
            return;
        }
        if (ObjUtil.notEqual(itemType.getId(), id)) {
            throw exception(MD_ITEM_TYPE_NAME_DUPLICATE);
        }
    }
    private void validateItemTypeCodeUnique(Long id, Long parentId, String code) {
        MesMdItemTypeDO itemType = itemTypeMapper.selectByParentIdAndCode(parentId, code);
        if (itemType == null) {
            return;
        }
        if (ObjUtil.notEqual(itemType.getId(), id)) {
            throw exception(MD_ITEM_TYPE_CODE_DUPLICATE);
        }
    }
    @Override
    public MesMdItemTypeDO getItemType(Long id) {
        // ä¼˜å…ˆä»Ž MDM èŽ·å–
        CommonResult<MdmItemCategoryRespDTO> result = mdmItemCategoryApi.getItemCategory(id);
        if (result.isSuccess() && result.getData() != null) {
            return convertToMesDO(result.getData());
        }
        // å›žé€€åˆ°æœ¬åœ°è¡¨
        return itemTypeMapper.selectById(id);
        return result.isSuccess() ? convertToMesDO(result.getData()) : null;
    }
    @Override
    public MesMdItemTypeDO getItemTypeByCode(String code) {
        // ä»Žæœ¬åœ°è¡¨æŸ¥
        return itemTypeMapper.selectByCode(code);
        CommonResult<MdmItemCategoryRespDTO> result = mdmItemCategoryApi.getItemCategoryByCode(code);
        return result.isSuccess() ? convertToMesDO(result.getData()) : null;
    }
    @Override
    public List<MesMdItemTypeDO> getItemTypeList(MesMdItemTypeListReqVO listReqVO) {
        // ä»Žæœ¬åœ°è¡¨æŸ¥
        return itemTypeMapper.selectList(listReqVO);
        List<MesMdItemTypeDO> list = getAllItemTypeList();
        return list.stream()
                .filter(itemType -> StrUtil.isBlank(listReqVO.getName())
                        || StrUtil.contains(itemType.getName(), listReqVO.getName()))
                .filter(itemType -> listReqVO.getStatus() == null
                        || Objects.equals(listReqVO.getStatus(), itemType.getStatus()))
                .sorted(Comparator.comparing(itemType -> ObjUtil.defaultIfNull(itemType.getSort(), 0)))
                .toList();
    }
    @Override
@@ -201,12 +179,25 @@
        if (CollUtil.isEmpty(ids)) {
            return Collections.emptyList();
        }
        return itemTypeMapper.selectByIds(ids);
        CommonResult<List<MdmItemCategoryRespDTO>> result = mdmItemCategoryApi.getItemCategoryList(ids);
        return convertToMesDOList(result.isSuccess() ? result.getData() : null);
    }
    private List<MesMdItemTypeDO> getAllItemTypeList() {
        CommonResult<List<MdmItemCategoryRespDTO>> result = mdmItemCategoryApi.getItemCategoryAllList();
        return convertToMesDOList(result.isSuccess() ? result.getData() : null);
    }
    private List<MesMdItemTypeDO> convertToMesDOList(List<MdmItemCategoryRespDTO> list) {
        if (CollUtil.isEmpty(list)) {
            return new ArrayList<>();
        }
        return new ArrayList<>(list.stream().map(this::convertToMesDO).toList());
    }
    @Override
    public List<MesMdItemTypeDO> getItemTypeChildrenList(Long parentId) {
        List<MesMdItemTypeDO> allList = itemTypeMapper.selectList();
        List<MesMdItemTypeDO> allList = getAllItemTypeList();
        List<MesMdItemTypeDO> result = new ArrayList<>();
        collectItemTypeChildren(result, parentId, allList);
        return result;
@@ -225,6 +216,9 @@
     * è½¬æ¢ MDM åˆ†ç±» DTO ä¸º MES DO
     */
    private MesMdItemTypeDO convertToMesDO(MdmItemCategoryRespDTO dto) {
        if (dto == null) {
            return null;
        }
        MesMdItemTypeDO mesDO = new MesMdItemTypeDO();
        mesDO.setId(dto.getId());
        mesDO.setCode(dto.getCode());
@@ -233,6 +227,8 @@
        mesDO.setItemOrProduct(dto.getItemOrProduct());
        mesDO.setSort(dto.getSort());
        mesDO.setStatus(dto.getStatus());
        mesDO.setRemark(dto.getRemark());
        mesDO.setCreateTime(dto.getCreateTime());
        return mesDO;
    }
@@ -249,6 +245,7 @@
        MesMdItemTypeImportRespVO respVO = MesMdItemTypeImportRespVO.builder()
                .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>())
                .failureCodes(new LinkedHashMap<>()).build();
        List<MesMdItemTypeDO> allList = getAllItemTypeList();
        AtomicInteger index = new AtomicInteger(1);
        importItemTypeList.forEach(importItem -> {
            int currentIndex = index.getAndIncrement();
@@ -268,7 +265,9 @@
            // 2.1 è§£æžçˆ¶åˆ†ç±»ï¼ˆä¸ºç©ºåˆ™é»˜è®¤ä¸ºæ ¹åˆ†ç±»ï¼‰
            Long parentId = MesMdItemTypeDO.PARENT_ID_ROOT;
            if (StrUtil.isNotBlank(importItem.getParentCode())) {
                MesMdItemTypeDO parentItemType = itemTypeMapper.selectByCode(importItem.getParentCode());
                MesMdItemTypeDO parentItemType = allList.stream()
                        .filter(itemType -> Objects.equals(importItem.getParentCode(), itemType.getCode()))
                        .findFirst().orElse(null);
                if (parentItemType == null) {
                    respVO.getFailureCodes().put(key, "父分类编码[" + importItem.getParentCode() + "]不存在");
                    return;
@@ -276,27 +275,49 @@
                parentId = parentItemType.getId();
            }
            // 2.2 åˆ¤æ–­æ˜¯å¦å­˜åœ¨ï¼ˆåŒä¸€çˆ¶åˆ†ç±»ä¸‹ç¼–码唯一)
            MesMdItemTypeDO existItemType = itemTypeMapper.selectByParentIdAndCode(parentId, importItem.getCode());
            if (existItemType == null) {
                // 2.2.1 æ–°å¢ž
                MesMdItemTypeDO itemType = BeanUtils.toBean(importItem, MesMdItemTypeDO.class);
                itemType.setParentId(parentId);
                itemType.setSort(ObjUtil.defaultIfNull(importItem.getSort(), 0));
                itemType.setStatus(ObjUtil.defaultIfNull(importItem.getStatus(), CommonStatusEnum.ENABLE.getStatus()));
                itemTypeMapper.insert(itemType);
                respVO.getCreateCodes().add(importItem.getCode());
            } else if (updateSupport) {
                // 2.2.2 æ›´æ–°
                MesMdItemTypeDO updateObj = BeanUtils.toBean(importItem, MesMdItemTypeDO.class);
                updateObj.setId(existItemType.getId());
                updateObj.setParentId(parentId);
                itemTypeMapper.updateById(updateObj);
                respVO.getUpdateCodes().add(importItem.getCode());
            } else {
                respVO.getFailureCodes().put(key, "分类编码已存在");
            Long finalParentId = parentId;
            MesMdItemTypeDO existItemType = allList.stream()
                    .filter(itemType -> Objects.equals(finalParentId, itemType.getParentId())
                            && Objects.equals(importItem.getCode(), itemType.getCode()))
                    .findFirst().orElse(null);
            try {
                MdmItemCategorySaveReqDTO dto = new MdmItemCategorySaveReqDTO();
                dto.setParentId(parentId);
                dto.setCode(importItem.getCode());
                dto.setName(importItem.getName());
                dto.setItemOrProduct(importItem.getItemOrProduct());
                dto.setItemType(convertMdmItemType(importItem.getItemOrProduct()));
                dto.setSort(ObjUtil.defaultIfNull(importItem.getSort(), 0));
                dto.setStatus(ObjUtil.defaultIfNull(importItem.getStatus(), CommonStatusEnum.ENABLE.getStatus()));
                dto.setRemark(importItem.getRemark());
                if (existItemType == null) {
                    // 2.2.1 æ–°å¢ž
                    dto.setId(null);
                    Long id = mdmItemCategoryApi.createItemCategory(dto).getData();
                    MesMdItemTypeDO created = new MesMdItemTypeDO();
                    created.setId(id);
                    created.setParentId(parentId);
                    created.setCode(importItem.getCode());
                    created.setName(importItem.getName());
                    created.setItemOrProduct(importItem.getItemOrProduct());
                    created.setSort(dto.getSort());
                    created.setStatus(dto.getStatus());
                    created.setRemark(importItem.getRemark());
                    allList.add(created);
                    respVO.getCreateCodes().add(importItem.getCode());
                } else if (updateSupport) {
                    // 2.2.2 æ›´æ–°
                    dto.setId(existItemType.getId());
                    mdmItemCategoryApi.updateItemCategory(dto);
                    respVO.getUpdateCodes().add(importItem.getCode());
                } else {
                    respVO.getFailureCodes().put(key, "分类编码已存在");
                }
            } catch (ServiceException e) {
                respVO.getFailureCodes().put(key, e.getMessage());
            }
        });
        return respVO;
    }
}
}