“mitao”
2026-05-16 5b32f811c6bb6ddeb7f3a1cad4df68cf5705b9b0
admin-server/src/main/java/com/estate/expert/admin/stat/report/data/ReportDataBase.java
@@ -16,6 +16,7 @@
import org.springframework.util.StringUtils;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@@ -26,6 +27,10 @@
 */
@SuperBuilder
public abstract class ReportDataBase {
    private static final String DAIGUAN_REMARK = "岱观科技";
    private static final String DEFAULT_COMPANY_NAME = "四川信立隆第三方评估咨询有限公司";
    private static final String DAIGUAN_COMPANY_NAME = "四川岱观科技有限公司";
    ReportTemplate template;
@@ -45,6 +50,7 @@
        var result = buildReportInfo();
        result.put("工程概况", buildProjectInfo());
        result.put("设备信息", buildDeviceInfo());
        result.put("设备分组信息", buildDeviceGroupInfo());
        result.put("评估结果", buildEvalInfo());
        return result;
    }
@@ -61,11 +67,23 @@
     */
    protected JSONObject buildReportInfo() {
        JSONObject result = new JSONObject();
        var reportDate = LocalDate.now();
        result.put("项目名称", project.getName());
        result.put("报告编号", template.getNumber() + "-" + String.format("%08d", reportId));
        result.put("报告日期", LocalDate.now());
        result.put("公司名称", "四川信立隆第三方评估咨询有限公司");
        result.put("报告日期", reportDate);
        result.put("报告日期中文", reportDate.format(DateTimeFormatter.ofPattern("yyyy年M月d日")));
        result.put("报告年份", reportDate.getYear());
        result.put("报告月份", reportDate.getMonthValue());
        result.put("报告日期日", reportDate.getDayOfMonth());
        result.put("公司名称", buildCompanyName());
        return result;
    }
    private String buildCompanyName() {
        if (template != null && DAIGUAN_REMARK.equals(template.getRemark())) {
            return DAIGUAN_COMPANY_NAME;
        }
        return DEFAULT_COMPANY_NAME;
    }
    /**
@@ -74,10 +92,14 @@
     */
    protected List<Object> buildDeviceInfo() {
        List<Object> deviceInfos = new ArrayList<>();
        for (var device : devices) {
        // 按照设备类型排序
        var sortedDevices = devices.stream()
                .sorted(Comparator.comparing(device -> device.getType() != null ? device.getType().ordinal() : Integer.MAX_VALUE))
                .collect(Collectors.toList());
        for (var device : sortedDevices) {
            JSONObject deviceInfo = new JSONObject();
            deviceInfo.put("设备类型", device.getType().getDesc());
            deviceInfo.put("设备编号", device.getName());
            deviceInfo.put("设备编号", device.getManufacturerNumber());
            deviceInfo.put("设备租赁单位", device.getProperties().get("工程起重机械租赁单位"));
            deviceInfo.put("设备使用单位", device.getProperties().get("使用单位"));
            deviceInfo.put("安拆单位", device.getProperties().get("工程起重机械安拆单位"));
@@ -85,6 +107,40 @@
            deviceInfos.add(deviceInfo);
        }
        return deviceInfos;
    }
    /**
     * 按设备类型汇总设备信息,供新版报告模板使用
     * @return 设备分组信息
     */
    protected List<Object> buildDeviceGroupInfo() {
        Map<String, List<Device>> groupedDevices = devices.stream()
                .sorted(Comparator.comparing(device -> device.getType() != null ? device.getType().ordinal() : Integer.MAX_VALUE))
                .collect(Collectors.groupingBy(
                        device -> device.getType() != null ? device.getType().getDesc() : "",
                        LinkedHashMap::new,
                        Collectors.toList()
                ));
        List<Object> groupInfos = new ArrayList<>();
        groupedDevices.forEach((deviceType, groupDevices) -> {
            var deviceNumbers = groupDevices.stream()
                    .map(Device::getManufacturerNumber)
                    .filter(StringUtils::hasText)
                    .collect(Collectors.toList());
            if (deviceNumbers.isEmpty()) {
                deviceNumbers.add("");
            }
            for (int i = 0; i < deviceNumbers.size(); i++) {
                JSONObject groupInfo = new JSONObject();
                groupInfo.put("设备类型", i == 0 ? deviceType : "");
                groupInfo.put("设备数量", i == 0 ? groupDevices.size() : "");
                groupInfo.put("设备编号", deviceNumbers.get(i));
                groupInfos.add(groupInfo);
            }
        });
        return groupInfos;
    }
    /**
@@ -100,7 +156,7 @@
        int totalErrors = Arrays.stream(node.getData().getTotalErrorCounts()).sum();
        result.put("隐患数量", totalErrors);
        List<Object> errorInfos = new ArrayList<>();
        for (int i = 3; i>=0 ; i--) {
        for (int i = 0; i<4 ; i++) {
            var level = ErrorLevel.values()[i];
            var count = node.getData().getTotalErrorCounts()[i];
            var info = new JSONObject();
@@ -110,6 +166,10 @@
            info.put("比例", formatPercent(count * 1.0 / totalErrors));
            errorInfos.add(info);
        }
        result.put("一级隐患数量", node.getData().getTotalErrorCounts()[0]);
        result.put("二级隐患数量", node.getData().getTotalErrorCounts()[1]);
        result.put("三级隐患数量", node.getData().getTotalErrorCounts()[2]);
        result.put("四级隐患数量", node.getData().getTotalErrorCounts()[3]);
        result.put("分项", errorInfos);
        return result;
    }
@@ -140,7 +200,7 @@
        }
        info.put("工程类型", project.getType().getDesc());
        info.put("工程规模", project.getProjectCost());
        info.put("工程规模", project.getScale());
        if (projectInfo != null) {
            info.put("项目简介", projectInfo.getDetail());
@@ -181,7 +241,7 @@
        var problem = record.getProblem();
        JSONObject subItem = new JSONObject();
        if(record.getDevice() != null)
            subItem.put("设备编号", record.getDevice().getName());
            subItem.put("设备编号", record.getDevice().getManufacturerNumber());
        subItem.put("隐患等级", record.getLevel().getDesc());
        subItem.put("问题部位", record.getProblemPart());
        subItem.put("问题备注", trimText(StringUtils.hasText(record.getRemark()) ? record.getRemark() : problem.getDescription()));
@@ -191,13 +251,13 @@
        if(!CollectionUtils.isEmpty(problem.getSpecificTerms())){
            StringBuilder sb = new StringBuilder();
            var terms = CollectionUtils.isEmpty(record.getSpecificTermIndexes())
                ? problem.getSpecificTerms()
                : record.getSpecificTermIndexes().stream()
            var terms = CollectionUtils.isEmpty(record.getSpecificTermIndexes())
                    ? problem.getSpecificTerms()
                    : record.getSpecificTermIndexes().stream()
                    .filter(idx -> idx < problem.getSpecificTerms().size())
                    .map(problem.getSpecificTerms()::get)
                    .collect(Collectors.toList());
            for(int i = 0; i < terms.size(); i++) {
                sb.append(terms.get(i));
                if(i < terms.size() - 1) {