diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java index 240d47f..7af459f 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java @@ -34,6 +34,7 @@ public interface ErrorCodeConstants { // ========== MES 基础数据-物料批次属性配置(1-040-102-100) ========== ErrorCode MD_ITEM_BATCH_CONFIG_NOT_EXISTS = new ErrorCode(1_040_102_100, "物料批次属性配置不存在"); ErrorCode MD_ITEM_BATCH_CONFIG_AT_LEAST_ONE_FLAG = new ErrorCode(1_040_102_101, "批次管理已启用,至少需要配置一个批次属性"); + ErrorCode MD_ITEM_PRODUCT_BOM_REQUIRED = new ErrorCode(1_040_102_102, "产品类物料启用前,必须配置至少一个 BOM 组成"); // ========== MES 仓库管理-批次管理(1-040-717-000) ========== ErrorCode WM_BATCH_PRODUCE_DATE_REQUIRED = new ErrorCode(1_040_717_000, "批次配置要求生产日期不能为空"); diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemServiceImpl.java index 07361b6..e66fd22 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemServiceImpl.java @@ -105,9 +105,18 @@ public class MesMdItemServiceImpl implements MesMdItemService { public void updateItemStatus(Long id, Integer status) { // 校验存在 MesMdItemDO item = validateItemExists(id); - // 如果启用,校验批次属性配置 - if (CommonStatusEnum.isEnable(status) && Boolean.TRUE.equals(item.getBatchFlag())) { - validateBatchConfigExists(id); + if (CommonStatusEnum.isEnable(status)) { + // 如果启用了批次管理,校验批次属性配置 + if (Boolean.TRUE.equals(item.getBatchFlag())) { + validateBatchConfigExists(id); + } + // 如果是产品类型,校验必须配置 BOM + MesMdItemTypeDO itemType = itemTypeService.getItemType(item.getItemTypeId()); + if (itemType != null && "PRODUCT".equals(itemType.getItemOrProduct())) { + if (CollUtil.isEmpty(productBomService.getProductBomListByItemId(id))) { + throw exception(MD_ITEM_PRODUCT_BOM_REQUIRED); + } + } } // 更新状态