| | |
| | | package com.tourguide.modules.order.service; |
| | | |
| | | import com.tourguide.modules.order.mapper.TourOrderMapper; |
| | | import com.tourguide.modules.order.entity.TourOrder; |
| | | import com.tourguide.modules.user.entity.GuideReceivingSession; |
| | | import com.tourguide.modules.user.mapper.GuideRealtimeStatusMapper; |
| | | import com.tourguide.modules.user.mapper.GuideReceivingSessionMapper; |
| | |
| | | orderMapper.startSessionOrders(session.getId(), LocalDateTime.now()); |
| | | realtimeStatusMapper.disableReceiving(session.getGuideId()); |
| | | } |
| | | |
| | | @Transactional |
| | | public void restoreAfterOrderCancellation(TourOrder order) { |
| | | if (order == null || order.getGuideId() == null || order.getReceivingSessionId() == null) return; |
| | | |
| | | GuideReceivingSession session = sessionMapper.selectForUpdate( |
| | | order.getReceivingSessionId(), order.getGuideId()); |
| | | if (session == null) return; |
| | | |
| | | long remainingOrders = orderMapper.countPendingMeetingBySession(session.getId(), order.getGuideId()); |
| | | if ("PRIVATE".equals(session.getReceivingMode()) |
| | | || ("ALL".equals(session.getReceivingMode()) && isPrivateOrder(order))) { |
| | | if (remainingOrders == 0 |
| | | && sessionMapper.reopenPrivateAfterOrderCancellation(session.getId(), order.getGuideId()) == 1) { |
| | | realtimeStatusMapper.enableReceiving(order.getGuideId()); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | if (!("GROUP".equals(session.getReceivingMode()) |
| | | || ("ALL".equals(session.getReceivingMode()) && !isPrivateOrder(order))) |
| | | || !"RECEIVING".equals(session.getStatus())) return; |
| | | if (remainingOrders == 0) { |
| | | sessionMapper.resetGroupAfterOrderCancellation(session.getId(), order.getGuideId()); |
| | | return; |
| | | } |
| | | int peopleCount = order.getPeopleCount() == null ? 0 : Math.max(0, order.getPeopleCount()); |
| | | if (peopleCount > 0) { |
| | | sessionMapper.releaseGroupCapacity(session.getId(), order.getGuideId(), peopleCount); |
| | | } |
| | | } |
| | | |
| | | private boolean isPrivateOrder(TourOrder order) { |
| | | return order.getOrderType() != null && order.getOrderType().startsWith("PRIVATE_"); |
| | | } |
| | | } |