| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取PLC2数据 |
| | | */ |
| | | @GetMapping("/plc2/auth") |
| | | @ManagerAuth |
| | | public R getMapFromPlc2() { |
| | | try { |
| | | String mapFilename = "plc2.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(); |
| | | } |
| | | |
| | | NavigateMapData navigateMapData = new NavigateMapData(); |
| | | |
| | | //解析json地图数据 |
| | | ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class); |
| | | List<List<MapNode>> lists = new ArrayList<>(); |
| | | //重建数据格式 |
| | | for (int i = 0; i < arrayList.size(); i++) { |
| | | Object obj = arrayList.get(i); |
| | | List<MapNode> list = JSON.parseArray(obj.toString(), MapNode.class); |
| | | for (int j = 0; j < list.size(); j++) { |
| | | MapNode mapNode = list.get(j); |
| | | list.set(j, mapNode); |
| | | } |
| | | lists.add(list); |
| | | } |
| | | return R.ok().add(lists); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return R.error(); |
| | | } |
| | | |
| | | /** |
| | | * 重置redis中的地图,将占用的库位全部解除 |
| | | */ |
| | | @GetMapping("/map/resetMap/auth") |