| | |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.wm.itemreceipt.MesWmItemReceiptLineMapper; |
| | | import cn.iocoder.yudao.module.mes.service.wm.arrivalnotice.MesWmArrivalNoticeLineService; |
| | | 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.transaction.annotation.Transactional; |
| | | 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; |
| | |
| | | private MesWmArrivalNoticeLineService arrivalNoticeLineService; |
| | | @Resource |
| | | private MesWmBatchService batchService; |
| | | @Resource |
| | | private MesWmItemUnitConvertService itemUnitConvertService; |
| | | |
| | | @Override |
| | | public Long createItemReceiptLine(MesWmItemReceiptLineSaveReqVO createReqVO) { |
| | |
| | | |
| | | // 3.1 创建入库单行 |
| | | MesWmItemReceiptLineDO line = BeanUtils.toBean(createReqVO, MesWmItemReceiptLineDO.class); |
| | | // 3.2 生成或获取批次 |
| | | // 3.2 双单位换算 |
| | | fillReceivedQuantity(line, createReqVO); |
| | | // 3.3 生成或获取批次 |
| | | MesWmBatchDO batch = generateOrGetBatch(receipt, createReqVO); |
| | | if (batch != null) { |
| | | line.setBatchId(batch.getId()); |
| | | line.setBatchCode(batch.getCode()); |
| | | } |
| | | // 3.3 插入数据库 |
| | | // 3.4 插入数据库 |
| | | itemReceiptLineMapper.insert(line); |
| | | return line.getId(); |
| | | } |
| | |
| | | |
| | | // 2.1 更新 |
| | | MesWmItemReceiptLineDO updateObj = BeanUtils.toBean(updateReqVO, MesWmItemReceiptLineDO.class); |
| | | // 2.2 生成或获取批次 |
| | | // 2.2 双单位换算 |
| | | fillReceivedQuantity(updateObj, updateReqVO); |
| | | // 2.3 生成或获取批次 |
| | | MesWmBatchDO batch = generateOrGetBatch(receipt, updateReqVO); |
| | | if (batch != null) { |
| | | updateObj.setBatchId(batch.getId()).setBatchCode(batch.getCode()); |
| | | } |
| | | // 2.3 更新数据库 |
| | | // 2.4 更新数据库 |
| | | itemReceiptLineMapper.updateById(updateObj); |
| | | } |
| | | |
| | | /** |
| | | * 双单位换算:按录入单位与所选型号,把录入数量换算为物料主单位的入库数量 |
| | | * |
| | | * 未选择录入单位时,说明本次按物料主单位录入,直接使用传入的入库数量。 |
| | | */ |
| | | private void fillReceivedQuantity(MesWmItemReceiptLineDO line, MesWmItemReceiptLineSaveReqVO reqVO) { |
| | | if (reqVO.getEnterUnitMeasureId() != null) { |
| | | BigDecimal primaryQuantity = itemUnitConvertService.convertToPrimaryUnit( |
| | | reqVO.getItemId(), reqVO.getItemModelId(), |
| | | reqVO.getEnterUnitMeasureId(), reqVO.getEnterQuantity()); |
| | | if (primaryQuantity != null) { |
| | | line.setReceivedQuantity(primaryQuantity); |
| | | } |
| | | } |
| | | if (line.getReceivedQuantity() == null) { |
| | | throw exception(WM_ITEM_RECEIPT_LINE_QUANTITY_REQUIRED); |
| | | } |
| | | } |
| | | |
| | | private void validateItemReceiptLineSaveData(MesWmItemReceiptDO receipt, MesWmItemReceiptLineSaveReqVO reqVO) { |
| | | // 校验关联到货通知单行 |
| | | validateArrivalNoticeLine(receipt, reqVO.getArrivalNoticeLineId()); |