liusheng
5 天以前 0bbbd746e8c39d91ad7b47a4e36e29ab972dc98c
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
package com.ruoyi.publicity.config;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
/**
 * 宣教模块的拦截器注册。
 * <p>
 * 与 {@code InhospVisitWebConfig} 完全同款做法与理由。
 *
 * <h3>为什么只挂 2 条精确路径,不用 {@code /smartor/publicity/**} 前缀</h3>
 * 本模块的端点是:
 * <pre>
 * POST /smartor/publicity/dealInHospPublicity   ← 挂(会生成宣教)
 * POST /smartor/publicity/dealMedicalPublicity  ← 挂(会生成宣教)
 * GET  /smartor/publicity/status                ← 不挂(只读状态查询)
 * </pre>
 * {@code /status} 是排查"为什么没发宣教"的唯一入口,模块关掉时恰恰最需要它;
 * 若用前缀把它一起拦了,就等于"出问题时连诊断入口都进不去"。
 * 这也与出入院模块"开关只拦随访触发、不拦数据端点"的约定保持一致。
 *
 * <h3>新增端点时的约定</h3>
 * 往后本模块若再加端点,默认<b>不</b>加入本清单;
 * 只有"会真的生成/改变宣教数据"的端点才挂,并同步更新
 * {@code PublicityContextCheck} 里的受保护路径条数断言。
 */
@Configuration
public class PublicityWebConfig implements WebMvcConfigurer {
 
    /**
     * 入院宣教(科室 type=4 / 病区 type=5)
     */
    public static final String DEAL_IN_HOSP_PUBLICITY_ENDPOINT =
            "/smartor/publicity/dealInHospPublicity";
 
    /**
     * 药品宣教(仅 sltd 站点,type=0)
     */
    public static final String DEAL_MEDICAL_PUBLICITY_ENDPOINT =
            "/smartor/publicity/dealMedicalPublicity";
 
    /**
     * 状态查询端点 —— <b>刻意不纳入拦截</b>,仅作为常量公开,
     * 便于测试断言"它确实没被挂上"。
     */
    public static final String STATUS_ENDPOINT_PENDING =
            "/smartor/publicity/status";
 
    @Autowired
    private PublicityAvailabilityInterceptor publicityAvailabilityInterceptor;
 
    /**
     * 供测试/非 Spring 环境直接构造
     */
    public PublicityWebConfig(PublicityAvailabilityInterceptor publicityAvailabilityInterceptor) {
        this.publicityAvailabilityInterceptor = publicityAvailabilityInterceptor;
    }
 
    /**
     * 受开关保护的精确路径(供测试断言条数与内容)
     */
    public static String[] guardedPathPatterns() {
        return new String[]{
                DEAL_IN_HOSP_PUBLICITY_ENDPOINT,
                DEAL_MEDICAL_PUBLICITY_ENDPOINT,
        };
    }
 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(publicityAvailabilityInterceptor)
                .addPathPatterns(guardedPathPatterns())
                // 拦截器本身很轻(只读一个 boolean),order 给小值让它在业务拦截器之前执行
                .order(-100);
    }
}