| | |
| | | import cn.iocoder.yudao.module.mes.service.mdm.MesMdmItemService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderBomService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.batch.MesWmBatchService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.unitconvert.MesWmItemUnitConvertService; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_OUTSOURCE_ISSUE_LINE_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_OUTSOURCE_ISSUE_LINE_ITEM_NOT_IN_BOM; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_OUTSOURCE_ISSUE_LINE_QUANTITY_REQUIRED; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_OUTSOURCE_ISSUE_NOT_EXISTS; |
| | | |
| | | /** |
| | |
| | | private MesWmBatchService batchService; |
| | | @Resource |
| | | private MesProWorkOrderBomService workOrderBomService; |
| | | @Resource |
| | | private MesWmItemUnitConvertService itemUnitConvertService; |
| | | |
| | | @Override |
| | | public Long createOutsourceIssueLine(MesWmOutsourceIssueLineSaveReqVO createReqVO) { |
| | |
| | | validateOutsourceIssueLineSaveData(createReqVO); |
| | | // 根据 batchCode 解析 batchId |
| | | fillBatchId(createReqVO); |
| | | // 双单位换算:按录入单位换算为物料主单位数量 |
| | | fillPrimaryQuantity(createReqVO); |
| | | |
| | | // 插入 |
| | | MesWmOutsourceIssueLineDO line = BeanUtils.toBean(createReqVO, MesWmOutsourceIssueLineDO.class); |
| | |
| | | validateOutsourceIssueLineSaveData(updateReqVO); |
| | | // 根据 batchCode 解析 batchId |
| | | fillBatchId(updateReqVO); |
| | | // 双单位换算:按录入单位换算为物料主单位数量 |
| | | fillPrimaryQuantity(updateReqVO); |
| | | |
| | | // 更新 |
| | | MesWmOutsourceIssueLineDO updateObj = BeanUtils.toBean(updateReqVO, MesWmOutsourceIssueLineDO.class); |
| | | outsourceIssueLineMapper.updateById(updateObj); |
| | | } |
| | | |
| | | /** |
| | | * 双单位换算:选择了录入单位时,按「录入数量 × 换算比率」得到物料主单位口径的发料数量 |
| | | * |
| | | * 未按辅单位录入时必须直接填写发料数量 |
| | | */ |
| | | private void fillPrimaryQuantity(MesWmOutsourceIssueLineSaveReqVO reqVO) { |
| | | if (reqVO.getEnterUnitMeasureId() != null) { |
| | | BigDecimal primaryQuantity = itemUnitConvertService.convertToPrimaryUnit( |
| | | reqVO.getItemId(), reqVO.getItemModelId(), |
| | | reqVO.getEnterUnitMeasureId(), reqVO.getEnterQuantity()); |
| | | if (primaryQuantity != null) { |
| | | reqVO.setQuantity(primaryQuantity); |
| | | } |
| | | } |
| | | if (reqVO.getQuantity() == null) { |
| | | throw exception(WM_OUTSOURCE_ISSUE_LINE_QUANTITY_REQUIRED); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void deleteOutsourceIssueLine(Long id) { |
| | | // 校验存在 |