package com.algo.util;
|
|
import com.algo.model.AGVStatus;
|
import com.algo.model.TaskData;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import java.io.File;
|
import java.io.FileNotFoundException;
|
import java.io.IOException;
|
import java.util.List;
|
|
public class AgvTaskUtils {
|
|
/**
|
* 加载和解析AGV状态列表
|
*
|
* @param filePath 文件地址
|
* @return AGV状态列表
|
*/
|
public static List<AGVStatus> loadAgvStatus(String filePath) {
|
ObjectMapper objectMapper = new ObjectMapper();
|
try {
|
// 直接解析JSON数组为List<AGVStatus>
|
return objectMapper.readValue(
|
new File(filePath),
|
new TypeReference<List<AGVStatus>>() {
|
}
|
);
|
} catch (FileNotFoundException e) {
|
System.err.println("AGV状态列表文件不存在: " + e.getMessage());
|
} catch (IOException e) {
|
System.err.println("路径AGV状态列表文件读取错误: " + e.getMessage());
|
} catch (Exception e) {
|
System.err.println("加载AGV状态列表文件失败: " + e.getMessage());
|
}
|
return null;
|
}
|
|
/**
|
* 加载和解析任务列表
|
*
|
* @param filePath 文件地址
|
* @return 任务列表
|
*/
|
public static List<TaskData> loadTaskList(String filePath) {
|
ObjectMapper objectMapper = new ObjectMapper();
|
try {
|
// 直接解析JSON数组为List<TaskData>,使用TypeReference指定泛型类型,避免类型擦除导致的转换错误
|
return objectMapper.readValue(
|
new File(filePath),
|
new TypeReference<List<TaskData>>() {
|
}
|
);
|
} catch (FileNotFoundException e) {
|
System.err.println("任务列表文件不存在: " + e.getMessage());
|
} catch (IOException e) {
|
System.err.println("任务列表文件读取错误: " + e.getMessage());
|
} catch (Exception e) {
|
System.err.println("加载任务列表文件失败: " + e.getMessage());
|
}
|
return null;
|
}
|
|
}
|