lyh
11 小时以前 4e24c63554a7a234c7b79fdcd8991b8024ef7a5f
保养规范修改导入与返回值
已修改2个文件
173 ■■■■ 文件已修改
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java 118 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java 55 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java
@@ -323,17 +323,49 @@
            // 统计导入结果
            int successCount = 0;
            int failureCount = 0;
            Result<?> importResult = new Result<>();
            // 用于收集所有未找到的设备编码
            List<String> allNotFoundCodes = new ArrayList<>();
            for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
                MultipartFile file = entity.getValue();
                String fileName = file.getOriginalFilename();
                Result<?> importResult=eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND",null);
                importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND", null);
                if (importResult.isSuccess()) {
                    // 检查是否包含部分成功信息
                    String message = importResult.getMessage();
                    if (message.contains("以下设备编码未找到:")) {
                        // 提取未找到的设备编码
                        String notFoundPart = message.substring(message.indexOf("以下设备编码未找到:") + 9);
                        allNotFoundCodes.addAll(Arrays.asList(notFoundPart.split(", ")));
                        // 修改为部分成功消息
                        importResult.setMessage(message.substring(0, message.indexOf(";但")));
                    }
                    successCount++;
                } else {
                    results.put(fileName, importResult.getMessage());
                    failureCount++;
                }
            }
            // 如果有未找到的设备编码,添加到最终结果
            if (!allNotFoundCodes.isEmpty()) {
                String notFoundMsg = "以下设备编码未找到:" + String.join(", ", allNotFoundCodes);
                if (successCount > 0) {
                    // 部分成功
                    return Result.ok("部分导入成功,成功文件数:" + successCount +
                            ",失败文件数:" + failureCount + ";" + notFoundMsg);
                } else {
                    // 全部失败
                    return Result.error("导入失败:" + notFoundMsg);
                }
            }
            if (successCount == 1) {
                return importResult;
            }
            // 构建最终响应
@@ -358,17 +390,50 @@
            // 统计导入结果
            int successCount = 0;
            int failureCount = 0;
            Result<?> importResult = new Result<>();
            // 用于收集所有未找到的设备编码
            List<String> allNotFoundCodes = new ArrayList<>();
            for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
                MultipartFile file = entity.getValue();
                String fileName = file.getOriginalFilename();
                Result<?> importResult= eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD",null);
                // 修正:三保导入应该使用"THIRD"类型
                importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD", null);
                if (importResult.isSuccess()) {
                    // 检查是否包含部分成功信息
                    String message = importResult.getMessage();
                    if (message.contains("以下设备编码未找到:")) {
                        // 提取未找到的设备编码
                        String notFoundPart = message.substring(message.indexOf("以下设备编码未找到:") + 9);
                        allNotFoundCodes.addAll(Arrays.asList(notFoundPart.split(", ")));
                        // 修改为部分成功消息
                        importResult.setMessage(message.substring(0, message.indexOf(";但")));
                    }
                    successCount++;
                } else {
                    results.put(fileName, importResult.getMessage());
                    failureCount++;
                }
            }
            // 如果有未找到的设备编码,添加到最终结果
            if (!allNotFoundCodes.isEmpty()) {
                String notFoundMsg = "以下设备编码未找到:" + String.join(", ", allNotFoundCodes);
                if (successCount > 0) {
                    // 部分成功
                    return Result.ok("部分导入成功,成功文件数:" + successCount +
                            ",失败文件数:" + failureCount + ";" + notFoundMsg);
                } else {
                    // 全部失败
                    return Result.error("导入失败:" + notFoundMsg);
                }
            }
            if (successCount == 1) {
                return importResult;
            }
            // 构建最终响应
@@ -382,31 +447,44 @@
    /**
     * 升版导入
     * @param id,file
     * @return
     */
    @ApiOperation(value = "升版导入", notes = "升版导入")
    @PostMapping(value = "/importUpgrade")
    public Result<?> importUpgrade(String id,MultipartFile file) {
        EamMaintenanceStandard eamMaintenanceStandard=eamMaintenanceStandardService.getById(id);
        if (eamMaintenanceStandard==null) {
    public Result<?> importUpgrade(String id, MultipartFile file) {
        EamMaintenanceStandard eamMaintenanceStandard = eamMaintenanceStandardService.getById(id);
        if (eamMaintenanceStandard == null) {
            return Result.error("请选择需要升版的保养标准");
        }else {
            switch (eamMaintenanceStandard.getMaintenanceCategory()){
        } else {
            Result<?> importResult;
            switch (eamMaintenanceStandard.getMaintenanceCategory()) {
                case "POINT_INSPECTION":
                    //点检升版导入
                    return eamMaintenanceStandardService.importPointInspectionExcel(file,id);
                case "SECOND_MAINTENANCE":
                    //二保升版导入
                    return eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND",id);
                case "THIRD_MAINTENANCE":
                    //三保升版导入
                    return eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD",id);
                default:
                    // 点检升版导入
                    importResult = eamMaintenanceStandardService.importPointInspectionExcel(file, id);
                    break;
                case "SECOND_MAINTENANCE":
                    // 二保升版导入
                    importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND", id);
                    break;
                case "THIRD_MAINTENANCE":
                    // 三保升版导入
                    importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD", id);
                    break;
                default:
                    return Result.error("不支持的保养类型");
            }
            // 处理升版导入中的设备未找到情况
            if (importResult.isSuccess()) {
                String message = importResult.getMessage();
                if (message.contains("以下设备编码未找到:")) {
                    // 提取未找到的设备编码
                    String notFoundPart = message.substring(message.indexOf("以下设备编码未找到:") + 9);
                    return Result.error("升版导入失败:" + notFoundPart);
                }
                return importResult;
            } else {
                return importResult;
            }
        }
        return Result.error("升版导入失败");
    }
    private Result<?> getResult(Map<String, String> results, int fileCount, int successCount, int failureCount) {
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;