From c9c80ecde06d151f4f2f3ccf46d3f4c0e65cd8a1 Mon Sep 17 00:00:00 2001 From: zjj <3272660260@qq.com> Date: 星期二, 23 九月 2025 13:13:46 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/impl/NyShuttleThread.java | 219 +++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 149 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java index 312b527..44f6187 100644 --- a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java +++ b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java @@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.DateUtils; import com.core.common.SpringUtils; -import com.core.exception.CoolException; import com.fasterxml.jackson.databind.ObjectMapper; import com.zy.asrs.entity.BasShuttle; import com.zy.asrs.entity.DeviceConfig; @@ -59,6 +58,7 @@ private List<JSONObject> socketReadResults = new ArrayList<>(); private List<DeviceMsgModel> socketResults = new ArrayList<>(); + private Long requestReadTime = System.currentTimeMillis(); //鍘熷璁惧鏁版嵁 private Object originDeviceData; @@ -89,35 +89,35 @@ }); readThread.start(); - //璁惧鎵ц - Thread executeThread = new Thread(() -> { - while (true) { - try { - if (shuttleAction == null) { - try { - shuttleAction = SpringUtils.getBean(ShuttleAction.class); - }catch (Exception e){ - } - continue; - } - - Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo()); - if (object == null) { - continue; - } - - Integer taskNo = Integer.valueOf(String.valueOf(object)); - if (taskNo != 0) { - //瀛樺湪浠诲姟闇�瑕佹墽琛� - boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo); - } - Thread.sleep(100); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - executeThread.start(); +// //璁惧鎵ц +// Thread executeThread = new Thread(() -> { +// while (true) { +// try { +// if (shuttleAction == null) { +// try { +// shuttleAction = SpringUtils.getBean(ShuttleAction.class); +// }catch (Exception e){ +// } +// continue; +// } +// +// Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo()); +// if (object == null) { +// continue; +// } +// +// Integer taskNo = Integer.valueOf(String.valueOf(object)); +// if (taskNo != 0) { +// //瀛樺湪浠诲姟闇�瑕佹墽琛� +// boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo); +// } +// Thread.sleep(100); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// }); +// executeThread.start(); } private void listenMessageFromRedis() { @@ -200,7 +200,10 @@ //鎸囦护瓒呰繃2鏉★紝涓嶅啀涓嬪彂浠诲姟鐘舵�佽姹� TreeSet<String> deviceCommandMsgListKey = deviceMsgUtils.getDeviceCommandMsgListKey(SlaveType.Shuttle, deviceConfig.getDeviceNo()); if (deviceCommandMsgListKey.size() < 2) { - requestCommand(readStatusCommand);//璇锋眰鐘舵�� + if ((System.currentTimeMillis() - requestReadTime) > 500) { + requestCommand(readStatusCommand);//璇锋眰鐘舵�� + requestReadTime = System.currentTimeMillis(); + } } if (this.socketReadResults.isEmpty()) { @@ -578,7 +581,7 @@ } @Override - public boolean isRequireCharge() { + public ShuttleRequireChargeType isRequireCharge() { if (this.shuttleProtocol.getDeviceStatus() == null || this.shuttleProtocol.getPakMk() == null || this.shuttleProtocol.getErrorCode() == null @@ -586,7 +589,7 @@ || this.shuttleProtocol.getMode() == null || this.shuttleProtocol.getExtend() == null ) { - return false; + return ShuttleRequireChargeType.NONE; } InnerSuhttleExtend extend = (InnerSuhttleExtend) this.shuttleProtocol.getExtend(); @@ -599,25 +602,43 @@ && extend.getSuspendState() == 0 ; if (!res) { - return res; + return ShuttleRequireChargeType.NONE; } else { // 鐢甸噺灏忎簬闃堝�奸渶瑕佽繘琛屽厖鐢� try { BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class); if (shuttleService == null) { - return false; + return ShuttleRequireChargeType.NONE; } + BasShuttle basShuttle = shuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", deviceConfig.getDeviceNo())); if (basShuttle == null) { - return false; + return ShuttleRequireChargeType.NONE; } + Integer chargeLine = basShuttle.getChargeLine(); if (chargeLine == null) { - return false; + return ShuttleRequireChargeType.NONE; } - return Integer.valueOf(this.shuttleProtocol.getBatteryPower()) < chargeLine; + + boolean chargeResult = Integer.valueOf(this.shuttleProtocol.getBatteryPower()) < chargeLine; + if (chargeResult) { + return ShuttleRequireChargeType.FORCE_CHARGE;//闇�瑕佸己鍒跺厖鐢� + } + + Integer suggestChargeLine = basShuttle.getSuggestChargeLine(); + if (suggestChargeLine == null) { + return ShuttleRequireChargeType.NONE; + } + + boolean suggestChargeResult = Integer.valueOf(this.shuttleProtocol.getBatteryPower()) < suggestChargeLine; + if (suggestChargeResult) { + return ShuttleRequireChargeType.SUGGEST_CHARGE;//寤鸿鍏呯數 + } + + return ShuttleRequireChargeType.NONE; } catch (Exception e) { - return false; + return ShuttleRequireChargeType.NONE; } } } @@ -762,13 +783,15 @@ @Override public synchronized boolean setTaskNo(Integer taskNo) { + redisUtil.set(RedisKeyType.SHUTTLE_FLAG.key + shuttleProtocol.getShuttleNo(), taskNo); this.shuttleProtocol.setTaskNo(taskNo); return true; } @Override public synchronized boolean setSyncTaskNo(Integer taskNo) { - this.shuttleProtocol.setSyncTaskNo(taskNo); + redisUtil.setSync(RedisKeyType.SHUTTLE_FLAG.key + shuttleProtocol.getShuttleNo(), taskNo); + this.shuttleProtocol.setTaskNo(taskNo); return true; } @@ -927,8 +950,11 @@ return false; } + List<NavigationMapType> restartCalcMapTypes = new ArrayList<>(mapTypes); + restartCalcMapTypes.add(NavigationMapType.SHUTTLE); + String currentLocNo = shuttleProtocol.getCurrentLocNo(); - List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(currentLocNo, locNo, mapTypes, assignCommand, this); + List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(currentLocNo, locNo, restartCalcMapTypes, assignCommand, this); if (commands == null) { return false; } @@ -963,7 +989,7 @@ } @Override - public ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes) { + public ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes, Boolean shuttleDirectionReverse) { NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class); NyShuttleHttpCommand httpStandard = getHttpStandard(deviceConfig.getDeviceNo(), taskNo); NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest(); @@ -974,21 +1000,25 @@ HashMap<String, Object> body = new HashMap<>(); body.put("requestType", "move");//绉诲姩鍛戒护 body.put("taskId", taskId);//TaskID闇�瑕侀殢鏈� -// body.put("start", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(startCodeNum, device.getHostId())));//璧风偣 -// body.put("target", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(distCodeNum, device.getHostId())));//缁堢偣 body.put("path", path); request.setBody(body); NavigateNode startNode = nodes.get(0); + List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null); for (NavigateNode node : nodes) { HashMap<String, Object> data = new HashMap<>(); String codeNum = NavigatePositionConvert.xyToPosition(node.getX(), node.getY(), node.getZ()); Map<String, Object> nyNode = navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(codeNum)); - int xp = Integer.parseInt(String.valueOf(nyNode.get("y"))); - int yp = Integer.parseInt(String.valueOf(nyNode.get("x"))); + + int xp = Integer.parseInt(String.valueOf(nyNode.get("x"))); + int yp = Integer.parseInt(String.valueOf(nyNode.get("y"))); + if (shuttleDirectionReverse) { + xp = Integer.parseInt(String.valueOf(nyNode.get("y"))); + yp = Integer.parseInt(String.valueOf(nyNode.get("x"))); + } + int z = Integer.parseInt(String.valueOf(nyNode.get("z"))); - List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null); List<MapNode> mapNodes = mapData.get(node.getX()); MapNode mapNode = mapNodes.get(node.getY()); @@ -1002,18 +1032,76 @@ httpStandard.setRequest(request); - LocMastService locMastService = SpringUtils.getBean(LocMastService.class); - LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() - .eq("qr_code_value", distCodeNum)); - if (locMast == null) { - throw new CoolException("搴撲綅淇℃伅涓嶅瓨鍦�"); - } + Object object = redisUtil.get(RedisKeyType.LOC_MAP.key); + HashMap<String, String> locMap = (HashMap<String, String>) object; + String targetLocNo = locMap.get(distCodeNum); ShuttleCommand command = new ShuttleCommand(); command.setShuttleNo(deviceConfig.getDeviceNo()); command.setBody(JSON.toJSONString(httpStandard)); command.setMode(ShuttleCommandModeType.MOVE.id); - command.setTargetLocNo(locMast.getLocNo()); + command.setTargetLocNo(targetLocNo); + command.setTaskNo(taskId); + return command; + } + + @Override + public ShuttleCommand getMoveLiftCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes, Boolean moveIn, Boolean shuttleDirectionReverse) { + NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class); + NyShuttleHttpCommand httpStandard = getHttpStandard(deviceConfig.getDeviceNo(), taskNo); + NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest(); + + ArrayList<HashMap<String, Object>> path = new ArrayList<>(); + + Integer taskId = getTaskId(); + HashMap<String, Object> body = new HashMap<>(); + if (moveIn) { + body.put("requestType", "intoLift");//杩涙彁鍗囨満 + } else { + body.put("requestType", "outLift");//鍑烘彁鍗囨満 + } + body.put("taskId", taskId);//TaskID闇�瑕侀殢鏈� + body.put("path", path); + request.setBody(body); + + NavigateNode startNode = nodes.get(0); + List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null); + for (NavigateNode node : nodes) { + HashMap<String, Object> data = new HashMap<>(); + String codeNum = NavigatePositionConvert.xyToPosition(node.getX(), node.getY(), node.getZ()); + Map<String, Object> nyNode = navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(codeNum)); + + int xp = Integer.parseInt(String.valueOf(nyNode.get("x"))); + int yp = Integer.parseInt(String.valueOf(nyNode.get("y"))); + if (shuttleDirectionReverse) { + xp = Integer.parseInt(String.valueOf(nyNode.get("y"))); + yp = Integer.parseInt(String.valueOf(nyNode.get("x"))); + } + + int z = Integer.parseInt(String.valueOf(nyNode.get("z"))); + + List<MapNode> mapNodes = mapData.get(node.getX()); + MapNode mapNode = mapNodes.get(node.getY()); + + data.put("xp", xp); + data.put("yp", yp); + data.put("z", z); + data.put("x", mapNode.getXBase()); + data.put("y", mapNode.getYBase()); + path.add(data); + } + + httpStandard.setRequest(request); + + Object object = redisUtil.get(RedisKeyType.LOC_MAP.key); + HashMap<String, String> locMap = (HashMap<String, String>) object; + String targetLocNo = locMap.get(distCodeNum); + + ShuttleCommand command = new ShuttleCommand(); + command.setShuttleNo(deviceConfig.getDeviceNo()); + command.setBody(JSON.toJSONString(httpStandard)); + command.setMode(ShuttleCommandModeType.MOVE.id); + command.setTargetLocNo(targetLocNo); command.setTaskNo(taskId); return command; } @@ -1082,7 +1170,6 @@ //鑾峰彇灏忚溅澶嶄綅鍝嶅簲鍛戒护 public ShuttleCommand getInitCommand(Integer taskNo, Integer code) { - LocMastService locMastService = SpringUtils.getBean(LocMastService.class); NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class); NyShuttleHttpCommand httpStandard = getHttpStandard(deviceConfig.getDeviceNo(), taskNo); NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest(); @@ -1098,15 +1185,14 @@ map.put("z", lev); String mapStr = JSON.toJSONString(map); - LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() - .eq("qr_code_value", mapStr)); - if (locMast == null) { - throw new CoolException("鍦板潃鐮佷笉瀛樺湪"); - } + + Object object = redisUtil.get(RedisKeyType.LOC_MAP.key); + HashMap<String, String> locMap = (HashMap<String, String>) object; + String targetLocNo = locMap.get(mapStr); List<List<MapNode>> mapData = navigateMapData.getJsonData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null); - List<MapNode> mapNodes = mapData.get(locMast.getRow1()); - MapNode mapNode = mapNodes.get(locMast.getBay1()); + List<MapNode> mapNodes = mapData.get(Utils.getRow(targetLocNo)); + MapNode mapNode = mapNodes.get(Utils.getBay(targetLocNo)); HashMap<String, Object> location = new HashMap<>(); location.put("xp", row); @@ -1256,13 +1342,6 @@ //WCS绯荤粺鍧愭爣杞墰鐪煎潗鏍� private static int[] WCSXyzToNyXyz(int x, int y, int z) { -// //WCS绯荤粺Y杞� => 鐗涚溂X杞磋浆鎹㈠叕寮� -// int x1 = Math.abs(y - 61) + 11; -// //WCS绯荤粺X杞� => 鐗涚溂Y杞磋浆鎹㈠叕寮� -// int y1 = x + 10; - -// int x1 = x + 10; -// int y1 = y + 10; LocMastService locMastService = SpringUtils.getBean(LocMastService.class); LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() .eq("row1", x) @@ -1275,7 +1354,7 @@ String qrCodeValue = locMast.getQrCodeValue(); JSONObject data = JSON.parseObject(qrCodeValue); - return new int[]{data.getInteger("y"), data.getInteger("x"), z}; + return new int[]{data.getInteger("x"), data.getInteger("y"), z}; } @Override -- Gitblit v1.9.1