| | |
| | | // 统计导入结果 |
| | | 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; |
| | | } |
| | | |
| | | // 构建最终响应 |
| | |
| | | // 统计导入结果 |
| | | 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; |
| | | } |
| | | |
| | | // 构建最终响应 |
| | |
| | | |
| | | /** |
| | | * 升版导入 |
| | | * @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) { |