| | |
| | | if (pricing == null || scenic == null) return false; |
| | | for (GuideReceivingSession session : candidates) { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | int leadMinutes = positive(scenic.getFirstOrderLeadMinutes(), 15); |
| | | LocalDateTime serviceStartAt = now.plusMinutes(leadMinutes); |
| | | boolean reserved = "GROUP".equals(mode) |
| | | ? reserveGroup(session, order, pricing, scenic, now) |
| | | : sessionMapper.assignPrivate(session.getId(), order.getPeopleCount(), now) == 1; |
| | | ? reserveGroup(session, order, pricing, scenic, now, serviceStartAt) |
| | | : sessionMapper.assignPrivate(session.getId(), order.getPeopleCount(), now, serviceStartAt) == 1; |
| | | if (!reserved) continue; |
| | | GuideUser guide = guideUserMapper.selectById(session.getGuideId()); |
| | | if (guide == null) continue; |
| | |
| | | } |
| | | |
| | | private boolean reserveGroup(GuideReceivingSession session, TourOrder order, ScenicPricing pricing, |
| | | OperationScenicSpot scenic, LocalDateTime now) { |
| | | OperationScenicSpot scenic, LocalDateTime now, LocalDateTime serviceStartAt) { |
| | | Integer maxPeople = pricing.getMaxParticipants(); |
| | | if (maxPeople == null || maxPeople < 1) return false; |
| | | int leadMinutes = positive(scenic.getFirstOrderLeadMinutes(), 15); |
| | | int cutoffMinutes = positive(scenic.getVisitorNoOrderMinutes(), leadMinutes); |
| | | return sessionMapper.reserveGroupCapacity(session.getId(), order.getPeopleCount(), maxPeople, now, |
| | | now.plusMinutes(leadMinutes), now.plusMinutes(cutoffMinutes)) == 1; |
| | | serviceStartAt, now.plusMinutes(cutoffMinutes)) == 1; |
| | | } |
| | | |
| | | private int positive(Integer value, int fallback) { return value == null || value < 1 ? fallback : value; } |