“mitao”
2026-04-17 d699da385dda6257677ee93bef47388c0635f64e
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
package com.tcm.training.admin.app.system.controller;
 
import com.tcm.training.admin.common.ApiResponse;
import com.tcm.training.admin.system.entity.AgreementContent;
import com.tcm.training.admin.system.service.AgreementContentAppService;
import com.tcm.training.admin.system.vo.AgreementContentItemVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * APP 协议内容接口。
 */
@Validated
@RestController
@RequestMapping({"/api/app/agreement-contents", "/api/v1/app/agreement-contents"})
public class AppAgreementContentController {
 
    private final AgreementContentAppService agreementContentAppService;
 
    /**
     * 注入协议内容服务。
     */
    public AppAgreementContentController(AgreementContentAppService agreementContentAppService) {
        this.agreementContentAppService = agreementContentAppService;
    }
 
    /**
     * 获取单条协议详情,并兼容 APP 页面已有的 user/privacy 参数。
     */
    @GetMapping("/{agreementType}")
    public ApiResponse<AgreementContentItemVO> detail(@PathVariable("agreementType") String agreementType) {
        return ApiResponse.ok(agreementContentAppService.detail(normalizeAgreementType(agreementType)));
    }
 
    /**
     * 将 APP 页面路由参数转换为后台协议类型常量。
     */
    private String normalizeAgreementType(String agreementType) {
        if (agreementType == null) {
            return null;
        }
        String normalized = agreementType.trim();
        if ("user".equalsIgnoreCase(normalized)) {
            return AgreementContent.TYPE_USER_AGREEMENT;
        }
        if ("privacy".equalsIgnoreCase(normalized)) {
            return AgreementContent.TYPE_PRIVACY_POLICY;
        }
        return normalized;
    }
}