| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.feedback.MesProFeedbackDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProductBomDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProductDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemTypeDO; |
| | | import cn.iocoder.yudao.module.mes.enums.md.MesMdItemTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemTypeService; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.workorder.MesProWorkOrderDO; |
| | | import cn.iocoder.yudao.module.mes.enums.pro.MesProMpsStatusEnum; |
| | |
| | | @Resource |
| | | private MesMdItemService itemService; |
| | | @Resource |
| | | private MesMdItemTypeService itemTypeService; |
| | | @Resource |
| | | private MesMdAutoCodeRecordService autoCodeRecordService; |
| | | @Resource |
| | | private CrmCustomerApi customerApi; |
| | |
| | | Long mdmItemId, String productName, BigDecimal quantity, Long clientId, |
| | | String requestDate, String remark) { |
| | | // 1. 根据 MDM 物料 ID 查找 MES 产品 |
| | | cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO mesItem = itemService.getItemByMdmItemId(mdmItemId); |
| | | MesMdItemDO mesItem = itemService.getItemByMdmItemId(mdmItemId); |
| | | if (mesItem == null) { |
| | | // MES 产品不存在,抛出异常并包含产品名称提示 |
| | | throw exception(PRO_MPS_MES_PRODUCT_NOT_EXISTS, productName != null ? productName : mdmItemId); |
| | | } |
| | | validateProductItem(mesItem.getId()); |
| | | |
| | | // 2. 生成 MPS 编码 |
| | | String code = generateMpsCode(); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createMps(MesProMpsSaveReqVO createReqVO) { |
| | | // 校验产品存在 |
| | | itemService.validateItemExists(createReqVO.getProductId()); |
| | | // 校验产品存在、启用且为产品类型 |
| | | validateProductItem(createReqVO.getProductId()); |
| | | |
| | | // 如果未填写编码,自动生成 |
| | | if (StrUtil.isBlank(createReqVO.getCode())) { |
| | |
| | | public void updateMps(MesProMpsSaveReqVO updateReqVO) { |
| | | // 校验存在 + 草稿状态 |
| | | validateMpsExistsAndDraft(updateReqVO.getId()); |
| | | // 校验产品存在、启用且为产品类型 |
| | | validateProductItem(updateReqVO.getProductId()); |
| | | |
| | | // 校验编码唯一 |
| | | validateMpsCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 校验产品存在、启用且为产品类型 |
| | | */ |
| | | private void validateProductItem(Long itemId) { |
| | | MesMdItemDO item = itemService.validateItemExistsAndEnable(itemId); |
| | | MesMdItemTypeDO itemType = itemTypeService.getItemType(item.getItemTypeId()); |
| | | if (itemType == null || !MesMdItemTypeEnum.isProduct(itemType.getItemOrProduct())) { |
| | | throw exception(PRO_MPS_PRODUCT_TYPE_INVALID); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据 MPS 创建生产工单 |
| | | */ |
| | | private Long createWorkOrderFromMps(MesProMpsDO mps, BigDecimal quantity) { |