| | |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | var result = buildReportInfo(); |
| | | result.put("工程概况", buildProjectInfo()); |
| | | result.put("设备信息", buildDeviceInfo()); |
| | | result.put("设备分组信息", buildDeviceGroupInfo()); |
| | | result.put("评估结果", buildEvalInfo()); |
| | | return result; |
| | | } |
| | |
| | | */ |
| | | 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("报告日期", reportDate); |
| | | result.put("报告日期中文", reportDate.format(DateTimeFormatter.ofPattern("yyyy年M月d日"))); |
| | | result.put("公司名称", "四川信立隆第三方评估咨询有限公司"); |
| | | return result; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 按设备类型汇总设备信息,供新版报告模板使用 |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | | * 构建错误级别 |
| | | * @param node 节点 |
| | | * @return 错误级别 |
| | |
| | | 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; |
| | | } |