刘光辉
14 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
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
package jnpf.limsService.support;
 
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
 
public class LimsSxtQushiApiChecks {
 
    public static void main(String[] args) throws Exception {
        Path root = Paths.get("").toAbsolutePath().normalize();
        String controller = read(root, "jnpf-lims/jnpf-lims-controller/src/main/java/jnpf/limsController/LimsSxtQushiController.java");
        require(controller, "@RequestMapping(\"/lims/biz/sxt/qushi\")", "trend controller route missing");
        require(controller, "@GetMapping(\"/options\")", "options endpoint missing");
        require(controller, "@PostMapping(\"/data\")", "data endpoint missing");
        require(controller, "quyangdian_ids", "trend option endpoint must accept selected point ids");
 
        String service = read(root, "jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/LimsSxtQushiService.java");
        require(service, "listOptions", "options service contract missing");
        require(service, "listData", "data service contract missing");
 
        String implementation = read(root, "jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/LimsSxtQushiServiceImpl.java");
        require(implementation, "LimsSxtQushiTrendSupport.toNumericOrNull", "numeric result normalization missing");
        require(implementation, "JianyanStatus.AUDITED", "only audited inspection results may be returned");
        require(implementation, "getShujuLeixing", "trendability must consider the configured data type");
        require(implementation, "getLaiyuanRenwuId", "trend result must link the source Renwu");
        require(implementation, "getRenwuJianyanXiangKuaizhaoId", "trend standard must link the inspection snapshot");
        require(implementation, "getSuoshuChejianId",
                "trend Renwu joins must use the workshop id snapshot");
        require(implementation, "ZoneId.of(\"Asia/Shanghai\")", "trend date range must use the fixed business time zone");
        require(implementation, "LimsJianyanXiangEntity::getId", "trend records must retain the inspection item id");
        require(implementation, "LimsSxtQuyangJihuaRenwuJianyanXiangKuaizhaoEntity::getFTenantId",
                "trend snapshot reads must enforce tenant isolation");
        require(implementation, "LimsSxtQuyangJihuaRenwuJianyanXiangKuaizhaoEntity::getRenwuId",
                "trend snapshot reads must enforce source Renwu integrity");
        require(implementation, "dangqianZuhuId", "tenant isolation missing");
        require(implementation, "pointIds.retainAll(validPointIds)",
                "inspection item options must require a point from the selected sample and workshop");
        reject(implementation, "LimsSxtQuyangJihuaTaskEntity", "legacy Task must not drive trends");
 
        String mapper = read(root, "jnpf-lims/jnpf-lims-biz/src/main/resources/mapper/LimsSxtQushiMapper.xml");
        String sampleTypeQuery = selectBlock(mapper, "selectSampleTypes");
        require(sampleTypeQuery, "FROM yangpin_guanli y", "sample types must start from sample master data");
        require(sampleTypeQuery, "INNER JOIN qingyan_leixing ql", "sample types must resolve the inspection category");
        require(sampleTypeQuery, "y.biz_enabled = 'enabled'", "disabled samples must be excluded");
        require(sampleTypeQuery, "ql.fenlei_mingcheng = '水系统'", "sample types must be limited to water system samples");
        reject(sampleTypeQuery, "activePointJoins", "sample types must not depend on sampling point configuration");
        require(mapper, "FROM lims_sxt_quyangdian p", "trend parent options must use active point master data");
        String inspectionItemQuery = selectBlock(mapper, "selectInspectionItems");
        require(inspectionItemQuery, "FROM lims_sxt_qingyan_xiangmu q", "trend items must start from request-item configuration");
        require(inspectionItemQuery, "lims_sxt_qingyan_xiangmu_zixiang qz", "trend items must use request-item configuration rows");
        require(inspectionItemQuery, "q.yangpin_leixing = #{yangpinLeixingId}", "trend items must follow the selected sample");
        require(inspectionItemQuery, "LEFT JOIN jianyan_xiangmu_guanli i", "configured items must remain visible without matching master data");
        require(inspectionItemQuery, "i.bianma = qz.xiangmu_bianhao", "inspection master data must be resolved by item code");
        require(inspectionItemQuery, "LEFT JOIN zhiliang_biaozhun_guanli_zixiang s", "configured standard limits must be resolved from the standard item id");
        require(inspectionItemQuery, "s.f_id = qz.xiangmu_id", "configured item id must resolve the standard item");
        require(inspectionItemQuery, "TRIM(COALESCE(NULLIF(s.shuju_leixing, ''), i.jieguo_leixing)) = '数值'",
                "trend item options must only return numeric data types");
        reject(inspectionItemQuery, "i.f_id = qz.xiangmu_id", "standard item ids must not be treated as inspection master ids");
        reject(inspectionItemQuery, "lims_sxt_quyang_jihua", "trend items must not depend on sampling plans");
        reject(inspectionItemQuery, "chejianId", "trend items must not be limited by workshop");
        reject(inspectionItemQuery, "quyangdian", "trend items must not be limited by sampling points");
        reject(mapper, "r.renwu_zhuangtai = 'generated'", "trend options must not require generated tasks");
        reject(implementation, "ZhiliangBiaozhunGuanli", "current standards must not override trend history data");
 
        String pointVo = read(root, "jnpf-lims/jnpf-lims-entity/src/main/java/jnpf/limsEntity/LimsSxtQushiQuyangdianVo.java");
        require(pointVo, "@JsonProperty(\"quyangdian_bianhao\")", "sampling point number JSON field missing");
        require(pointVo, "@JsonProperty(\"quyang_didian\")", "sampling point location JSON field missing");
 
        String itemVo = read(root, "jnpf-lims/jnpf-lims-entity/src/main/java/jnpf/limsEntity/LimsSxtQushiJianyanXiangmuVo.java");
        require(itemVo, "@JsonProperty(\"jianyan_xiangmu_bianma\")", "inspection item code JSON field missing");
        require(itemVo, "@JsonProperty(\"lilun_shangxian\")", "inspection theoretical upper JSON field missing");
        require(itemVo, "@JsonProperty(\"lilun_xiaxian\")", "inspection theoretical lower JSON field missing");
        require(itemVo, "@JsonProperty(\"biaozhun_shangxian\")", "inspection standard upper JSON field missing");
        require(itemVo, "@JsonProperty(\"biaozhun_xiaxian\")", "inspection standard lower JSON field missing");
    }
 
    private static String read(Path root, String relativePath) throws Exception {
        return new String(Files.readAllBytes(root.resolve(relativePath)));
    }
 
    private static String selectBlock(String mapper, String id) {
        int start = mapper.indexOf("<select id=\"" + id + "\"");
        int end = mapper.indexOf("</select>", start);
        if (start < 0 || end < 0) {
            throw new AssertionError("mapper select block missing: " + id);
        }
        return mapper.substring(start, end);
    }
 
    private static void require(String source, String token, String message) {
        if (!source.contains(token)) {
            throw new AssertionError(message);
        }
    }
 
    private static void reject(String source, String token, String message) {
        if (source.contains(token)) {
            throw new AssertionError(message);
        }
    }
}