| | |
| | | @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); |
| | | } |
| | | } |
| | |
| | | public void exportStockOutRecord(HttpServletResponse response, StockOutRecordDto stockOutRecordDto) { |
| | | List<StockOutRecordExportData> list = stockOutRecordMapper.listStockOutRecordExportData(stockOutRecordDto); |
| | | for (StockOutRecordExportData stockInRecordExportData : list) { |
| | | if (stockInRecordExportData.getType().equals("0")) { |
| | | stockInRecordExportData.setRecordType(EnumUtil.fromCode(StockOutQualifiedRecordTypeEnum.class, Integer.parseInt(stockInRecordExportData.getRecordType())).getValue()); |
| | | }else { |
| | | stockInRecordExportData.setRecordType(EnumUtil.fromCode(StockInQualifiedRecordTypeEnum.class, Integer.parseInt(stockInRecordExportData.getRecordType())).getValue()); |
| | | if (StringUtils.isEmpty(stockInRecordExportData.getRecordType())) { |
| | | continue; |
| | | } |
| | | StockOutQualifiedRecordTypeEnum outRecordTypeEnum = |
| | | EnumUtil.fromCode(StockOutQualifiedRecordTypeEnum.class, Integer.parseInt(stockInRecordExportData.getRecordType())); |
| | | if (outRecordTypeEnum != null) { |
| | | stockInRecordExportData.setRecordType(outRecordTypeEnum.getValue()); |
| | | continue; |
| | | } |
| | | StockInQualifiedRecordTypeEnum inRecordTypeEnum = |
| | | EnumUtil.fromCode(StockInQualifiedRecordTypeEnum.class, Integer.parseInt(stockInRecordExportData.getRecordType())); |
| | | if (inRecordTypeEnum != null) { |
| | | stockInRecordExportData.setRecordType(inRecordTypeEnum.getValue()); |
| | | } |
| | | } |
| | | ExcelUtil<StockOutRecordExportData> util = new ExcelUtil<>(StockOutRecordExportData.class); |
| | |
| | | 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; |
| | | } |
| | | } |