查询轨迹更改
This commit is contained in:
parent
0dd79f01e0
commit
8ad2eaf682
@ -5434,20 +5434,35 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
|
||||
//判断文件后缀是.txt还是.csv
|
||||
String fileName = tsFiles.getFileName();
|
||||
TsFiles tsFilesData = tsFilesMapper.selectById(configId);
|
||||
// TsFiles tsFilesData = tsFilesMapper.selectById(configId);
|
||||
|
||||
// 根据文件后缀确定配置文件路径
|
||||
String configResourcePath;
|
||||
if (fileName.toLowerCase().endsWith(".csv")) {
|
||||
configResourcePath = "config/trj_config.txt";
|
||||
} else if (fileName.toLowerCase().endsWith(".txt")) {
|
||||
configResourcePath = "config/trj_config_ins_img.txt";
|
||||
} else {
|
||||
throw new IllegalArgumentException("不支持的文件格式: " + fileName + ",仅支持.csv和.txt文件");
|
||||
}
|
||||
|
||||
|
||||
if (currentTaskFuture != null && !currentTaskFuture.isDone()) {
|
||||
currentTaskFuture.cancel(true);
|
||||
}
|
||||
|
||||
currentTaskFuture = executorService.submit(() -> {
|
||||
try {
|
||||
// 1. 获取配置文件路径
|
||||
StorageSourceConfig config = getStorageSourceConfig("filePath", "local", tsTask.getLocalStorageId());
|
||||
Path basePath = Paths.get(config.getValue() + tsFilesData.getWorkPath());
|
||||
// // 1. 获取配置文件路径
|
||||
// StorageSourceConfig config = getStorageSourceConfig("filePath", "local", tsTask.getLocalStorageId());
|
||||
// Path basePath = Paths.get(config.getValue() + tsFilesData.getWorkPath());
|
||||
//
|
||||
// // 2. 读取配置文件(假设配置文件名为 trj_config.txt)
|
||||
// Path configPath = basePath.resolve(tsFilesData.getFileName());
|
||||
// Map<String, String> columnMapping = parseConfigFile(configPath, token);
|
||||
|
||||
// 2. 读取配置文件(假设配置文件名为 trj_config.txt)
|
||||
Path configPath = basePath.resolve(tsFilesData.getFileName());
|
||||
Map<String, String> columnMapping = parseConfigFile(configPath, token);
|
||||
// 1. 从资源文件读取配置文件
|
||||
Map<String, String> columnMapping = parseConfigFromResource(configResourcePath, token);
|
||||
|
||||
String timeColumn = columnMapping.get("time");
|
||||
String lonColumn = columnMapping.get("lon");
|
||||
@ -5458,6 +5473,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
timeColumn, lonColumn, latColumn, hgtColumn);
|
||||
|
||||
// 3. 获取数据文件路径
|
||||
StorageSourceConfig config = getStorageSourceConfig("filePath", "local", tsTask.getLocalStorageId());
|
||||
Path basePath = Paths.get(config.getValue() + tsFiles.getWorkPath());
|
||||
Path dataPath = basePath.resolve(tsFiles.getFileName());
|
||||
|
||||
// 4. 处理数据文件
|
||||
@ -5477,6 +5494,64 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从资源文件读取配置文件并解析为列名映射
|
||||
*/
|
||||
public Map<String, String> parseConfigFromResource(String resourcePath, String token) throws IOException {
|
||||
Map<String, String> columnMapping = new HashMap<>();
|
||||
|
||||
// 使用ClassLoader读取资源文件
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
try (InputStream inputStream = classLoader.getResourceAsStream(resourcePath);
|
||||
BufferedReader reader = inputStream != null ?
|
||||
new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)) : null) {
|
||||
|
||||
if (reader == null) {
|
||||
throw new IOException("找不到配置文件: " + resourcePath);
|
||||
}
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (line.isEmpty() || line.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 分割键值对,支持=和:分隔符
|
||||
String[] parts = line.split("[=:]", 2);
|
||||
if (parts.length < 2) {
|
||||
LOGGER.warn("忽略无效行: {}", line);
|
||||
continue;
|
||||
}
|
||||
|
||||
String key = parts[0].trim().toLowerCase();
|
||||
String value = parts[1].trim();
|
||||
|
||||
// 清理引号
|
||||
if (value.startsWith("\"") && value.endsWith("\"")) {
|
||||
value = value.substring(1, value.length() - 1);
|
||||
}
|
||||
|
||||
// 只处理需要的键
|
||||
if (key.equals("time") || key.equals("lon") ||
|
||||
key.equals("lat") || key.equals("hgt")) {
|
||||
columnMapping.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 验证是否获取到所有必需的列
|
||||
if (columnMapping.size() < 4) {
|
||||
JSONObject jsonResponse = new JSONObject();
|
||||
jsonResponse.put("message", "配置文件选择错误,请重新选择!");
|
||||
|
||||
ServerSendEventServer.sendMessageById(token, jsonResponse.toString());
|
||||
throw new IOException("配置文件缺少必需列");
|
||||
}
|
||||
|
||||
return columnMapping;
|
||||
}
|
||||
|
||||
|
||||
// // 封装发送数据的逻辑
|
||||
// private void sendData(String token, String[] values, int lineCount) {
|
||||
|
||||
6
java/src/main/resources/config/trj_config.txt
Normal file
6
java/src/main/resources/config/trj_config.txt
Normal file
@ -0,0 +1,6 @@
|
||||
time: UTC
|
||||
lon: LonGps
|
||||
lat: LatGps
|
||||
hgt: HgtGps
|
||||
|
||||
|
||||
6
java/src/main/resources/config/trj_config_ins_img.txt
Normal file
6
java/src/main/resources/config/trj_config_ins_img.txt
Normal file
@ -0,0 +1,6 @@
|
||||
time: GPU_TEMP
|
||||
lon: LON
|
||||
lat: LAT
|
||||
hgt: ALT
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user