| | |
| | | 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; |
| | |
| | | order.setGuideName(guide.getRealName()); |
| | | order.setGuideMobile(guide.getMobile()); |
| | | order.setAcceptedAt(now); |
| | | order.setStatus(OrderStatus.PENDING_MEETING.getCode()); |
| | | boolean serving = "GROUP".equals(mode) && "IN_SERVICE".equals(session.getStatus()); |
| | | order.setStatus(serving ? OrderStatus.IN_SERVICE.getCode() : OrderStatus.PENDING_MEETING.getCode()); |
| | | if (serving) { |
| | | order.setArrivedAt(now); |
| | | order.setServiceStartedAt(now); |
| | | } |
| | | earningSnapshotService.apply(order, guide); |
| | | orderMapper.updateById(order); |
| | | guideUserMapper.incrementAcceptedOrderCount(guide.getId()); |
| | |
| | | } |
| | | |
| | | 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; } |