| | |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.TreeMap; |
| | | |
| | | /** |
| | |
| | | protected Map<Integer, FuzzyResult> deviceResMap; |
| | | |
| | | TreeRoot<HierarchyData> deviceHierarchy; |
| | | |
| | | Map<String, Long> deviceProblemHazardCounts; |
| | | |
| | | Map<String, Long> deviceProblemCheckCounts; |
| | | |
| | | /** |
| | | * 生成报告数据 |
| | |
| | | List<Object> result = new ArrayList<>(); |
| | | |
| | | JSONObject info = new JSONObject(); |
| | | info.put("设备编号", device.getName()); |
| | | info.put("设备编号", device.getManufacturerNumber()); |
| | | |
| | | var errorCounts = deviceRes.root().getData().getTotalErrorCounts(); |
| | | info.put("一级隐患", errorCounts[0]); |
| | |
| | | List<Object> result = new ArrayList<>(); |
| | | |
| | | JSONObject info = new JSONObject(); |
| | | info.put("设备编号", device.getName()); |
| | | info.put("设备编号", device.getManufacturerNumber()); |
| | | |
| | | info.put("问题", buildDeviceErrorInfo(device)); |
| | | result.add(info); |
| | |
| | | // 检查问题列:默认为问题备注,当问题备注为空时,填写问题描述(与安全报告一致) |
| | | info.put("检查问题", StringUtils.hasText(record.getRemark()) ? record.getRemark() : record.getProblem().getDescription()); |
| | | info.put("隐患等级", record.getLevel().getDesc()); |
| | | info.put("同类隐患出现频次", getDeviceProblemHazardCount(record)); |
| | | info.put("检查频次", getDeviceProblemCheckCount(record)); |
| | | var subItem = buildRecordDetail(record); |
| | | subItem.put("项目级别", errorNode(record).getName()); |
| | | info.put("问题详情", subItem); |
| | |
| | | return result; |
| | | } |
| | | |
| | | private long getDeviceProblemHazardCount(ErrorRecord record) { |
| | | if (deviceProblemHazardCounts == null) { |
| | | return 0L; |
| | | } |
| | | return deviceProblemHazardCounts.getOrDefault(buildDeviceProblemKey(record), 0L); |
| | | } |
| | | |
| | | private long getDeviceProblemCheckCount(ErrorRecord record) { |
| | | if (deviceProblemCheckCounts == null) { |
| | | return 0L; |
| | | } |
| | | return deviceProblemCheckCounts.getOrDefault(buildDeviceProblemKey(record), 0L); |
| | | } |
| | | |
| | | private String buildDeviceProblemKey(ErrorRecord record) { |
| | | Integer deviceId = record != null && record.getDevice() != null ? record.getDevice().getId() : null; |
| | | Integer problemId = record != null && record.getProblem() != null ? record.getProblem().getId() : null; |
| | | return buildDeviceProblemKey(deviceId, problemId); |
| | | } |
| | | |
| | | public static String buildDeviceProblemKey(Integer deviceId, Integer problemId) { |
| | | return Objects.toString(deviceId, "") + "::" + Objects.toString(problemId, ""); |
| | | } |
| | | |
| | | /** |
| | | * 构建设备记录 |
| | | * @param device 设备 |
| | | * @return 设备记录 |
| | | */ |
| | | private List<ErrorRecord> buildDeviceRecords(Device device){ |
| | | return records.stream().filter(r -> r.getDevice().getId().equals(device.getId())).toList(); |
| | | return records.stream() |
| | | .filter(r -> r.getDevice().getId().equals(device.getId())) |
| | | .sorted(Comparator.comparing(r -> r.getLevel() != null ? r.getLevel().ordinal() : ErrorLevel.P4.ordinal())) |
| | | .toList(); |
| | | } |
| | | |
| | | |