刘光辉
15 小时以前 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
package jnpf.bizcommon.audit.service.listener;
 
import com.alibaba.fastjson.JSON;
 
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
 
/** 子表差异从 VisualLog listLog 进入统一审计契约的轻量探针。 */
public final class AuditChildTableDiffProbe {
 
    private AuditChildTableDiffProbe() {
    }
 
    public static void main(String[] args) {
        Map<String, Object> childField = map("prop", "xiangmu", "label", "项目", "jnpfKey", "input");
        Map<String, Object> childRow = map("xiangmu", "新项目", "jnpf_old_xiangmu", "旧项目", "jnpf_type", 1);
        Map<String, Object> tableLog = map(
                "field", "tableField1", "fieldName", "检测项目", "jnpfKey", "table", "type", 1,
                "targetTable", "lims_jianyan_xiang",
                "chidField", Collections.singletonList(childField),
                "chidData", Collections.singletonList(childRow));
        Map<String, Object> mainLog = map("field", "biz_status", "fieldName", "状态", "jnpfKey", "select");
 
        List<Map<String, Object>> childDiffs = AuditVisualLogListener.childDiffs(Arrays.asList(mainLog, tableLog));
        check("只提取一个子表项", childDiffs.size() == 1);
        check("保留子表数据", childDiffs.get(0).get("chidData") instanceof List);
        check("保留子表表头", childDiffs.get(0).get("chidField") instanceof List);
        check("保留子表物理表名", "lims_jianyan_xiang".equals(childDiffs.get(0).get("targetTable")));
 
        String merged = AuditVisualLogListener.appendChildDiffs(
                "[{\"field\":\"biz_status\",\"oldData\":\"created\",\"newData\":\"confirmed\"}]",
                childDiffs);
        List<?> mergedItems = JSON.parseArray(merged);
        check("主表和子表差异同时保留", mergedItems.size() == 2);
 
        Map<String, Object> row = map("biz_status", "confirmed", "tableField1", "[{...}]");
        Map<String, Object> withoutChild = AuditVisualLogListener.withoutFields(
                row, new LinkedHashSet<>(Collections.singletonList("tablefield1")));
        check("普通字段 diff 排除子表原始数组", withoutChild.containsKey("biz_status") && !withoutChild.containsKey("tableField1"));
    }
 
    private static Map<String, Object> map(Object... values) {
        Map<String, Object> result = new LinkedHashMap<>();
        for (int i = 0; i < values.length; i += 2) {
            result.put(String.valueOf(values[i]), values[i + 1]);
        }
        return result;
    }
 
    private static void check(String message, boolean condition) {
        if (!condition) {
            throw new AssertionError(message);
        }
        System.out.println("PASS: " + message);
    }
}