自动化立体仓库 - WCS系统
Junjie
2023-03-28 6bad808389ec9d4c7331bb471c1410b50893fc1c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.zy.common.utils;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zy.core.enums.ShuttleTaskModeType;
 
import java.io.*;
import java.util.ArrayList;
 
/**
 * A*算法地图获取类
 */
public class NavigateMapData {
 
    public int[][] getData() {
        return getData(ShuttleTaskModeType.PAK_IN.id);
    }
 
    public int[][] getData(Integer mapType) {
        try {
            String mapFilename = "";
            if (mapType == ShuttleTaskModeType.PAK_IN.id) {
                //入库地图
                mapFilename = "mapIn.json";
            }else {
                //出库地图
                mapFilename = "mapOut.json";
            }
 
            String fileName = this.getClass().getClassLoader().getResource(mapFilename).getPath();//获取文件路径
            File file = new File(fileName);
            StringBuffer stringBuffer = new StringBuffer();
            if (file.isFile() && file.exists()) {
                InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
                BufferedReader br = new BufferedReader(isr);
                String lineTxt = null;
                while ((lineTxt = br.readLine()) != null) {
                    stringBuffer.append(lineTxt);
                }
                br.close();
 
                //解析json地图数据
                ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class);
                int[][] map = new int[arrayList.size()][];
                int j = 0;
                for (Object obj : arrayList) {
                    ArrayList list = JSON.parseObject(obj.toString(), ArrayList.class);
                    int[] tmp = new int[list.size()];
                    int i = 0;
                    for (Object o : list) {
                        JSONObject jsonObject = JSON.parseObject(o.toString());
                        //将数据添加进二维数组
                        tmp[i++] = Integer.parseInt(jsonObject.get("value").toString());
                    }
                    //数据添加进一维数组
                    map[j++] = tmp;
                }
 
                return map;
            } else {
                System.out.println("文件不存在!");
            }
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
        return null;
    }
 
    //获取JSON格式数据
    public ArrayList<ArrayList<JSONObject>> getJsonData(Integer mapType) {
        try {
            String mapFilename = "";
            if (mapType == ShuttleTaskModeType.PAK_IN.id) {
                //入库地图
                mapFilename = "mapIn.json";
            }else {
                //出库地图
                mapFilename = "mapOut.json";
            }
 
            String fileName = this.getClass().getClassLoader().getResource(mapFilename).getPath();//获取文件路径
            File file = new File(fileName);
            StringBuffer stringBuffer = new StringBuffer();
            if (file.isFile() && file.exists()) {
                InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
                BufferedReader br = new BufferedReader(isr);
                String lineTxt = null;
                while ((lineTxt = br.readLine()) != null) {
                    stringBuffer.append(lineTxt);
                }
                br.close();
 
                //返回的结果集
                ArrayList<ArrayList<JSONObject>> returnLists = new ArrayList<>();
 
                //解析json地图数据
                ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class);
                for (Object obj : arrayList) {
                    ArrayList list = JSON.parseObject(obj.toString(), ArrayList.class);
                    ArrayList<JSONObject> maps = new ArrayList<>();
                    for (Object o : list) {
                        JSONObject jsonObject = JSON.parseObject(o.toString());
                        maps.add(jsonObject);
                    }
                    returnLists.add(maps);
                }
 
                return returnLists;
            } else {
                System.out.println("文件不存在!");
            }
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
        return null;
    }
 
}