| | |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi; |
| | | import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemCreateReqDTO; |
| | | 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.unit.MdmUnitMeasureApi; |
| | | import cn.iocoder.yudao.module.mdm.api.unit.dto.MdmUnitMeasureRespDTO; |
| | | import cn.iocoder.yudao.module.mdm.enums.MdmItemTypeEnum; |
| | |
| | | // ========== 设备物料联动依赖 ========== |
| | | @Resource |
| | | private MdmItemApi mdmItemApi; |
| | | @Resource |
| | | private MdmItemCategoryApi mdmItemCategoryApi; |
| | | @Resource |
| | | private MdmUnitMeasureApi mdmUnitMeasureApi; |
| | | @Resource |
| | |
| | | * @return MDM 物料编号(= MES 物料编号) |
| | | */ |
| | | private Long createEquipmentMaterial(String code, String name, String specification, String remark) { |
| | | // 1. 解析“设备”类型(MES 侧)与“台”单位(MDM 侧 + MES 侧),缺失则提示主数据未初始化 |
| | | // 1. 分别按编码解析 MDM 分类、MES 类型和两侧单位,禁止依赖两套表主键恰好一致。 |
| | | MesMdItemTypeDO itemType = mesMdItemTypeService.getItemTypeByCode(EQUIPMENT_ITEM_TYPE_CODE); |
| | | if (itemType == null) { |
| | | throw exception(DV_MACHINERY_EQUIP_MASTER_MISSING); |
| | | } |
| | | CommonResult<MdmItemCategoryRespDTO> categoryResult = |
| | | mdmItemCategoryApi.getItemCategoryByCode(EQUIPMENT_ITEM_TYPE_CODE); |
| | | MdmItemCategoryRespDTO mdmCategory = categoryResult.isSuccess() ? categoryResult.getData() : null; |
| | | if (mdmCategory == null) { |
| | | throw exception(DV_MACHINERY_EQUIP_MASTER_MISSING); |
| | | } |
| | | if (mesMdUnitMeasureService.getUnitMeasureByCode(EQUIPMENT_UNIT_CODE) == null) { |
| | |
| | | throw exception(DV_MACHINERY_EQUIP_MASTER_MISSING); |
| | | } |
| | | |
| | | // 2. 创建 MDM 物料;分类使用“设备”分类(其 id 与 MES 类型 id 对齐,由初始化脚本保证) |
| | | // 2. 创建 MDM 物料;分类取 MDM 自身主键,允许不同环境中两套分类表的主键不一致。 |
| | | MdmItemCreateReqDTO createReqDTO = new MdmItemCreateReqDTO(); |
| | | createReqDTO.setCode(code); |
| | | createReqDTO.setName(name); |
| | | createReqDTO.setSpecification(specification); |
| | | createReqDTO.setRemark(remark); |
| | | createReqDTO.setCategoryId(itemType.getId()); |
| | | createReqDTO.setCategoryId(mdmCategory.getId()); |
| | | createReqDTO.setUnitMeasureId(mdmUnit.getId()); |
| | | createReqDTO.setItemType(MdmItemTypeEnum.EQUIPMENT.getType()); |
| | | createReqDTO.setStatus(0); |