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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.talentcard.server.business.admin;
 
import java.time.LocalDate;
import java.util.List;
 
import com.talentcard.server.business.PageResult;
import com.talentcard.server.business.admin.auth.AdminAuthInterceptor;
import com.talentcard.server.common.ApiResponse;
import com.talentcard.server.request.DependentCardAuditRequest;
import com.talentcard.server.response.DependentCardApplyAdminResponse;
import com.talentcard.server.response.DependentCardApplyStatusLogResponse;
import com.talentcard.server.service.DependentCardApplyAdminService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
@Tag(name = "管理后台-家属附属卡审核", description = "家属附属卡申请查询、审核和状态记录")
@RestController
@RequestMapping("/api/admin/dependent-card-applies")
public class DependentCardApplyAdminController {
    private final DependentCardApplyAdminService service;
 
    public DependentCardApplyAdminController(DependentCardApplyAdminService service) {
        this.service = service;
    }
 
    @Operation(summary = "分页查询家属附属卡申请")
    @GetMapping
    public ApiResponse<PageResult<DependentCardApplyAdminResponse>> page(
            @Parameter(description = "主卡ID") @RequestParam(required = false) Long talentCardId,
            @Parameter(description = "家属姓名、手机号或身份证号") @RequestParam(required = false) String familyKeyword,
            @Parameter(description = "持卡人姓名、手机号、身份证号或卡号") @RequestParam(required = false) String talentKeyword,
            @Parameter(description = "卡片等级") @RequestParam(required = false) String cardLevel,
            @Parameter(description = "状态:0待审核、1已通过、2已驳回、3已取消") @RequestParam(required = false) Integer status,
            @Parameter(description = "申请开始日期") @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate applyStart,
            @Parameter(description = "申请结束日期") @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate applyEnd,
            @Parameter(description = "是否按家属卡管理范围查询(仅已绑定和已解绑)") @RequestParam(defaultValue = "false") boolean management,
            @Parameter(description = "页码") @RequestParam(defaultValue = "1") int page,
            @Parameter(description = "每页数量,最大100") @RequestParam(defaultValue = "10") int size
    ) {
        return ApiResponse.success(service.page(talentCardId, familyKeyword, talentKeyword, cardLevel, status, applyStart, applyEnd, management, page, size));
    }
 
    @Operation(summary = "查询家属附属卡申请详情")
    @GetMapping("/{id}")
    public ApiResponse<DependentCardApplyAdminResponse> detail(@PathVariable Long id) {
        return ApiResponse.success(service.detail(id));
    }
 
    @Operation(summary = "审核家属附属卡申请", description = "仅待审核申请可以变更为通过或驳回;通过时校验主卡权限和家属卡名额")
    @ApiResponses({
            @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "审核成功"),
            @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "审核失败、申请不存在、状态冲突或绑定名额已满")
    })
    @PatchMapping("/{id}/audit")
    public ApiResponse<DependentCardApplyAdminResponse> audit(
            @PathVariable Long id,
            @Valid @RequestBody DependentCardAuditRequest request,
            @RequestAttribute(AdminAuthInterceptor.OPERATOR_ID_ATTRIBUTE) Long operatorId
    ) {
        return ApiResponse.success(service.audit(id, request, operatorId));
    }
 
    @Operation(summary = "解除家属卡绑定", description = "仅正常状态的家属卡可以解除绑定")
    @PatchMapping("/{id}/unbind")
    public ApiResponse<DependentCardApplyAdminResponse> unbind(
            @PathVariable Long id,
            @RequestAttribute(AdminAuthInterceptor.OPERATOR_ID_ATTRIBUTE) Long operatorId
    ) {
        return ApiResponse.success(service.unbind(id, operatorId));
    }
 
    @Operation(summary = "查询家属附属卡申请状态记录")
    @GetMapping("/{id}/status-logs")
    public ApiResponse<List<DependentCardApplyStatusLogResponse>> statusLogs(@PathVariable Long id) {
        return ApiResponse.success(service.statusLogs(id));
    }
}