liujie
2026-08-14 92a75a7b157e6fd6423df17cfd32015017bdb8c9
backend/src/main/java/com/tourguide/modules/review/service/OrderReviewService.java
@@ -15,6 +15,7 @@
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;
@@ -32,11 +33,15 @@
    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,
@@ -127,6 +132,21 @@
        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);
@@ -143,6 +163,7 @@
        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() {