| | |
| | | import cn.hutool.core.lang.Assert; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.transaction.vo.MesWmTransactionPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.mdm.MesMdmItemDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.materialstock.MesWmMaterialStockDO; |
| | |
| | | // 1.5 关联事务校验 |
| | | checkRelatedTransaction(reqDTO); |
| | | |
| | | // 2.1 获取或创建库存记录 |
| | | MesWmMaterialStockDO materialStock = materialStockService.getOrCreateMaterialStock( |
| | | reqDTO.getItemId(), reqDTO.getWarehouseId(), reqDTO.getLocationId(), reqDTO.getAreaId(), |
| | | reqDTO.getBatchId(), reqDTO.getBatchCode(), reqDTO.getVendorId(), reqDTO.getReceiptTime()); |
| | | // 2.1 获取或创建库存记录(如果传入了 materialStockId 则直接使用,避免重新匹配) |
| | | MesWmMaterialStockDO materialStock; |
| | | if (reqDTO.getMaterialStockId() != null) { |
| | | materialStock = materialStockService.getMaterialStock(reqDTO.getMaterialStockId()); |
| | | if (materialStock == null) { |
| | | throw exception(WM_MATERIAL_STOCK_NOT_EXISTS); |
| | | } |
| | | // 校验物料、批次、仓库等维度一致(防止传入错误的 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); |
| | | } |
| | | } else { |
| | | materialStock = materialStockService.getOrCreateMaterialStock( |
| | | reqDTO.getItemId(), reqDTO.getWarehouseId(), reqDTO.getLocationId(), reqDTO.getAreaId(), |
| | | reqDTO.getBatchId(), reqDTO.getBatchCode(), reqDTO.getVendorId(), reqDTO.getReceiptTime()); |
| | | } |
| | | // 2.2 冻结校验(仓库、库区、库位、库存记录) |
| | | checkFrozen(reqDTO, materialStock); |
| | | // 2.3 更新库存数量 |
| | |
| | | reqDTOs.forEach(this::createTransaction); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<MesWmTransactionDO> getTransactionPage(MesWmTransactionPageReqVO pageReqVO) { |
| | | return transactionMapper.selectPage(pageReqVO); |
| | | } |
| | | |
| | | // ==================== 私有校验方法 ==================== |
| | | |
| | | /** |