1
zhang
2025-09-10 b1e74bb24e7785176e59699cfe8eb4f217c958c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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;
    }
 
}