liusheng
8 天以前 34f78281cf395a24e1f3f1c3b861186ff8a03b7b
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.ruoyi.template.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;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
 * 模板模块的 MVC 配置:把 {@link TemplateAvailabilityInterceptor} 挂到
 * <b>本模块的模板管理端点</b>上({@code sys_config: template.enabled} 关闭时明确报错)。
 *
 * <h3>为什么逐个列路径,而不是 {@code /smartor/**} 前缀</h3>
 * {@code /smartor/*} 下还有大量<b>不属于模板</b>的端点(服务子任务、档案、服务任务、
 * 问卷任务实例、方案流程…)。用前缀会<b>误伤</b>它们 ——
 * 关闭模板模块不该让那些功能一起停摆。
 * <p>
 * 判断标准是"这个端点管的是不是模板数据",而不是"它在不在本模块里"。
 * 这一点与出入院模块 {@code InhospVisitWebConfig} 的取舍完全一致
 * (那里也刻意不用 {@code /smartor/patinhosp/**} 前缀)。
 *
 * <h3>受保护清单</h3>
 * 共 <b>66</b> 个 URL 前缀,覆盖 ruoyi-template 内全部模板控制器
 * 以及<b>刻意留在 smartor</b> 的 3 个模板管理控制器
 * ({@code SvyLibTemplateController} / {@code SvyTaskController} /
 * {@code SvyTaskTemplateController} 等 —— 它们的端点是模板管理,所以照样受开关管)。
 *
 * <h3>刻意<b>不</b>受管的</h3>
 * {@code IvrTaskVisitResultController} / {@code IvrTasksmsController} /
 * {@code IvrTaskcallrecordController} —— 它们是**任务执行记录**(运行时实例),
 * 已按职责移出本模块;关掉"模板"不该让"任务执行记录查询"停摆。
 *
 * <h3>生成方式</h3>
 * 本文件由 {@code sql/_probe/gen_template_guarded_urls.py} + 本脚本从**实际控制器**抽取,
 * 不是手抄的 —— 手抄 66 个路径必然会漏,而漏了不会报错,只会让那个端点静默不受开关管。
 */
@Configuration
public class TemplateWebConfig implements WebMvcConfigurer {
 
    @Autowired
    private TemplateAvailabilityInterceptor templateAvailabilityInterceptor;
 
    /**
     * 供测试/非 Spring 环境直接构造
     */
    public TemplateWebConfig() {
    }
 
    public TemplateWebConfig(TemplateAvailabilityInterceptor interceptor) {
        this.templateAvailabilityInterceptor = interceptor;
    }
 
    /**
     * 本模块"关闭即明确报错"的端点(供校验脚本/测试断言)
     */
    public static List<String> guardedPathPatterns() {
        return new ArrayList<>(Arrays.asList(
                "/base/tag/**",  // BaseTagController
                "/smartor/assort/**",  // IvrLibaTargetAssortController
                "/smartor/category/**",  // IvrLibaExtemplateCategoryController
                "/smartor/extemplate/**",  // IvrLibaExtemplateController
                "/smartor/extemplatescript/**",  // IvrLibaExtemplatescriptController
                "/smartor/heLibraryAssort/**",  // HeLibraryAssortController
                "/smartor/heLibraryTag/**",  // HeLibraryTagController
                "/smartor/hecategory/**",  // HeCategoryController
                "/smartor/helibrary/**",  // HeLocallibraryController
                "/smartor/ivrTaskTemplate/**",  // IvrTaskTemplateController
                "/smartor/library/**",  // HeLibraryController
                "/smartor/optionwjx/**",  // SvyLibTemplateTargetoptionWjxController
                "/smartor/outicd10/**",  // Icd10AssociationController
                "/smartor/schemeautofinshrule/**",  // SchemeAutofinshruleController
                "/smartor/schemecalldetail/**",  // SchemeTaskrecordCalldetailController
                "/smartor/schemecategory/**",  // SchemeCategoryController
                "/smartor/schemelibrary/**",  // SchemeLocallibraryController
                "/smartor/schemeplan/**",  // SchemePlanController
                "/smartor/schemetask/**",  // SchemeTaskController
                "/smartor/schemetaskconfig/**",  // SchemeTaskconfigController
                "/smartor/schemetaskrecord/**",  // SchemeTaskrecordController
                "/smartor/schemetaskrepeatconfig/**",  // SchemeTaskrepeatconfigController
                "/smartor/schemetriggerrule/**",  // SchemeTriggerruleController
                "/smartor/schemetriggerscene/**",  // SchemeTriggersceneController
                "/smartor/script/**",  // IvrLibaScriptController
                "/smartor/scriptassort/**",  // IvrLibaScriptAssortController
                "/smartor/scripttag/**",  // IvrLibaScriptTagController
                "/smartor/scripttarget/**",  // IvrLibaScriptTargetController
                "/smartor/scripttargetoption/**",  // IvrLibaScriptTargetoptionController
                "/smartor/srcriptwjx/**",  // SvyLibTemplateScriptWjxController
                "/smartor/svyLibScriptCategory/**",  // SvyLibScriptCategoryController
                "/smartor/svyLibScriptTag/**",  // SvyLibScriptTagController
                "/smartor/svyLibTemplate/**",  // SvyLibTemplateController
                "/smartor/svyLibTemplateCategory/**",  // SvyLibTemplateCategoryController
                "/smartor/svyLibTemplateTag/**",  // SvyLibTemplateTagController
                "/smartor/svyTaskScript/**",  // SvyTaskScriptController
                "/smartor/svyTaskTargetOption/**",  // SvyTaskTemplateTargetoptionController
                "/smartor/svyTaskTempScript/**",  // SvyTaskTemplateScriptController
                "/smartor/svycategory/**",  // SvyCategoryController
                "/smartor/svyexception/**",  // SvyLibExceptionController
                "/smartor/svyfinish/**",  // SvyFinishController
                "/smartor/svyfinishoption/**",  // SvyFinishoptionController
                "/smartor/svyfinishtopic/**",  // SvyFinishtopicController
                "/smartor/svyresult/**",  // SvyLibResultController
                "/smartor/svyscript/**",  // SvyLibScriptController
                "/smartor/svyscriptoption/**",  // SvyTaskScriptoptionController
                "/smartor/svytargetoption/**",  // SvyLibTemplateTargetoptionController
                "/smartor/svytask/**",  // SvyTaskController
                "/smartor/svytemplateTask/**",  // SvyTaskTemplateController
                "/smartor/svytemplatescript/**",  // SvyLibTemplateScriptController
                "/smartor/svytscroption/**",  // SvyLibScriptOptionController
                "/smartor/tag/**",  // IvrLibaTargetTagController
                "/smartor/target/**",  // IvrLibaTargetController
                "/smartor/targetoption/**",  // IvrLibaTargetoptionController
                "/smartor/taskTemplateScript/**",  // IvrTaskTemplateScriptController
                "/smartor/td/**",  // TemplateDeptController
                "/smartor/template/**",  // IvrLibaTemplateController
                "/smartor/templateassort/**",  // IvrLibaTemplateAssortController
                "/smartor/templatescript/**",  // IvrLibaTemplateScriptController
                "/smartor/templatetag/**",  // IvrLibaTemplateTagController
                "/smartor/templatetargetoption/**",  // IvrLibaTemplateTargetoptionController
                "/smartor/templatewjx/**",  // SvyLibTemplateWjxController
                "/system/answer/**",  // SvyTaskAnswerController
                "/system/tagcategory/**",  // BaseTagcategoryController
                "/system/taskTemplateTargetoption/**",  // IvrTaskTemplateTargetoptionController
                "/system/topic/**"  // SvyTopicController
        ));
    }
 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(templateAvailabilityInterceptor)
                .addPathPatterns(guardedPathPatterns())
                // 拦截器很轻(只读一个 boolean),order 给个小值让它在业务拦截器之前执行
                .order(-100);
    }
}