| | |
| | | import cn.iocoder.yudao.module.mes.service.mdm.MesMdmItemService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.batch.MesWmBatchService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.materialstock.MesWmMaterialStockService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.stockwarning.MesWmStockWarningService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.transaction.dto.MesWmTransactionSaveReqDTO; |
| | | import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseAreaService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseLocationService; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | |
| | | private MesWmWarehouseLocationService locationService; |
| | | @Resource |
| | | private MesWmWarehouseAreaService areaService; |
| | | @Resource |
| | | private MesWmStockWarningService stockWarningService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | if (materialStock == null) { |
| | | throw exception(WM_MATERIAL_STOCK_NOT_EXISTS); |
| | | } |
| | | // 校验物料、批次、仓库等维度一致(防止传入错误的 materialStockId) |
| | | // 校验物料、批次、仓库等维度一致(防止传入错误的 materialStockId)。 |
| | | // 若此处不一致,通常是该库存已被移库/合并/拆分,需退回重新拣货,故给出针对性提示 |
| | | if (ObjUtil.notEqual(materialStock.getItemId(), reqDTO.getItemId()) |
| | | || ObjUtil.notEqual(materialStock.getWarehouseId(), reqDTO.getWarehouseId()) |
| | | || ObjUtil.notEqual(materialStock.getLocationId(), reqDTO.getLocationId()) |
| | | || ObjUtil.notEqual(materialStock.getAreaId(), reqDTO.getAreaId())) { |
| | | throw exception(WM_MATERIAL_STOCK_SELECTION_MISMATCH); |
| | | throw new ServiceException(WM_MATERIAL_STOCK_SELECTION_MISMATCH.getCode(), |
| | | "该库存记录已变动(可能被移库/合并/拆分),与出库明细不一致,无法扣减,请退回重新拣货"); |
| | | } |
| | | } else if (isInbound) { |
| | | // 入库事务:根据 forceCreateNewStock 标志决定是创建新记录还是查找/创建 |
| | |
| | | // 2.3 更新库存数量 |
| | | boolean checkFlag = ObjUtil.defaultIfNull(reqDTO.getCheckFlag(), true); |
| | | materialStockService.updateMaterialStockQuantity(materialStock.getId(), reqDTO.getQuantity(), checkFlag); |
| | | // 2.4 库存预警校验:本次变动导致库存跨越上下限时,自动发送站内通知(需求 5.1②) |
| | | stockWarningService.checkAfterStockChange(reqDTO.getItemId(), reqDTO.getWarehouseId(), reqDTO.getQuantity()); |
| | | |
| | | // 3. 插入事务流水 |
| | | MesWmTransactionDO transaction = MesWmTransactionDO.builder() |