修改轨迹展示,获取数据发送频率

This commit is contained in:
wanxiaoli 2026-01-19 09:03:30 +08:00
parent a3adc6e33e
commit e702165615
2 changed files with 64 additions and 26 deletions

View File

@ -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(); // 确保资源释放
}
}
/**
* 给所有用户发消息
*/

View File

@ -5459,11 +5459,16 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> 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<TsFilesMapper, TsFiles> 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<TsFilesMapper, TsFiles> 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<TsFilesMapper, TsFiles> 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;
// }
// }
}