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;
|
}
|
}
|