liujie
2026-09-20 25999c575dd42b4715e49d3fe57e73c2c3204ccb
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
package com.estate.expert.admin.stat.report.data;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.estate.expert.admin.domain.exam.eval.fuzzy.FuzzyResult;
import com.estate.expert.admin.domain.exam.eval.fuzzy.FuzzyRiskLevel;
import com.estate.expert.admin.domain.exam.eval.fuzzy.FuzzyValue;
import com.estate.expert.admin.domain.exam.eval.score.ScoreResult;
import com.estate.expert.admin.domain.exam.eval.score.ScoreValue;
import com.estate.expert.admin.domain.project.Project;
import com.estate.expert.admin.domain.project.enums.ProjectType;
import com.estate.expert.admin.domain.report.ReportTemplate;
import com.estate.expert.admin.stat.report.builder.SystemReportBuilder;
import com.estate.expert.admin.stat.report.data.impl.SystemScoreReportData;
import com.estate.expert.admin.utils.tree.TreeNode;
import org.junit.jupiter.api.Test;
 
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
 
class SystemReportDataTest {
 
    @Test
    void scoreReportUsesScoreTreeForHazardSummary() {
        var project = new Project();
        project.setName("测试项目");
        project.setType(ProjectType.HOUSE_CONSTRUCTION);
 
        var template = new ReportTemplate();
        template.setNumber("TEST");
 
        var scoreRoot = new TreeNode<>("root", ScoreValue.builder()
                .score(80)
                .totalErrorCounts(new int[]{1, 2, 3, 4})
                .build());
        var fuzzyRoot = new TreeNode<>("root", FuzzyValue.builder()
                .riskLevel(FuzzyRiskLevel.P4)
                .totalErrorCounts(new int[]{9, 9, 9, 9})
                .build());
 
        var report = SystemScoreReportData.builder()
                .reportId(1)
                .project(project)
                .template(template)
                .devices(List.of())
                .scoreResult(new ScoreResult(scoreRoot))
                .sysResult(new FuzzyResult(fuzzyRoot))
                .build()
                .generate();
 
        var summary = report.getJSONObject("评估结果").getJSONObject("隐患等级分布");
        assertEquals(10, summary.getIntValue("隐患数量"));
        assertEquals(1, summary.getIntValue("一级隐患数量"));
        assertEquals(4, summary.getIntValue("四级隐患数量"));
    }
 
    @Test
    void hazardDistributionIncludesManagementBehavior() throws Exception {
        var evalResult = new JSONObject();
        var checkItems = new JSONArray();
        checkItems.add(checkItem("安全检查"));
        checkItems.add(checkItem("管理行为"));
        evalResult.put("检查项", checkItems);
 
        var data = new JSONObject();
        data.put("评估结果", evalResult);
 
        Method initChart = SystemReportBuilder.class.getDeclaredMethod(
                "initChart", JSONObject.class, java.util.Map.class);
        initChart.setAccessible(true);
        initChart.invoke(new SystemReportBuilder(null), data, new HashMap<>());
 
        assertEquals(2, evalResult.getJSONArray("安全检查项").size());
        assertEquals("管理行为", evalResult.getJSONArray("安全检查项")
                .getJSONObject(1).getString("名称"));
    }
 
    private JSONObject checkItem(String name) {
        var item = new JSONObject();
        item.put("类别", "测试类别");
        item.put("问题数量", 1);
        item.put("问题百分比", "100.00%");
 
        var category = new JSONObject();
        category.put("分项", new JSONArray(List.of(item)));
 
        var result = new JSONObject();
        result.put("名称", name);
        result.put("分项评估", new JSONArray(List.of(category)));
        return result;
    }
}