lyh
3 天以前 4e24c63554a7a234c7b79fdcd8991b8024ef7a5f
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java
@@ -1213,11 +1213,7 @@
        // 检查项目名称列
        Cell nameCell = row.getCell(1);
        if (nameCell != null && nameCell.getCellType() != CellType.BLANK) {
            return false;
        }
        return true;
        return nameCell == null || nameCell.getCellType() == CellType.BLANK;
    }
    /**
@@ -1324,7 +1320,7 @@
            EamMaintenanceStandard oldStandardForRevision = null;
            Map<String, Integer> deviceVersionMap = new HashMap<>();
            Map<String, Integer> compositeVersionMap = new HashMap<>();
            List<String> notFoundEquipmentCodes = new ArrayList<>();
            // 获取文档中的所有段落
            List<XWPFParagraph> paragraphs = doc.getParagraphs();
@@ -1358,6 +1354,21 @@
                    EamMaintenanceStandard standard = extractDeviceInfo(table, type);
                    if (standard == null) {
                        throw new ImportException("表格" + (i+1) + ":设备信息提取失败");
                    }
                    if (StrUtil.isEmpty(standard.getEquipmentId())) {
                        // 记录未找到的设备编码
                        if (StrUtil.isNotEmpty(standard.getEquipmentCode())) {
                            notFoundEquipmentCodes.add(standard.getEquipmentCode());
                        } else {
                            notFoundEquipmentCodes.add("未知编码(表格" + (i+1) + ")");
                        }
                        // 跳过当前设备,继续处理下一个
                        do {
                            i++;
                        } while (i < tables.size() && !isDeviceInfoTable(tables.get(i)));
                        continue;
                    }
                    // 从文档中获取标题(表格前的段落)
@@ -1409,6 +1420,11 @@
            // 校验设备数量
            if (standards.isEmpty()) {
                // 如果所有设备都未找到,返回特定错误
                if (!notFoundEquipmentCodes.isEmpty()) {
                    return Result.error(fileName + ":所有设备编码均未找到:" +
                            String.join(", ", notFoundEquipmentCodes));
                }
                return Result.error(fileName + ":未找到有效的设备信息表格");
            }
@@ -1431,7 +1447,15 @@
            // 作废旧版本(保留最新版本)
            obsoleteOldVersionsByCompositeKey(deviceVersionMap);
            if (!notFoundEquipmentCodes.isEmpty()) {
                String successMsg = fileName + "部分导入成功,设备数:" + standards.size() +
                        ",项目数:" + allItems.size();
                String errorMsg = "以下设备编码未找到:" + String.join(", ", notFoundEquipmentCodes);
                return Result.ok(successMsg + ";但" + errorMsg);
            }
            return Result.ok(fileName + "导入成功,设备数:" + standards.size() + ",项目数:" + allItems.size());
        } catch (ImportException e) {
            return Result.error(fileName + ":" + e.getMessage());
@@ -1471,13 +1495,10 @@
    /**
     * 从表格前的段落中提取标题(修复版)
     * 从表格前的段落中提取标题
     */
    private String extractTitleBeforeTable(XWPFTable table, List<XWPFParagraph> paragraphs) {
        try {
            // 获取表格的CTTbl对象
            CTTbl ctTbl = table.getCTTbl();
            // 获取表格所在的body
            IBody body = table.getBody();
@@ -1513,7 +1534,7 @@
                XWPFTableRow firstRow = table.getRow(0);
                for (XWPFTableCell cell : firstRow.getTableCells()) {
                    String text = getCellText(cell);
                    if (text != null && text.contains("保养规范")) {
                    if (text.contains("保养规范")) {
                        return text.trim();
                    }
                }
@@ -1864,15 +1885,21 @@
        standard.setEquipmentName(row2Data.get("设备名称"));
        standard.setEquipmentModel(row2Data.get("设备型号"));
        // 关联设备ID
        // 关联设备ID - 修改点:设备未找到时不抛出异常
        if (StrUtil.isNotEmpty(standard.getEquipmentCode())) {
            EamEquipment equipment = eamEquipmentService.selectByEquipmentCode(standard.getEquipmentCode());
            if (equipment == null) {
                log.warn("设备编码未找到: {}", standard.getEquipmentCode());
                return null;
                // 记录未找到设备编码的日志
                log.error("设备编码未找到: {}", standard.getEquipmentCode());
                // 返回对象但设备ID为空,表示设备未找到
                return standard;
            } else {
                standard.setEquipmentId(equipment.getId());
            }
        } else {
            // 处理设备编码为空的情况
            log.error("设备编码为空");
            return standard;
        }
        return standard;