From b13b6baf03a0860d0aa7fe7536bf2313588bf8ae Mon Sep 17 00:00:00 2001 From: zhangc <zc@123> Date: 星期日, 02 三月 2025 16:54:53 +0800 Subject: [PATCH] 四期 --- src/main/java/com/zy/asrs/controller/MapController.java | 213 ++++++++++++++++++++++++++++++++++------------------ 1 files changed, 138 insertions(+), 75 deletions(-) diff --git a/src/main/java/com/zy/asrs/controller/MapController.java b/src/main/java/com/zy/asrs/controller/MapController.java index 5a6d83a..653bd64 100644 --- a/src/main/java/com/zy/asrs/controller/MapController.java +++ b/src/main/java/com/zy/asrs/controller/MapController.java @@ -4,11 +4,14 @@ import com.alibaba.fastjson.JSONObject; import com.core.annotations.ManagerAuth; import com.core.common.R; +import com.zy.asrs.entity.BasMap; import com.zy.asrs.entity.LocDetl; import com.zy.asrs.entity.LocMast; +import com.zy.asrs.service.BasMapService; import com.zy.asrs.service.LocDetlService; import com.zy.asrs.service.LocMastService; import com.zy.asrs.utils.Utils; +import com.zy.common.utils.RedisUtil; import com.zy.common.web.BaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -25,6 +28,10 @@ private LocMastService locMastService; @Autowired private LocDetlService locDetlService; + @Autowired + private BasMapService basMapService; + @Autowired + private RedisUtil redisUtil; private static final List<String> DISABLE_LOC_NO = new ArrayList<String>() {{ // add("0200101"); @@ -43,85 +50,65 @@ @GetMapping("/map/getData/{lev}/auth") @ManagerAuth public String getMapData(@PathVariable("lev") Integer lev) { - try { - String mapFilename = "map.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(); + BasMap basMap = basMapService.selectLatestMap(lev); + //瑙f瀽json鍦板浘鏁版嵁 + List<ArrayList> arrayLists = JSON.parseArray(basMap.getData(), ArrayList.class); +// ArrayList<HashMap<String, Integer>> lineRows = new ArrayList<>(); +// int dataRow = 0; +// int dataRowCount = 0; +// for (int i = 1; i < arrayLists.size(); i++) { +// boolean flag = true; +// ArrayList rows = arrayLists.get(i); +// for (int j = 1; j < rows.size() - 1; j++) { +// Object o = rows.get(j); +// JSONObject jsonObject = JSON.parseObject(o.toString()); +// int value = Integer.parseInt(jsonObject.get("value").toString()); +// if (value >= 0 && value != 3) { +// //鍙湁璇ヨ涓殑浠讳竴涓�鍒楁湁鏁版嵁锛屽垯涓嶉渶瑕佸垱寤虹┖鐧借 +// flag = false; +// } +// } +// +// if (flag) { +// //绌虹櫧琛岄渶瑕佽烦杩� +// HashMap<String, Integer> map = new HashMap<>(); +// map.put("start", dataRow); +// int end = i - 1 - dataRowCount; +// map.put("end", end); +// map.put("count", dataRowCount); +// dataRow = end; +// dataRowCount++; +// lineRows.add(map); +// } +// } - //瑙f瀽json鍦板浘鏁版嵁 - List<ArrayList> arrayLists = JSON.parseArray(stringBuffer.toString(), ArrayList.class); - ArrayList<HashMap<String, Integer>> lineRows = new ArrayList<>(); - int dataRow = 0; - int dataRowCount = 0; - for (int i = 1; i < arrayLists.size(); i++) { - boolean flag = true; - ArrayList rows = arrayLists.get(i); - for (int j = 1; j < rows.size() - 1; j++) { - Object o = rows.get(j); - JSONObject jsonObject = JSON.parseObject(o.toString()); - int value = Integer.parseInt(jsonObject.get("value").toString()); - if (value >= 0 && value != 3) { - //鍙湁璇ヨ涓殑浠讳竴涓�鍒楁湁鏁版嵁锛屽垯涓嶉渶瑕佸垱寤虹┖鐧借 - flag = false; - } - } + //鑾峰彇褰撳墠妤煎眰搴撲綅鏁版嵁 + List<LocMast> locMasts = locMastService.selectLocByLev(lev); + for (LocMast locMast : locMasts) { + Integer row = locMast.getRow1(); + Integer bay = locMast.getBay1(); +// for (HashMap<String, Integer> lineRow : lineRows) { +// if (row > lineRow.get("start") && row <= lineRow.get("end")) { +// row += lineRow.get("count"); +// break; +// } +// } - if (flag) { - //绌虹櫧琛岄渶瑕佽烦杩� - HashMap<String, Integer> map = new HashMap<>(); - map.put("start", dataRow); - int end = i - 1 - dataRowCount; - map.put("end", end); - map.put("count", dataRowCount); - dataRow = end; - dataRowCount++; - lineRows.add(map); - } - } - - //鑾峰彇褰撳墠妤煎眰搴撲綅鏁版嵁 - List<LocMast> locMasts = locMastService.selectLocByLev(lev); - for (LocMast locMast : locMasts) { - Integer row = locMast.getRow1(); - Integer bay = locMast.getBay1(); - for (HashMap<String, Integer> lineRow : lineRows) { - if (row > lineRow.get("start") && row <= lineRow.get("end")) { - row += lineRow.get("count"); - break; - } - } - - ArrayList rowData = arrayLists.get(row); - Object o = rowData.get(bay); - JSONObject jsonObject = JSON.parseObject(o.toString()); - if (DISABLE_LOC_NO.contains(locMast.getLocNo())) { - //绂佹搴撲綅 - jsonObject.put("value", 10);//灏嗙鐢ㄥ簱浣嶈繘琛岃缃� - } - jsonObject.put("locNo", locMast.getLocNo());//璁剧疆搴撲綅鍙� - jsonObject.put("locSts", locMast.getLocSts());//搴撲綅鐘舵�� - //鏇存柊list - rowData.set(bay, jsonObject); - arrayLists.set(row, rowData); - } - - return JSONObject.toJSONString(arrayLists); - } else { - System.out.println("鏂囦欢涓嶅瓨鍦�!"); + ArrayList rowData = arrayLists.get(row); + Object o = rowData.get(bay); + JSONObject jsonObject = JSON.parseObject(o.toString()); + if (DISABLE_LOC_NO.contains(locMast.getLocNo())) { + //绂佹搴撲綅 + jsonObject.put("value", 10);//灏嗙鐢ㄥ簱浣嶈繘琛岃缃� } - } catch (IOException ioException) { - ioException.printStackTrace(); + jsonObject.put("locNo", locMast.getLocNo());//璁剧疆搴撲綅鍙� + jsonObject.put("locSts", locMast.getLocSts());//搴撲綅鐘舵�� + //鏇存柊list + rowData.set(bay, jsonObject); + arrayLists.set(row, rowData); } - return null; + + return JSONObject.toJSONString(arrayLists); } @RequestMapping("/map/searchData/auth") @@ -152,4 +139,80 @@ return R.ok().add(lists); } + @GetMapping("/map/realtime/getData/{lev}/auth") + @ManagerAuth + public String getRealtimeMapData(@PathVariable("lev") Integer lev) { + BasMap basMap = basMapService.selectLatestMap(lev); + //瑙f瀽json鍦板浘鏁版嵁 + List<ArrayList> arrayLists = JSON.parseArray(basMap.getData(), ArrayList.class); +// ArrayList<HashMap<String, Integer>> lineRows = new ArrayList<>(); +// int dataRow = 0; +// int dataRowCount = 0; +// for (int i = 1; i < arrayLists.size(); i++) { +// boolean flag = true; +// ArrayList rows = arrayLists.get(i); +// for (int j = 1; j < rows.size() - 1; j++) { +// Object o = rows.get(j); +// JSONObject jsonObject = JSON.parseObject(o.toString()); +// int value = Integer.parseInt(jsonObject.get("value").toString()); +// if (value >= 0 && value != 3) { +// //鍙湁璇ヨ涓殑浠讳竴涓�鍒楁湁鏁版嵁锛屽垯涓嶉渶瑕佸垱寤虹┖鐧借 +// flag = false; +// } +// } +// +// if (flag) { +// //绌虹櫧琛岄渶瑕佽烦杩� +// HashMap<String, Integer> map = new HashMap<>(); +// map.put("start", dataRow); +// int end = i - 1 - dataRowCount; +// map.put("end", end); +// map.put("count", dataRowCount); +// dataRow = end; +// dataRowCount++; +// lineRows.add(map); +// } +// } + + //鑾峰彇褰撳墠妤煎眰搴撲綅鏁版嵁 + List<LocMast> locMasts = locMastService.selectLocByLev(lev); + for (LocMast locMast : locMasts) { + Integer row = locMast.getRow1(); + Integer bay = locMast.getBay1(); +// for (HashMap<String, Integer> lineRow : lineRows) { +// if (row > lineRow.get("start") && row <= lineRow.get("end")) { +// row += lineRow.get("count"); +// break; +// } +// } + + ArrayList rowData = arrayLists.get(row); + Object o = rowData.get(bay); + JSONObject jsonObject = JSON.parseObject(o.toString()); + if (DISABLE_LOC_NO.contains(locMast.getLocNo())) { + //绂佹搴撲綅 + jsonObject.put("value", 10);//灏嗙鐢ㄥ簱浣嶈繘琛岃缃� + } + jsonObject.put("locNo", locMast.getLocNo());//璁剧疆搴撲綅鍙� + jsonObject.put("locSts", locMast.getLocSts());//搴撲綅鐘舵�� + //鏇存柊list + rowData.set(bay, jsonObject); + arrayLists.set(row, rowData); + } + + return JSONObject.toJSONString(arrayLists); + } + + @GetMapping("/map/resetMap/{lev}/auth") + @ManagerAuth + public R resetMap(@PathVariable("lev") Integer lev) { + Object o = redisUtil.get("realtimeBasMap_" + lev); + if (o == null) { + return R.error("鍙傛暟缂哄け"); + } + redisUtil.del("realtimeBasMap_" + lev); + basMapService.deleteByLev(lev); + return R.ok(); + } + } -- Gitblit v1.9.1