From 33c638f4f7d49d92814a5d69cf51dca6026ced66 Mon Sep 17 00:00:00 2001 From: Junjie <xjj@123> Date: 星期五, 18 十月 2024 14:22:04 +0800 Subject: [PATCH] # --- zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java | 205 +++++++++++++++++++++++++++++++++++--------------- 1 files changed, 142 insertions(+), 63 deletions(-) diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java index 820c458..d252ea6 100644 --- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java @@ -60,17 +60,44 @@ public synchronized ShuttleThread searchIdleShuttle(Task task) { String locNo = taskService.judgeInbound(task) ? task.getDestLoc() : task.getOriginLoc(); ShuttleThread resThread = null; - Integer finalDistance = ShuttleDispatcher.INF; - - //妫�娴嬬洰鏍囨ゼ灞傝溅鏁伴噺鏄惁灏忎簬鍏佽鐨勬渶澶ф暟閲� - boolean checkDispatchMaxNum = checkDispatchMaxNum(Utils.getLev(locNo), task.getHostId()); - + int lev = Utils.getLev(locNo); List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>() .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()) .eq(Device::getHostId, task.getHostId()) .eq(Device::getStatus, 1)); - + //鑾峰彇鍚屽眰灏忚溅 + List<Device> currentLevDevices = new ArrayList<>(); + //鑾峰彇璺ㄥ眰灏忚溅 + List<Device> diffLevDevices = new ArrayList<>(); for (Device device : list) { + //鑾峰彇鍥涘悜绌挎杞︾嚎绋� + ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); + ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); + if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { + continue; + } + + if (Utils.getLev(shuttleProtocol.getCurrentLocNo()) == lev) { + currentLevDevices.add(device); + }else { + diffLevDevices.add(device); + } + } + //鎼滅储鍚屽眰 + resThread = this.searchCurrentLevShuttle(currentLevDevices, locNo); + + //鍚屽眰娌℃湁鎼滅储鍒板悎閫傚皬杞︼紝璺ㄦゼ灞傛悳绱� + if(resThread == null) { + resThread = this.searchDiffLevShuttle(diffLevDevices, locNo, task); + } + + return resThread; + } + + private synchronized ShuttleThread searchCurrentLevShuttle(List<Device> devices, String locNo) { + ShuttleThread resThread = null; + Integer finalDistance = ShuttleDispatcher.INF; + for (Device device : devices) { if (taskService.hasBusyOutboundByShuttle(Integer.parseInt(device.getDeviceNo()))) { continue; } @@ -115,32 +142,102 @@ break; } - String targetLocNo = null;//榛樿鍒版彁鍗囨満寰呮満浣� // 鍚屾ゼ灞傜洿鎺ヨ绠楀埌鐩爣搴撲綅 - if (currentLev == Utils.getLev(locNo)) { - targetLocNo = locNo; - }else { - if (!checkDispatchMaxNum) { - News.info("{}浠诲姟锛寋}灞傦紝宸茬粡杈惧埌褰撳墠妤煎眰璋冨害杞﹁締鏈�澶у��", task.getTaskNo(), Utils.getLev(locNo)); - continue; - } - - //鑾峰彇璺濈鐩爣浣嶇疆鏈�杩戠殑绌洪棽鍙崲灞傛彁鍗囨満 - LiftThread liftThread = liftDispatcher.searchIdleLift(locNo, task.getHostId(), true); - if (liftThread == null) { - continue; - } - Device recentTransferLift = liftThread.getDevice(); - - //鑾峰彇灏忚溅妤煎眰鎻愬崌鏈哄緟鏈轰綅 - ShuttleStandby shuttleStandby = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>() - .eq(ShuttleStandby::getDeviceId, recentTransferLift.getId()) - .eq(ShuttleStandby::getDeviceLev, currentLev) - .eq(ShuttleStandby::getStatus, 1)); - targetLocNo = shuttleStandby.getDeviceLoc(); + //褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鐩爣搴撲綅璺濈 + List<NavigateNode> currentShuttlePath = NavigateUtils.calc( + currentLocNo + , locNo + , NavigationMapType.NORMAL.id + , Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), currentLev) + );//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘 + if (currentShuttlePath == null) { + continue; } - //褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鎻愬崌鏈哄彛璺濈 + Integer currDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� + + // 鎸傝浇浠诲姟鏉冮噸 + List<Task> tasks = taskService.selectWorkingByShuttle(Integer.valueOf(device.getDeviceNo()), null); + if (!Cools.isEmpty(tasks)) { + currDistance += tasks.size() * WEIGHT; + } + + if (currDistance < finalDistance) { + finalDistance = currDistance; + resThread = shuttleThread; + } + } + + return resThread; + } + + private synchronized ShuttleThread searchDiffLevShuttle(List<Device> devices, String locNo, Task task) { + ShuttleThread resThread = null; + Integer finalDistance = ShuttleDispatcher.INF; + + //妫�娴嬬洰鏍囨ゼ灞傝溅鏁伴噺鏄惁灏忎簬鍏佽鐨勬渶澶ф暟閲� + boolean checkDispatchMaxNum = checkDispatchMaxNum(Utils.getLev(locNo), task.getHostId()); + + for (Device device : devices) { + if (taskService.hasBusyOutboundByShuttle(Integer.parseInt(device.getDeviceNo()))) { + continue; + } + //鑾峰彇鍥涘悜绌挎杞︾嚎绋� + ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); + ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); + if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { + continue; + } + + if (!shuttleThread.isIdle()) { + continue; + } + + BasShuttle basShuttle = basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>() + .eq(BasShuttle::getShuttleNo, device.getDeviceNo()) + .eq(BasShuttle::getHostId, device.getHostId())); + if (basShuttle == null) { + continue;//灏忚溅鍩虹鏁版嵁涓嶅瓨鍦� + } + + if (!Cools.isEmpty(basShuttle.getDisableLev())) { + List<Integer> disableLev = JSON.parseArray(basShuttle.getDisableLev(), Integer.class); + //妫�鏌ュ皬杞︽槸鍚︾鐢ㄨ妤煎眰 + if (disableLev.contains(Utils.getLev(locNo))) { + continue;//灏忚溅绂佺敤璇ユゼ灞傝烦杩囪杞� + } + } + + //妫�娴嬫槸鍚﹀瓨鍦ㄥ厖鐢典换鍔� + Task taskCharge = taskService.selectChargeWorking(Integer.valueOf(device.getDeviceNo())); + if (taskCharge != null) { + continue; + } + + // 鏈夋病鏈夎鍏朵粬浠诲姟璋冨害 + int currentLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠灞傞珮 + String currentLocNo = shuttleProtocol.getCurrentLocNo();//灏忚溅褰撳墠搴撲綅鍙� + + if (!checkDispatchMaxNum) { + News.info("{}浠诲姟锛寋}灞傦紝宸茬粡杈惧埌褰撳墠妤煎眰璋冨害杞﹁締鏈�澶у��", task.getTaskNo(), Utils.getLev(locNo)); + continue; + } + + //鑾峰彇璺濈灏忚溅浣嶇疆鏈�杩戠殑绌洪棽鍙崲灞傛彁鍗囨満 + LiftThread liftThread = liftDispatcher.searchIdleLift(currentLocNo, task.getHostId(), true); + if (liftThread == null) { + continue; + } + Device recentTransferLift = liftThread.getDevice(); + + //鑾峰彇灏忚溅妤煎眰鎻愬崌鏈哄緟鏈轰綅 + ShuttleStandby shuttleStandby = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>() + .eq(ShuttleStandby::getDeviceId, recentTransferLift.getId()) + .eq(ShuttleStandby::getDeviceLev, currentLev) + .eq(ShuttleStandby::getStatus, 1)); + String targetLocNo = shuttleStandby.getDeviceLoc(); + + //褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鎻愬崌鏈哄緟鏈轰綅璺濈 List<NavigateNode> currentShuttlePath = NavigateUtils.calc( currentLocNo , targetLocNo @@ -338,7 +435,7 @@ return false; } - int levCount = 0;//鐩爣妤煎眰杞﹁締鏁伴噺 + ArrayList<Integer> shuttleNos = new ArrayList<>(); List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>() .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()) .eq(Device::getHostId, hostId) @@ -373,7 +470,7 @@ continue;//鍏呯數涓� } - levCount++;//鐩爣妤煎眰鏈夎溅锛屾暟閲忓鍔� + shuttleNos.add(shuttleProtocol.getShuttleNo());//鐩爣妤煎眰鏈夎溅锛屾坊鍔犺繘list } } @@ -391,52 +488,34 @@ } if (targetLev == lev) { - levCount++;//宸ヤ綔妗g洰鏍囨ゼ灞傚拰瀹為檯妤煎眰鐩稿悓锛屾暟閲忓鍔� + //宸ヤ綔妗g洰鏍囨ゼ灞傚拰瀹為檯妤煎眰鐩稿悓锛屾暟閲忓鍔� + if (!shuttleNos.contains(task.getShuttleNo())) { + shuttleNos.add(task.getShuttleNo()); + } continue; } - } //鎼滅储鏄惁瀛樺湪鍓嶅線鐩爣妤煎眰鐨勫皬杞﹀伐浣滄。 for (Task task : taskService.list(new LambdaQueryWrapper<Task>() .in(Task::getTaskSts, TaskStsType.NEW_INBOUND.sts, TaskStsType.ANALYZE_INBOUND.sts, TaskStsType.EXECUTE_INBOUND.sts, TaskStsType.COMPLETE_INBOUND.sts , TaskStsType.NEW_OUTBOUND.sts, TaskStsType.ANALYZE_OUTBOUND.sts, TaskStsType.EXECUTE_OUTBOUND.sts, TaskStsType.COMPLETE_OUTBOUND.sts))) { - - List<Motion> motions = motionService.list(new LambdaQueryWrapper<Motion>() - .eq(Motion::getTaskNo, task.getTaskNo()) - .in(Motion::getMotionCtg, MotionCtgType.SHUTTLE_MOVE - , MotionCtgType.SHUTTLE_MOVE_LIFT_PALLET - , MotionCtgType.SHUTTLE_MOVE_DOWN_PALLET - , MotionCtgType.SHUTTLE_MOVE_FROM_LIFT - , MotionCtgType.SHUTTLE_MOVE_TO_LIFT - , MotionCtgType.SHUTTLE_MOVE_FROM_CONVEYOR - , MotionCtgType.SHUTTLE_MOVE_TO_CONVEYOR - , MotionCtgType.SHUTTLE_MOVE_FROM_LIFT_TO_CONVEYOR - )); - - boolean isUpdateLev = false; - for (Motion motion : motions) { - if (motion.getOrigin() == null || motion.getTarget() == null) { - continue; - } - - int sourceLev = Utils.getLev(motion.getOrigin());//鍔ㄤ綔婧愭ゼ灞� - int targetLev = Utils.getLev(motion.getTarget());//鍔ㄤ綔鐩爣妤煎眰 - if (sourceLev != targetLev) { - isUpdateLev = true; - break; - } - } - - if(isUpdateLev) { - levCount++;//宸ヤ綔妗e睘浜庤法灞備换鍔★紝灏忚溅褰掑睘浜庣洰鏍囨ゼ灞� + String locNo = taskService.judgeInbound(task) ? task.getDestLoc() : task.getOriginLoc(); + if (Utils.getLev(locNo) != lev) { continue; } + if (task.getShuttleNo() == null) { + continue; + } + + if (!shuttleNos.contains(task.getShuttleNo())) { + shuttleNos.add(task.getShuttleNo()); + } } - return levCount < Integer.parseInt(dict.getValue()); + return shuttleNos.size() < Integer.parseInt(dict.getValue()); } //鍒嗘瀽鍑哄簱璺緞寰呮満搴撲綅 -- Gitblit v1.9.1