| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.zy.core.enums.ShuttleTaskModeType; |
| | | |
| | | import java.io.*; |
| | | import java.util.ArrayList; |
| | |
| | | public class NavigateMapData { |
| | | |
| | | public int[][] getData() { |
| | | return getData("in"); |
| | | return getData(ShuttleTaskModeType.PAK_IN.id); |
| | | } |
| | | |
| | | public int[][] getData(String mapType) { |
| | | public int[][] getData(Integer mapType) { |
| | | try { |
| | | String mapFilename = ""; |
| | | if (mapType.equals("in")) { |
| | | if (mapType == ShuttleTaskModeType.PAK_IN.id) { |
| | | //入库地图 |
| | | mapFilename = "mapIn.json"; |
| | | }else { |
| | | //出库地图 |
| | | mapFilename = "mapOut.json"; |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |