From e702165615e9f0b1d9feba7b038f2afa4a610418 Mon Sep 17 00:00:00 2001 From: wanxiaoli Date: Mon, 19 Jan 2026 09:03:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BD=A8=E8=BF=B9=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=EF=BC=8C=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=A2=91=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/ServerSendEventServer.java | 21 +++++- .../service/impl/TsFilesServiceImpl.java | 69 ++++++++++++------- 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/java/src/main/java/com/yfd/platform/component/ServerSendEventServer.java b/java/src/main/java/com/yfd/platform/component/ServerSendEventServer.java index d22d2e4..451bd51 100644 --- a/java/src/main/java/com/yfd/platform/component/ServerSendEventServer.java +++ b/java/src/main/java/com/yfd/platform/component/ServerSendEventServer.java @@ -1,6 +1,7 @@ package com.yfd.platform.component; import lombok.extern.slf4j.Slf4j; +import org.apache.catalina.connector.ClientAbortException; import org.springframework.http.MediaType; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; @@ -65,13 +66,27 @@ public class ServerSendEventServer { } } catch (IOException e) { - log.error("user id:{}, send message error:{}", userId, - e.getMessage()); - e.printStackTrace(); + // 处理客户端断开连接的情况 + if (e instanceof ClientAbortException || + (e.getCause() != null && e.getCause() instanceof ClientAbortException)) { + log.warn("客户端已断开连接,移除SSE连接,user id: {}", userId); + } else { + log.error("发送消息失败,user id:{}, error:{}", userId, e.getMessage()); + } + + // 移除已失效的emitter + removeEmitter(userId); } } } + private static void removeEmitter(String userId) { + SseEmitter emitter = sseEmitterMap.remove(userId); + if (emitter != null) { + emitter.complete(); // 确保资源释放 + } + } + /** * 给所有用户发消息 */ diff --git a/java/src/main/java/com/yfd/platform/modules/experimentalData/service/impl/TsFilesServiceImpl.java b/java/src/main/java/com/yfd/platform/modules/experimentalData/service/impl/TsFilesServiceImpl.java index 70cac4f..f868593 100644 --- a/java/src/main/java/com/yfd/platform/modules/experimentalData/service/impl/TsFilesServiceImpl.java +++ b/java/src/main/java/com/yfd/platform/modules/experimentalData/service/impl/TsFilesServiceImpl.java @@ -5459,11 +5459,16 @@ public class TsFilesServiceImpl extends ServiceImpl impl // 根据文件后缀确定配置文件路径 String configResourcePath; + String Separator; if (fileName.toLowerCase().endsWith(".csv")) { + configResourcePath = "config/trj_config.txt"; + Separator = ","; } else if (fileName.toLowerCase().endsWith(".txt")) { configResourcePath = "config/trj_config_ins_img.txt"; + Separator = "\t"; } else { + Separator = ""; throw new IllegalArgumentException("不支持的文件格式: " + fileName + ",仅支持.csv和.txt文件"); } @@ -5499,7 +5504,7 @@ public class TsFilesServiceImpl extends ServiceImpl impl Path dataPath = basePath.resolve(tsFiles.getFileName()); // 4. 处理数据文件 - processDataFile(dataPath, samTimes, token, timeColumn, lonColumn, latColumn, hgtColumn); + processDataFile(dataPath, samTimes, token, timeColumn, lonColumn, latColumn, hgtColumn,Separator); } catch (Exception e) { LOGGER.error("任务执行失败: {}", e.getMessage(), e); @@ -5665,7 +5670,7 @@ public class TsFilesServiceImpl extends ServiceImpl impl private void processDataFile(Path dataPath, int samTimes, String token, String timeColumn, String lonColumn, - String latColumn, String hgtColumn) + String latColumn, String hgtColumn,String Separator) throws IOException { try (BufferedReader reader = Files.newBufferedReader(dataPath, StandardCharsets.UTF_8)) { @@ -5749,32 +5754,50 @@ public class TsFilesServiceImpl extends ServiceImpl impl int sendCount = 0; int lineCountData = 0; - float timeValue0 = 0; - float timeValue1 = 0; + double timeValue0 = 0; + double timeValue1 = 0; int result = 0; // - while (!Thread.currentThread().isInterrupted() && (line = reader.readLine()) != null) { - lineCountData++; - if (lineCountData > 2) { - break; // 跳出循环,停止读取数据 + while (!Thread.currentThread().isInterrupted() ) { + String line1 = ""; + String line2 = ""; + if((line = reader.readLine()) != null) + line1 = line; + if ((line = reader.readLine()) != null) { + line2 = line; } + System.out.println("正在处理数据行: {}" +line1); + System.out.println("正在处理数据行: {}" +line2); // 使用逗号分隔数据行 - String[] values = line.split(","); // 改为逗号分隔 - if (lineCountData == 1) { - // 读取第一行的时间值 - timeValue0 = Float.parseFloat(getValueSafely(values, timeIndex, "0.0")); // 将字符串转换为数字 - } else if (lineCountData == 2) { - // 读取第二行的时间值 - timeValue1 = Float.parseFloat(getValueSafely(values, timeIndex, "0.0")); // 将字符串转换为数字 - // 计算 timeValue1 - timeValue0 - float data = timeValue1 - timeValue0; - // 计算 1 / data - if (data != 0) { // 确保避免除以零 - result = (int) Math.floor(1 / data); - } else { - result = 1; - } + String[] values = line1.split(Separator); // 改为逗号分隔 + timeValue0 = Float.parseFloat(values[timeIndex]);//Float.parseFloat(getValueSafely(values, timeIndex, "0.0")); + String[] values2 = line2.split(Separator); // 改为逗号分隔 + timeValue1 = Float.parseFloat(values2[timeIndex]);//Float.parseFloat(getValueSafely(values2, timeIndex, "0.0")); + + double data = timeValue1 - timeValue0; + // 计算 1 / data + if (Math.abs(data) > 0.0000001) { + // 四舍五入,而不是向下取整 + result = (int) Math.round(1.0 / data); + break; + }else { + result = 1; } +// if (lineCountData == 1) { +// // 读取第一行的时间值 +// timeValue0 = Float.parseFloat(getValueSafely(values, timeIndex, "0.0")); // 将字符串转换为数字 +// } else if (lineCountData == 2) { +// // 读取第二行的时间值 +// timeValue1 = Float.parseFloat(getValueSafely(values, timeIndex, "0.0")); // 将字符串转换为数字 +// // 计算 timeValue1 - timeValue0 +// float data = timeValue1 - timeValue0; +// // 计算 1 / data +// if (data != 0) { // 确保避免除以零 +// result = (int) Math.floor(1 / data); +// } else { +// result = 1; +// } +// } }