| | |
| | | |
| | | JSONObject recordValues = StrUtil.isBlank(snapshot.getRecordValues()) |
| | | ? new JSONObject() : JSON.parseObject(snapshot.getRecordValues()); |
| | | // 保存时同样只取模板中的第一个导出值,提交校验与保存口径保持一致。 |
| | | String coordinate = coordinates.get(0); |
| | | JSONObject cell = recordValues.getJSONObject(coordinate); |
| | | Object value = cell == null ? null : cell.get("v"); |
| | | if (value == null || StringUtils.isBlank(String.valueOf(value))) { |
| | | missing.add(templateName + "(" + coordinate + ")"); |
| | | for (String coordinate : coordinates) { |
| | | JSONObject cell = recordValues.getJSONObject(coordinate); |
| | | Object value = cell == null ? null : cell.get("v"); |
| | | if (value == null || StringUtils.isBlank(String.valueOf(value))) { |
| | | missing.add(templateName + "(" + coordinate + ")"); |
| | | } |
| | | } |
| | | } |
| | | return missing; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 新聚直绑模板订单:一个模板页签在报告中只对应一条检测项目。 |
| | | * 新聚直绑模板订单:模板中每一个“导出值”批注都对应报告中的一条检测项目。 |
| | | */ |
| | | private List<Map<String, String>> buildTemplateDetectionResultRows(Integer orderId) { |
| | | List<InsOrderStandardTemplate> snapshots = insOrderStandardTemplateService.list( |
| | |
| | | List<Map<String, String>> rows = new ArrayList<>(); |
| | | int sequence = 1; |
| | | for (InsOrderStandardTemplate snapshot : snapshots) { |
| | | TemplateExportCell exportCell = getFirstTemplateExportCell(snapshot.getThing()); |
| | | List<TemplateExportCell> exportCells = getTemplateExportCells(snapshot.getThing()); |
| | | JSONObject recordValues = StrUtil.isBlank(snapshot.getRecordValues()) |
| | | ? new JSONObject() : JSON.parseObject(snapshot.getRecordValues()); |
| | | String result = readTemplateCellText(recordValues, exportCell.resultCoordinate, exportCell.templateValues); |
| | | if (StringUtils.isBlank(result)) { |
| | | throw new ErrorException("模板“" + defaultReportText(snapshot.getName(), "模板ID " + snapshot.getTemplateId()) |
| | | + "”的导出值不能为空"); |
| | | } |
| | | String unit = exportCell.unitCoordinate == null ? null |
| | | : readTemplateCellText(recordValues, exportCell.unitCoordinate, exportCell.templateValues); |
| | | String itemName = exportCell.itemCoordinate == null ? null |
| | | : readTemplateCellText(recordValues, exportCell.itemCoordinate, exportCell.templateValues); |
| | | for (TemplateExportCell exportCell : exportCells) { |
| | | String result = readTemplateCellText(recordValues, exportCell.resultCoordinate, exportCell.templateValues); |
| | | if (StringUtils.isBlank(result)) { |
| | | throw new ErrorException("模板“" + defaultReportText(snapshot.getName(), "模板ID " + snapshot.getTemplateId()) |
| | | + "”的导出值不能为空(" + exportCell.resultCoordinate + ")"); |
| | | } |
| | | String unit = exportCell.unitCoordinate == null ? null |
| | | : readTemplateCellText(recordValues, exportCell.unitCoordinate, exportCell.templateValues); |
| | | String itemName = exportCell.itemCoordinate == null ? null |
| | | : readTemplateCellText(recordValues, exportCell.itemCoordinate, exportCell.templateValues); |
| | | |
| | | Map<String, String> row = new LinkedHashMap<>(); |
| | | row.put("seq", String.valueOf(sequence++)); |
| | | String reportItemName = defaultReportText(itemName, |
| | | defaultReportText(snapshot.getName(), "模板ID " + snapshot.getTemplateId())); |
| | | row.put("itemName", formatExportItemName(reportItemName)); |
| | | row.put("unit", defaultReportText(unit, "/")); |
| | | row.put("result", result); |
| | | rows.add(row); |
| | | Map<String, String> row = new LinkedHashMap<>(); |
| | | row.put("seq", String.valueOf(sequence++)); |
| | | String reportItemName = defaultReportText(itemName, |
| | | defaultReportText(snapshot.getName(), "模板ID " + snapshot.getTemplateId())); |
| | | row.put("itemName", formatExportItemName(reportItemName)); |
| | | row.put("unit", defaultReportText(unit, "/")); |
| | | row.put("result", result); |
| | | rows.add(row); |
| | | } |
| | | } |
| | | if (rows.isEmpty()) { |
| | | throw new ErrorException("当前订单未找到可生成报告的原始记录模板"); |
| | |
| | | return rows; |
| | | } |
| | | |
| | | private TemplateExportCell getFirstTemplateExportCell(String compressedThing) { |
| | | private List<TemplateExportCell> getTemplateExportCells(String compressedThing) { |
| | | if (StrUtil.isBlank(compressedThing)) { |
| | | throw new ErrorException("原始记录模板为空"); |
| | | } |
| | |
| | | throw new ErrorException("模板必须至少配置一个导出值批注"); |
| | | } |
| | | exportCells.sort(Comparator.comparingInt((int[] cell) -> cell[0]).thenComparingInt(cell -> cell[1])); |
| | | int[] firstExport = exportCells.get(0); |
| | | int resultColumnForRow = resultColumn == null ? firstExport[1] : resultColumn; |
| | | // 通常“导出值”批注配置在项目名称单元格;若配置在结果单元格,则回到“检测项目”列取名称。 |
| | | Integer itemColumnForRow = !Objects.equals(firstExport[1], resultColumnForRow) |
| | | ? firstExport[1] : itemColumn; |
| | | TemplateExportCell result = new TemplateExportCell(); |
| | | result.resultCoordinate = firstExport[0] + "-" + resultColumnForRow; |
| | | result.itemCoordinate = itemColumnForRow == null ? null : firstExport[0] + "-" + itemColumnForRow; |
| | | result.unitCoordinate = unitColumn == null ? null : firstExport[0] + "-" + unitColumn; |
| | | result.templateValues = templateValues; |
| | | return result; |
| | | List<TemplateExportCell> results = new ArrayList<>(); |
| | | for (int[] exportCell : exportCells) { |
| | | int resultColumnForRow = resultColumn == null ? exportCell[1] : resultColumn; |
| | | // 通常“导出值”批注配置在项目名称单元格;若配置在结果单元格,则回到“检测项目”列取名称。 |
| | | Integer itemColumnForRow = !Objects.equals(exportCell[1], resultColumnForRow) |
| | | ? exportCell[1] : itemColumn; |
| | | TemplateExportCell result = new TemplateExportCell(); |
| | | result.resultCoordinate = exportCell[0] + "-" + resultColumnForRow; |
| | | result.itemCoordinate = itemColumnForRow == null ? null : exportCell[0] + "-" + itemColumnForRow; |
| | | result.unitCoordinate = unitColumn == null ? null : exportCell[0] + "-" + unitColumn; |
| | | result.templateValues = templateValues; |
| | | results.add(result); |
| | | } |
| | | return results; |
| | | } |
| | | |
| | | private String readTemplateCellText(JSONObject recordValues, String coordinate, Map<String, String> templateValues) { |