| 
					
				 | 
			
			
				@@ -87,6 +87,9 @@ public class VoyageApiImpl implements VoyageApi{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (type == DistributorOrStoreEnum.DISTRIBUTOR.getValue()) {//分销商下单,当前阶段不考虑门店下单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //初定扣分销商库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //先返还初定扣的库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //再去扣初定的库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 preReduceStockDistributor(reqDTO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }finally { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -120,17 +123,403 @@ public class VoyageApiImpl implements VoyageApi{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void reduceStock(ReduceStockReqDTO reqDTO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //TODO: 当前阶段不考虑门店库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long voyageId = reqDTO.getVoyageId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //现在给整个航次的库存加锁 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String lockKey = String.format(ProductRedisKeyConstants.STOCK_REDIS_KEY_PREFIX, voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        RLock lock = redissonClient.getLock(lockKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            lock.lock(60, TimeUnit.SECONDS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Integer type = reqDTO.getType();//判断是分销商还是门店下单 1:分销商,2:门店 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (type == DistributorOrStoreEnum.DISTRIBUTOR.getValue()) {//分销商下单,当前阶段不考虑门店下单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //初定扣分销商库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //先返还初定扣的库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //再去扣确定的库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                reduceStockDistributor(reqDTO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }finally { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(lock.isHeldByCurrentThread() && lock.isLocked()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                lock.unlock(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void cancelReduceStock(ReduceStockReqDTO reqDTO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //TODO: 当前阶段不考虑门店库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long voyageId = reqDTO.getVoyageId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //现在给整个航次的库存加锁 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String lockKey = String.format(ProductRedisKeyConstants.STOCK_REDIS_KEY_PREFIX, voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        RLock lock = redissonClient.getLock(lockKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            lock.lock(60, TimeUnit.SECONDS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Integer type = reqDTO.getType();//判断是分销商还是门店下单 1:分销商,2:门店 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (type == DistributorOrStoreEnum.DISTRIBUTOR.getValue()) {//分销商下单,当前阶段不考虑门店下单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //初定扣分销商库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                cancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }finally { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(lock.isHeldByCurrentThread() && lock.isLocked()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                lock.unlock(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 初定取消还分销商库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 确定状态时取消订单还库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param orderId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private void preCancelReduceStockDistributor(Long orderId, Integer type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //删除已使用房间记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void cancelReduceStockDistributor(Long orderId, Integer type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //退还航次总库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //找到确定时扣库存的记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        VoyageStockLogDO voyageStockLogDO = voyageStockLogMapper.selectByOrder(orderId, TradeOrderStatusEnum.UNUSED.getStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(voyageStockLogDO != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //删除已使用房间记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockRoomUsedMapper.deleteByOrderId(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Long voyageId = voyageStockLogDO.getVoyageId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 获取航次总库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //还航次总库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal totalNum = voyageStockLogDO.getVirtualNum().add(voyageStockLogDO.getRealNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDO.setShareNum(stockDO.getShareNum().add(voyageStockLogDO.getShareNum())); //退回共享库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDO.setVirtualNum(stockDO.getVirtualNum().add(voyageStockLogDO.getVirtualNum())); //退回虚拟库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDO.setRealTotalNum(stockDO.getRealTotalNum().add(voyageStockLogDO.getRealNum())); //退回真实库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDO.setCanSellNum(stockDO.getCanSellNum().add(totalNum)); //退回可售库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDO.setBookNum(stockDO.getBookNum().subtract(totalNum)); // 减去已预订数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockMapper.updateById(stockDO);//更新航次总库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //删除航次库存操作记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockLogMapper.deleteById(voyageStockLogDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            log.error("订单取消时,未找到对应的航次库存操作记录,订单ID:{}", orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long voyageId = voyageStockLogDO.getVoyageId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long distributorId = voyageStockLogDO.getDistributorId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //找到初定时扣库存详情的记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId, TradeOrderStatusEnum.UNUSED.getStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(detailLogList != null && detailLogList.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //退还航次库存详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<String, BigDecimal> realNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), VoyageStockDetailLogDO::getRealNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<String, BigDecimal> VirtualNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), VoyageStockDetailLogDO::getVirtualNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<String, BigDecimal> shareNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), VoyageStockDetailLogDO::getShareNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<String, BigDecimal> totalNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), item -> item.getRealNum().add(item.getVirtualNum())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDetailList.stream().forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String key = item.getRoomModelId() + "_" + item.getFloor(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setBookNum(item.getBookNum().subtract(totalNumMap.get(key))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setCanSellNum(item.getCanSellNum().add(totalNumMap.get(key))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setRealTotalNum(item.getRealTotalNum().add(realNumMap.get(key))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setVirtualNum(item.getVirtualNum().add(VirtualNumMap.get(key))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockDetailMapper.updateBatch(stockDetailList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Integer stockType = detailLogList.get(0).getStockType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(stockType == 2) { //2:还分销商库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //判断分销商库存是否存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                VoyageStockDistributeNewDetailReqVO detailReqVO = new VoyageStockDistributeNewDetailReqVO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                detailReqVO.setVoyageId(voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                detailReqVO.setType(type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                detailReqVO.setObjectId(distributorId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<VoyageStockDistributeNewRespVO> distributeNewRespVOS =  voyageStockDistributeNewService.getDetail(detailReqVO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespVOS, VoyageStockDistributeNewDO.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(list != null && list.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    list.stream().forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        String key = item.getRoomModelId() + "_" + item.getFloor(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        item.setNum(item.getNum().add(totalNumMap.get(key))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        item.setBookNum(item.getBookNum().subtract(totalNumMap.get(key))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    voyageStockDistributeNewMapper.updateBatch(list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 删除库存详情初定记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockDetailLogMapper.deleteByOrder(orderId, TradeOrderStatusEnum.UNUSED.getStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 确定时扣库存,有限扣实际库存,不足再扣虚拟库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param reqDTO 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void reduceStockDistributor(ReduceStockReqDTO reqDTO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //航次库存操作日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        VoyageStockLogDO voyageStockLogDO = new VoyageStockLogDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //航次库存详情操作日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<VoyageStockDetailLogDO> detailLogList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer type = reqDTO.getType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long voyageId = reqDTO.getVoyageId(); //航次ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long distributorId = reqDTO.getDistributorId(); //分销商ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long storeId = reqDTO.getStoreId(); //门店ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BigDecimal totalUseNum = reqDTO.getUseRoomNum(); //总共使用房间数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long orderId = reqDTO.getOrderId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer orderStatus = reqDTO.getOrderStatus(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        voyageStockLogDO.setVoyageId(voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        voyageStockLogDO.setType(2);//标识减少 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        voyageStockLogDO.setOrderId(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        voyageStockLogDO.setOrderStatus(orderStatus); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        voyageStockLogDO.setOperateType(VoyageStockLogTypeEnum.ORDER_SUB.getValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        voyageStockLogDO.setDistributorId(distributorId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        voyageStockLogDO.setStoreId(storeId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 获取航次总库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(stockDO == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw exception(VOYAGE_NO_STOCK); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //共享库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BigDecimal shareNum = stockDO.getShareNum(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //航次库存详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //判断分销商库存是否存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        VoyageStockDistributeNewDetailReqVO detailReqVO = new VoyageStockDistributeNewDetailReqVO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        detailReqVO.setVoyageId(voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        detailReqVO.setType(type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        detailReqVO.setObjectId(distributorId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<VoyageStockDistributeNewRespVO> distributeNewRespVOS =  voyageStockDistributeNewService.getDetail(detailReqVO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<OrderRoomUseDTO> orderRoomList = reqDTO.getOrderRoomList();//订单使用房间详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Long> roomIds = CollectionUtils.convertList(orderRoomList, OrderRoomUseDTO::getRoomId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<RoomRespDTO> roomList = roomApi.getRoomListByIds(roomIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<Long, BigDecimal> roomMap = CollectionUtils.convertMap(orderRoomList, item -> item.getRoomId(), item -> item.getNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, BigDecimal> roomModelFloorNumMap = CollectionUtils.convertMap(roomList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item -> item.getRoomModelId() + "_" + item.getFloors(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item -> roomMap.get(item.getId()) == null ? BigDecimal.ZERO : roomMap.get(item.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(distributeNewRespVOS.isEmpty()) {//分销商未分配库存,扣共享库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockLogDO.setStockType(1); //1共享库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //判断共享库存是否充足 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(shareNum.compareTo(totalUseNum) < 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw exception(VOYAGE_SHARE_STOCK_NOT_ENOUGH); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //判断航次房型楼层库存是否充足 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 判断库存是否充足 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDetailList.stream().forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                BigDecimal canSellNum = item.getCanSellNum(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(useNum == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    useNum = BigDecimal.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(canSellNum.compareTo(useNum) < 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    throw exception(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 库存充足,扣库存详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDetailList.stream().forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(useNum == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    useNum = BigDecimal.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //航次库存详情操作日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                VoyageStockDetailLogDO voyageStockDetailLogDO = new VoyageStockDetailLogDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setVoyageId(voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setType(2);//标识减少 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setOrderId(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setOrderStatus(orderStatus); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setOperateType(VoyageStockLogTypeEnum.ORDER_SUB.getValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setRoomModelId(item.getRoomModelId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setFloor(item.getFloor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setDistributorId(distributorId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setStoreId(storeId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setStockType(1); //1共享库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 减可售房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setCanSellNum(item.getCanSellNum().subtract(useNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 减实际房间数,此处确定,先扣实际库存,实际库存不足再扣细虚拟库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(item.getRealTotalNum().compareTo(useNum) >= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    voyageStockDetailLogDO.setVirtualNum(BigDecimal.ZERO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    voyageStockDetailLogDO.setRealNum(useNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    item.setRealTotalNum(item.getRealTotalNum().subtract(useNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    voyageStockDetailLogDO.setVirtualNum(useNum.subtract(item.getRealTotalNum())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    voyageStockDetailLogDO.setRealNum(useNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    item.setRealTotalNum(BigDecimal.ZERO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    // 扣实际房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    item.setVirtualNum(item.getVirtualNum().subtract(useNum.subtract(item.getRealTotalNum()))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 加预定房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setBookNum(item.getBookNum().add(useNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                detailLogList.add(voyageStockDetailLogDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockDetailMapper.updateBatch(stockDetailList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 扣总库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 减可售房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDO.setCanSellNum(stockDO.getCanSellNum().subtract(totalUseNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 减实际房间数,此处确定,先扣实际库存,实际库存不足再扣虚拟库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(stockDO.getRealTotalNum().compareTo(totalUseNum) >= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                stockDO.setRealTotalNum(stockDO.getRealTotalNum().subtract(totalUseNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockLogDO.setVirtualNum(BigDecimal.ZERO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockLogDO.setRealNum(totalUseNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockLogDO.setRealNum(stockDO.getRealTotalNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockLogDO.setVirtualNum(totalUseNum.subtract(voyageStockLogDO.getRealNum())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                stockDO.setRealTotalNum(BigDecimal.ZERO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 扣虚拟房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                stockDO.setVirtualNum(stockDO.getVirtualNum().subtract(totalUseNum.subtract(stockDO.getRealTotalNum()))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 加预定房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDO.setBookNum(stockDO.getBookNum().add(totalUseNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 扣共享库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDO.setShareNum(stockDO.getShareNum().subtract(totalUseNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockLogDO.setShareNum(totalUseNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockMapper.updateById(stockDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockLogDO.setStockType(2); //2分销商库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //分销商已分配库存,扣自身库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //判断航次房型楼层库存是否充足 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            distributeNewRespVOS.stream().forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                BigDecimal canSellNum = item.getNum(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(useNum == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    useNum = BigDecimal.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(canSellNum.compareTo(useNum) < 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    throw exception(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 扣分销商库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 库存充足,扣库存详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespVOS, VoyageStockDistributeNewDO.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            list.stream().forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(useNum == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    useNum = BigDecimal.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 减可售房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setNum(item.getNum().subtract(useNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 加预定房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setBookNum(item.getBookNum().add(useNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockDistributeNewMapper.updateBatch(list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 库存充足,扣库存详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDetailList.stream().forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(useNum == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    useNum = BigDecimal.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //航次库存详情操作日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                VoyageStockDetailLogDO voyageStockDetailLogDO = new VoyageStockDetailLogDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setVoyageId(voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setType(2);//标识减少 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setOrderId(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setOrderStatus(orderStatus); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setOperateType(VoyageStockLogTypeEnum.ORDER_SUB.getValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setRoomModelId(item.getRoomModelId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setFloor(item.getFloor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setDistributorId(distributorId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setStoreId(storeId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockDetailLogDO.setStockType(2); //2分销商库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 减可售房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setCanSellNum(item.getCanSellNum().subtract(useNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 减实际房间数,此处确定,先扣实际库存,实际库存不足再扣实际库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(item.getVirtualNum().compareTo(useNum) >= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    voyageStockDetailLogDO.setRealNum(useNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    voyageStockDetailLogDO.setVirtualNum(BigDecimal.ZERO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    item.setRealTotalNum(item.getRealTotalNum().subtract(useNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    voyageStockDetailLogDO.setRealNum(item.getRealTotalNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    voyageStockDetailLogDO.setVirtualNum(totalUseNum.subtract(item.getRealTotalNum())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    item.setRealTotalNum(BigDecimal.ZERO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    // 扣虚拟房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    item.setVirtualNum(item.getVirtualNum().subtract(useNum.subtract(item.getRealTotalNum()))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 加预定房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                item.setBookNum(item.getBookNum().add(useNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                detailLogList.add(voyageStockDetailLogDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockDetailMapper.updateBatch(stockDetailList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 扣总库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 减可售房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDO.setCanSellNum(stockDO.getCanSellNum().subtract(totalUseNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 减剩余房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            stockDO.setSurplusNum(stockDO.getSurplusNum().subtract(totalUseNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 减实际房间数,此处确定,先扣实际库存,实际库存不足再扣虚拟库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(stockDO.getRealTotalNum().compareTo(totalUseNum) >= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                stockDO.setRealTotalNum(stockDO.getRealTotalNum().subtract(totalUseNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockLogDO.setRealNum(totalUseNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockLogDO.setVirtualNum(BigDecimal.ZERO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockLogDO.setRealNum(stockDO.getRealTotalNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                voyageStockLogDO.setVirtualNum(totalUseNum.subtract(voyageStockLogDO.getRealNum())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                stockDO.setRealTotalNum(BigDecimal.ZERO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 扣虚拟房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                stockDO.setVirtualNum(stockDO.getVirtualNum().subtract(totalUseNum.subtract(stockDO.getRealTotalNum()))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 加预定房间数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stockDO.setBookNum(stockDO.getBookNum().add(totalUseNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 扣共享库存,此处为分销商库存,不扣共享库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockLogDO.setShareNum(BigDecimal.ZERO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockMapper.updateById(stockDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 添加房间使用记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<VoyageStockRoomUsedDO> roomUsedList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<Long, RoomRespDTO> roomIdMap = CollectionUtils.convertMap(roomList, RoomRespDTO::getId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        orderRoomList.forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            VoyageStockRoomUsedDO roomUsedDO = new VoyageStockRoomUsedDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            roomUsedDO.setOrderId(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            roomUsedDO.setVoyageId(voyageId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            RoomRespDTO roomRespDTO = roomIdMap.get(item.getRoomId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(roomRespDTO == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw exception(VOYAGE_ROOM_NOT_EXIST.getCode(), String.format(VOYAGE_ROOM_NOT_EXIST.getMsg(), item.getRoomId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            roomUsedDO.setRoomModelId(roomRespDTO.getRoomModelId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            roomUsedDO.setFloor(roomRespDTO.getFloors()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            roomUsedDO.setRoomId(item.getRoomId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            roomUsedDO.setNum(item.getNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            roomUsedDO.setStatus(orderStatus); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            roomUsedList.add(roomUsedDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //先删除当前订单已被使用的房间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         voyageStockRoomUsedMapper.deleteByOrderId(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(roomUsedList.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockRoomUsedMapper.insertBatch(roomUsedList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 添加库存日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        voyageStockLogMapper.insert(voyageStockLogDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 添加库存详情日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(detailLogList.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockDetailLogMapper.insertBatch(detailLogList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 初定取消还分销商库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void preCancelReduceStockDistributor(Long orderId, Integer type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //退还航次总库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //找到初定时扣库存的记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         VoyageStockLogDO voyageStockLogDO = voyageStockLogMapper.selectByOrder(orderId, TradeOrderStatusEnum.YD.getStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if(voyageStockLogDO != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //删除已使用房间记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            voyageStockRoomUsedMapper.deleteByOrderId(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Long voyageId = voyageStockLogDO.getVoyageId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 获取航次总库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId); 
			 |