liujie
2026-08-14 92a75a7b157e6fd6423df17cfd32015017bdb8c9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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<GuideEarningsResponse> 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");
        }
    }
}