| | |
| | | @AllArgsConstructor |
| | | public class StockInRecordServiceImpl extends ServiceImpl<StockInRecordMapper, StockInRecord> implements StockInRecordService { |
| | | |
| | | private static final String UNQUALIFIED_TYPE = "unqualified"; |
| | | private static final String WASTE_TYPE = "waste"; |
| | | |
| | | private StockInRecordMapper stockInRecordMapper; |
| | | private StockInventoryMapper stockInventoryMapper; |
| | | private StockUninventoryMapper stockUninventoryMapper; |
| | |
| | | stockInventoryMapper.updateSubtractStockInventory(stockInRecordDto); |
| | | } |
| | | }else if (stockInRecord.getType().equals("1")) { |
| | | String uninventoryType = resolveUninventoryTypeByInRecordType(stockInRecord.getRecordType()); |
| | | LambdaQueryWrapper<StockUninventory> eq = new LambdaQueryWrapper<StockUninventory>() |
| | | .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId()); |
| | | .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId()) |
| | | .eq(StockUninventory::getType, uninventoryType); |
| | | if (StringUtils.isEmpty(stockInRecord.getBatchNo())) { |
| | | eq.isNull(StockUninventory::getBatchNo); |
| | | } else { |
| | |
| | | stockUninventoryDto.setProductModelId(stockUninventory.getProductModelId()); |
| | | stockUninventoryDto.setBatchNo(stockUninventory.getBatchNo()); |
| | | stockUninventoryDto.setQualitity(stockInRecord.getStockInNum()); |
| | | 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 { |
| | |
| | | } |
| | | } else if ("1".equals(stockInRecord.getType())) { |
| | | // 不合格入库 -> 先查库存,存在则更新,不存在则新增 |
| | | StockUninventory stockUninventory = getStockUninventory(stockInRecord.getProductModelId(), stockInRecord.getBatchNo()); |
| | | String uninventoryType = resolveUninventoryTypeByInRecordType(stockInRecord.getRecordType()); |
| | | StockUninventory stockUninventory = getStockUninventory(stockInRecord.getProductModelId(), stockInRecord.getBatchNo(), uninventoryType); |
| | | StockUninventoryDto stockUninventoryDto = new StockUninventoryDto(); |
| | | stockUninventoryDto.setProductModelId(stockInRecord.getProductModelId()); |
| | | stockUninventoryDto.setBatchNo(stockInRecord.getBatchNo()); |
| | |
| | | stockUninventoryDto.setRemark(stockInRecord.getRemark()); |
| | | stockUninventoryDto.setManufacturerId(stockInRecord.getManufacturerId()); |
| | | stockUninventoryDto.setSource(stockInRecord.getSource()); |
| | | stockUninventoryDto.setType(uninventoryType); |
| | | if (stockUninventory == null) { |
| | | stockUninventoryMapper.insert(new StockUninventory() {{ |
| | | setProductModelId(stockInRecord.getProductModelId()); |
| | | setQualitity(finalStockInNum); |
| | | setBatchNo(stockInRecord.getBatchNo()); |
| | | setType(uninventoryType); |
| | | setRemark(stockInRecord.getRemark()); |
| | | setManufacturerId(stockInRecord.getManufacturerId()); |
| | | setSource(stockInRecord.getSource()); |
| | |
| | | return items.size(); |
| | | } |
| | | |
| | | private String resolveUninventoryTypeByInRecordType(String recordType) { |
| | | if (StockInQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode().equals(recordType)) { |
| | | return WASTE_TYPE; |
| | | } |
| | | return UNQUALIFIED_TYPE; |
| | | } |
| | | |
| | | private void adjustPurchaseInboundAuditFields(StockInRecord stockInRecord, BigDecimal finalStockInNum) { |
| | | if (stockInRecord == null || finalStockInNum == null) { |
| | | return; |