| | |
| | | import com.tourguide.modules.review.mapper.OrderReviewMapper; |
| | | import com.tourguide.modules.user.entity.GuideUser; |
| | | import com.tourguide.modules.user.mapper.GuideUserMapper; |
| | | import com.tourguide.modules.user.service.GuideAutoDisableService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | |
| | | private final OrderReviewMapper reviewMapper; |
| | | private final TourOrderMapper orderMapper; |
| | | private final GuideUserMapper guideUserMapper; |
| | | private final GuideAutoDisableService autoDisableService; |
| | | |
| | | public OrderReviewService(OrderReviewMapper reviewMapper, TourOrderMapper orderMapper, GuideUserMapper guideUserMapper) { |
| | | public OrderReviewService(OrderReviewMapper reviewMapper, TourOrderMapper orderMapper, |
| | | GuideUserMapper guideUserMapper, |
| | | GuideAutoDisableService autoDisableService) { |
| | | this.reviewMapper = reviewMapper; |
| | | this.orderMapper = orderMapper; |
| | | this.guideUserMapper = guideUserMapper; |
| | | this.autoDisableService = autoDisableService; |
| | | } |
| | | |
| | | public PageResponse<OrderReviewResponse> page(long page, long size, String keyword, Integer status, |
| | |
| | | return new OrderReviewResponse(review); |
| | | } |
| | | |
| | | public OrderReviewResponse detailByOrder(Long visitorId, Long orderId) { |
| | | TourOrder order = orderMapper.selectById(orderId); |
| | | if (order == null) throw new BusinessException(404, "order not found"); |
| | | if (order.getVisitorId() == null || !order.getVisitorId().equals(visitorId)) { |
| | | throw new BusinessException(403, "cannot view another visitor's review"); |
| | | } |
| | | |
| | | OrderReview review = reviewMapper.selectOne(new LambdaQueryWrapper<OrderReview>() |
| | | .eq(OrderReview::getOrderId, orderId) |
| | | .eq(OrderReview::getStatus, 1) |
| | | .last("LIMIT 1")); |
| | | if (review == null) throw new BusinessException(404, "review not found"); |
| | | return new OrderReviewResponse(review); |
| | | } |
| | | |
| | | @Transactional |
| | | public void delete(Long id) { |
| | | OrderReview review = reviewMapper.selectById(id); |
| | |
| | | BigDecimal average = reviewMapper.selectAverageScore(guideId); |
| | | guide.setRating(average == null ? BigDecimal.ZERO : average.setScale(2, RoundingMode.HALF_UP)); |
| | | guideUserMapper.updateById(guide); |
| | | autoDisableService.disableGuideIfEligible(guideId); |
| | | } |
| | | |
| | | private String generateReviewNo() { |