package com.tourguide.api.guide; import com.tourguide.common.api.ApiResponse; import com.tourguide.common.exception.BusinessException; import com.tourguide.modules.order.dto.GuideEarningsResponse; import com.tourguide.modules.order.service.GuideEarningsService; import com.tourguide.security.AppUserPrincipal; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.time.LocalDate; import java.time.format.DateTimeParseException; /** 导游端真实业绩汇总和订单明细。 */ @RestController @RequestMapping("/api/guide/earnings") public class GuideEarningsController { private final GuideEarningsService earningsService; public GuideEarningsController(GuideEarningsService earningsService) { this.earningsService = earningsService; } @GetMapping public ApiResponse get( @AuthenticationPrincipal AppUserPrincipal principal, @RequestParam(required = false) String serviceType, @RequestParam(required = false) String scenicName, @RequestParam(required = false) String date, @RequestParam(defaultValue = "1") long pageNum, @RequestParam(defaultValue = "50") long pageSize) { return ApiResponse.success(earningsService.get( principal.getUserId(), serviceType, scenicName, parseDate(date), pageNum, pageSize)); } private LocalDate parseDate(String date) { if (date == null || date.trim().isEmpty() || "undefined".equalsIgnoreCase(date) || "null".equalsIgnoreCase(date)) { return null; } try { return LocalDate.parse(date); } catch (DateTimeParseException exception) { throw new BusinessException(400, "日期格式不正确,应为yyyy-MM-dd"); } } }