| | |
| | | package com.tourguide.modules.review.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.tourguide.common.api.PageResponse; |
| | | import com.tourguide.common.exception.BusinessException; |
| | |
| | | import com.tourguide.modules.user.entity.GuideUser; |
| | | import com.tourguide.modules.user.mapper.GuideUserMapper; |
| | | import com.tourguide.modules.user.service.GuideAutoDisableService; |
| | | import com.tourguide.modules.system.service.GuideNotificationService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | |
| | | private final TourOrderMapper orderMapper; |
| | | private final GuideUserMapper guideUserMapper; |
| | | private final GuideAutoDisableService autoDisableService; |
| | | private final ObjectMapper objectMapper; |
| | | private final GuideNotificationService notificationService; |
| | | |
| | | public OrderReviewService(OrderReviewMapper reviewMapper, TourOrderMapper orderMapper, |
| | | GuideUserMapper guideUserMapper, |
| | | GuideAutoDisableService autoDisableService) { |
| | | this(reviewMapper, orderMapper, guideUserMapper, autoDisableService, new ObjectMapper(), null); |
| | | } |
| | | |
| | | public OrderReviewService(OrderReviewMapper reviewMapper, TourOrderMapper orderMapper, |
| | | GuideUserMapper guideUserMapper, |
| | | GuideAutoDisableService autoDisableService, |
| | | ObjectMapper objectMapper) { |
| | | this(reviewMapper, orderMapper, guideUserMapper, autoDisableService, objectMapper, null); |
| | | } |
| | | |
| | | @Autowired |
| | | public OrderReviewService(OrderReviewMapper reviewMapper, TourOrderMapper orderMapper, |
| | | GuideUserMapper guideUserMapper, |
| | | GuideAutoDisableService autoDisableService, |
| | | ObjectMapper objectMapper, |
| | | GuideNotificationService notificationService) { |
| | | this.reviewMapper = reviewMapper; |
| | | this.orderMapper = orderMapper; |
| | | this.guideUserMapper = guideUserMapper; |
| | | this.autoDisableService = autoDisableService; |
| | | this.objectMapper = objectMapper; |
| | | this.notificationService = notificationService; |
| | | } |
| | | |
| | | public PageResponse<OrderReviewResponse> page(long page, long size, String keyword, Long visitorId, Integer status, |
| | |
| | | review.setScenicName(order.getScenicName()); |
| | | review.setScore(request.getScore()); |
| | | review.setContent(request.getContent()); |
| | | review.setImageUrls(serializeImages(request.getImages())); |
| | | review.setReviewedAt(LocalDateTime.now()); |
| | | review.setStatus(1); |
| | | review.setDeleted(0); |
| | | reviewMapper.insert(review); |
| | | refreshGuideRating(order.getGuideId()); |
| | | if (notificationService != null) { |
| | | notificationService.notifyOrderReviewed(order); |
| | | } |
| | | return new OrderReviewResponse(review); |
| | | } |
| | | |
| | |
| | | autoDisableService.disableGuideIfEligible(guideId); |
| | | } |
| | | |
| | | private String serializeImages(List<String> images) { |
| | | if (images == null || images.isEmpty()) return null; |
| | | List<String> normalized = images.stream() |
| | | .filter(StringUtils::hasText) |
| | | .map(String::trim) |
| | | .limit(3) |
| | | .collect(Collectors.toList()); |
| | | if (normalized.isEmpty()) return null; |
| | | try { |
| | | return objectMapper.writeValueAsString(normalized); |
| | | } catch (Exception exception) { |
| | | throw new BusinessException(400, "评价图片格式不正确"); |
| | | } |
| | | } |
| | | |
| | | private String generateReviewNo() { |
| | | String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); |
| | | return "RV" + time + UUID.randomUUID().toString().replace("-", "").substring(0, 8).toUpperCase(); |