| | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class StockOutRecordServiceImpl extends ServiceImpl<StockOutRecordMapper, StockOutRecord> implements StockOutRecordService { |
| | | private static final String UNQUALIFIED_TYPE = "unqualified"; |
| | | private static final String WASTE_TYPE = "waste"; |
| | | |
| | | private final StockOutRecordMapper stockOutRecordMapper; |
| | | private final StockInventoryMapper stockInventoryMapper; |
| | | private final StockUninventoryMapper stockUninventoryMapper; |
| | |
| | | } |
| | | } |
| | | else if (stockOutRecord.getType().equals("1")) { |
| | | String uninventoryType = resolveUninventoryTypeByOutRecordType(stockOutRecord.getRecordType()); |
| | | LambdaQueryWrapper<StockUninventory> wrapper = new LambdaQueryWrapper<StockUninventory>() |
| | | .eq(StockUninventory::getProductModelId, stockOutRecord.getProductModelId()); |
| | | .eq(StockUninventory::getProductModelId, stockOutRecord.getProductModelId()) |
| | | .eq(StockUninventory::getType, uninventoryType); |
| | | if (StringUtils.isEmpty(stockOutRecord.getBatchNo())) { |
| | | wrapper.isNull(StockUninventory::getBatchNo); |
| | | } else { |
| | |
| | | stockUninventoryDto.setProductModelId(stockUninventory.getProductModelId()); |
| | | stockUninventoryDto.setQualitity(stockOutRecord.getStockOutNum()); |
| | | stockUninventoryDto.setBatchNo(stockUninventory.getBatchNo()); |
| | | stockUninventoryDto.setType(uninventoryType); |
| | | stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto); |
| | | } |
| | | } |
| | |
| | | stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto); |
| | | } else if ("1".equals(stockOutRecord.getType())) { |
| | | // 不合格出库 -> 先查库存是否存在,存在才扣减 |
| | | StockUninventory stockUninventory = getStockUninventory(stockOutRecord.getProductModelId(), stockOutRecord.getBatchNo()); |
| | | String uninventoryType = resolveUninventoryTypeByOutRecordType(stockOutRecord.getRecordType()); |
| | | StockUninventory stockUninventory = getStockUninventory(stockOutRecord.getProductModelId(), stockOutRecord.getBatchNo(), uninventoryType); |
| | | if (stockUninventory == null) { |
| | | throw new BaseException("不合格库存记录不存在,出库批次:" + stockOutRecord.getOutboundBatches()); |
| | | } |
| | |
| | | stockUninventoryDto.setProductModelId(stockOutRecord.getProductModelId()); |
| | | stockUninventoryDto.setBatchNo(stockOutRecord.getBatchNo()); |
| | | stockUninventoryDto.setQualitity(stockOutRecord.getStockOutNum()); |
| | | stockUninventoryDto.setType(uninventoryType); |
| | | stockUninventoryMapper.updateSubtractStockUnInventory(stockUninventoryDto); |
| | | } |
| | | } |
| | |
| | | return stockInventoryMapper.selectOne(eq); |
| | | } |
| | | |
| | | private StockUninventory getStockUninventory(Long productModelId, String batchNo) { |
| | | private StockUninventory getStockUninventory(Long productModelId, String batchNo, String uninventoryType) { |
| | | LambdaQueryWrapper<StockUninventory> eq = new LambdaQueryWrapper<>(); |
| | | eq.eq(StockUninventory::getProductModelId, productModelId); |
| | | if (StringUtils.isNotEmpty(uninventoryType)) { |
| | | eq.eq(StockUninventory::getType, uninventoryType); |
| | | } |
| | | if (StringUtils.isEmpty(batchNo)) { |
| | | eq.isNull(StockUninventory::getBatchNo); |
| | | } else { |
| | |
| | | } |
| | | return stockUninventoryMapper.selectOne(eq); |
| | | } |
| | | |
| | | private String resolveUninventoryTypeByOutRecordType(String recordType) { |
| | | if (StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode().equals(recordType)) { |
| | | return WASTE_TYPE; |
| | | } |
| | | return UNQUALIFIED_TYPE; |
| | | } |
| | | } |