wenminjie
2026-08-06 8898f00c2150048a03ca561b7ed98dbf9c80732b
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
package com.talentcard.server.business.portal;
 
import java.util.Map;
 
import com.talentcard.server.common.ApiResponse;
import com.talentcard.server.request.BenefitVerificationCodeRequest;
import com.talentcard.server.service.BenefitVerificationCodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.http.CacheControl;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
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/app/benefit-verification-codes")
public class BenefitVerificationCodeController {
    private final BenefitVerificationCodeService service;
 
    public BenefitVerificationCodeController(BenefitVerificationCodeService service) {
        this.service = service;
    }
 
    @Operation(summary = "获取电影票兑换码二维码", description = "返回电影票固定兑换码二维码,核销或电影券有效期结束后失效")
    @GetMapping(value = "/{claimId}/image", produces = MediaType.IMAGE_PNG_VALUE)
    public ResponseEntity<byte[]> movieImage(
            @Parameter(description = "电影票领取记录ID", required = true) @PathVariable Long claimId) {
        return ResponseEntity.ok()
                .cacheControl(CacheControl.noStore())
                .body(service.movieCodeImage(claimId));
    }
 
    @Operation(summary = "查询权益可用次数", description = "按主卡或亲属附属卡、人才卡等级和商户配置查询当前可用权益次数,不生成核销码")
    @GetMapping("/quota")
    public ApiResponse<Map<String, Object>> quota(
            @Parameter(description = "权益类型:MOVIE_TICKET电影票、HOTEL酒店", required = true)
            @RequestParam String benefitType,
            @Parameter(description = "人才用户ID;未传cardId时必填")
            @RequestParam(required = false) Long talentId,
            @Parameter(description = "人才卡ID;支持主卡或亲属附属卡")
            @RequestParam(required = false) Long cardId,
            @Parameter(description = "商户ID", required = true)
            @RequestParam Long merchantId
    ) {
        return ApiResponse.success(service.quota(new BenefitVerificationCodeRequest(
                benefitType, talentId, cardId, merchantId)));
    }
 
    @Operation(summary = "生成权益核销码", description = "电影票生成固定兑换码,酒店生成60秒动态核销码")
    @PostMapping
    public ApiResponse<Map<String, Object>> create(
            @Valid @RequestBody BenefitVerificationCodeRequest request,
            @RequestHeader(value = "X-Idempotency-Key", required = false) String idempotencyKey
    ) {
        return ApiResponse.success(service.generate(request, idempotencyKey));
    }
}