From 1be3b992120afd57db72b53c9819b8e8e74fbf29 Mon Sep 17 00:00:00 2001 From: lsh <lsh@163.com> Date: 星期五, 13 六月 2025 16:20:20 +0800 Subject: [PATCH] * --- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 218 +++++++++++++++++------------------------------------- 1 files changed, 70 insertions(+), 148 deletions(-) diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java index c5d84c1..a1d5b62 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java @@ -206,24 +206,23 @@ /** * 绔欑偣浠诲姟妫�娴� 涓嬪彂灏忚溅鍙栨斁浠诲姟 */ - public synchronized List<List<List<WrkMast>>> DevpTaskNoRun() { - List<List<List<WrkMast>>> wrkMastListAll = new ArrayList<>(); + public synchronized void DevpTaskNoRun() { try { List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", 1L).orderBy("modi_time", true)); if (wrkMasts.isEmpty()) { - return wrkMastListAll; + return; } long differenceInSeconds = TimeCalculatorUtils.differenceInMilliseconds(wrkMasts.get(0).getModiTime(), new Date()); if (differenceInSeconds <= 1000) { - return wrkMastListAll; + return; } BasCircularShuttle basCircularShuttle = basCircularShuttleService.selectOne(new EntityWrapper<BasCircularShuttle>().eq("rgv_id", 1)); RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, basCircularShuttle.getRgvNo()); RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); if (rgvProtocol == null) { - return wrkMastListAll; + return; } List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position", true)); List<BasDevpPosition> basDevpPositionDevRegion = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("dev_region", true)); @@ -232,15 +231,13 @@ BasDevpPosition[] basDevpPositionsListUN = SortTheExecutionOfTheCarUtil.devpNoSortUN(basDevpPositionsList); List<List<Integer>> siteListAll = SortTheExecutionOfTheCarUtil.siteListAll(basDevpPositionDevRegion); // List<List<WrkMast>> wrkMastLists = getWrkMastLists(basDevpPositionsListUN); - return getWrkMastListAll(siteListAll,basDevpPositionsListUN); + List<List<List<WrkMast>>> wrkMastListAll = getWrkMastListAll(siteListAll, basDevpPositionsListUN); //涓嬪彂浠诲姟 // taskDown(wrkMastLists); - + taskDown(wrkMastListAll); } catch (Exception e) { - log.error("鑷姩涓嬪彂灏忚溅鍙栨斁浠诲姟澶辫触锛屽紓甯革細" + e); + log.error("鑷姩涓嬪彂灏忚溅浠诲姟澶辫触锛屽紓甯革細" + e); } - return wrkMastListAll; - } @@ -330,140 +327,7 @@ } } -// public synchronized void taskDown(List<List<WrkMast>> wrkMastLists) { -// long rgvId = 0; -// runRgv: -// for (List<WrkMast> wrkMastList : wrkMastLists) { -// for (WrkMast wrkMast : wrkMastList) { -// while (rgvId <= rgvCount) { -// rgvId++; -//// log.info("瀛樺湪浠诲姟锛孯GV鍙�={}锛屼换鍔℃暟鎹�={}", rgvId, JSON.toJSON(wrkMast)); -// if (rgvId > rgvCount) { -// break runRgv; -// } -// BasCircularShuttle basCircularShuttle = basCircularShuttleService.selectOne(new EntityWrapper<BasCircularShuttle>().eq("rgv_id", rgvId)); -// if (basCircularShuttle.getStatus() != 0){ -// continue ; -// } -// RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, basCircularShuttle.getRgvNo()); -// RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); -// if (rgvProtocol == null) { -// continue; -// } -// -// List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("rgv_no", rgvProtocol.getRgvNo()).eq("wrk_sts", 2L)); -// if (!wrkMasts.isEmpty()) { -// continue; -// } -// if (rgvProtocol != null -// && rgvProtocol.modeType == RgvModeType.AUTO -// && (rgvProtocol.getStatusType() == RgvStatusType.IDLE || rgvProtocol.getStatusType() == RgvStatusType.ROAM) -// && rgvProtocol.getTaskNo1() == 0 -// && rgvProtocol.getAlarm() == 0) { -// if (rgvProtocol.getStatusType() == RgvStatusType.ROAM) { -// double finalVelocity = 0.0; // 鏈�缁堥�熷害 (m/s) -// double distance = (Math.pow(finalVelocity, 2) - Math.pow(rgvProtocol.instantaneousSpeed / 60, 2)) / (2 * acceleration); -// BasDevpPosition basDevpPosition = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("dev_no", wrkMast.getSourceStaNo())); -// if ((distance * proportion + (rgvProtocol.instantaneousSpeed / 60) * proportion * rgvDate) > (SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPosition.getPlcPosition(), rgvProtocol.getRgvPos(), perimeter) )) { -//// List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position", true)); -//// if (basDevpPositions.isEmpty()) { -//// log.error("鑾峰彇鎵�鏈夌珯鐐逛俊鎭紓甯�,RGV浠诲姟涓嬪彂澶辫触锛岃鑱旂郴绠$悊鍛橈紒锛侊紒"); -//// break runRgv; -//// } -//// List<Integer> devpList = SortTheExecutionOfTheCarUtil.BasDevpPositionExtractSites(basDevpPositions); -//// -//// if (!SortTheExecutionOfTheCarUtil.calculateShortestDistanceDirection(devpList,rgvProtocol.getEndStaM(),wrkMast.getSourceStaNo())){ -// continue; -//// } -// } -// } -// RgvCommand rgvCommand = new RgvCommand(); -// rgvCommand.setRgvNo(rgvProtocol.getRgvNo()); -// rgvCommand.setAckFinish1((short) 0); // 宸ヤ綅1浠诲姟瀹屾垚纭浣� -// rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); -// rgvCommand.setTaskMode1(RgvTaskModeType.FETCH_PUT); // 宸ヤ綅1浠诲姟妯″紡: 鍙栨斁璐� -// rgvCommand.setSourceStaNo1(wrkMast.getSourceStaNo().shortValue()); //宸ヤ綅1璧风偣 -// rgvCommand.setDestinationStaNo1(wrkMast.getStaNo().shortValue()); //宸ヤ綅1鐩爣绔欑偣 -// rgvCommand.setCommand((short) 1); //宸ヤ綅1浠诲姟纭 -// rgvCommand.setRgvSome(basCircularShuttle.getRgvSome()==1 ? (short) 1 : (short) 0); -// if (!MessageQueue.offer(SlaveType.Rgv, rgvProtocol.getRgvNo(), new Task(2, rgvCommand))) { -// // -// log.error("RGV鍛戒护涓嬪彂澶辫触锛孯GV鍙�={}锛屼换鍔℃暟鎹�={}", rgvId, JSON.toJSON(rgvCommand)); -// break runRgv; -// } -// log.info("RGV鍛戒护涓嬪彂鎴愬姛锛孯GV鍙�={}锛屼换鍔℃暟鎹�={}", rgvId, JSON.toJSON(rgvCommand)); -// -// wrkMast.setWrkSts(2L); -// wrkMast.setRgvNo(rgvProtocol.getRgvNo()); -// Date now = new Date(); -// wrkMast.setAppeTime(now); -// wrkMast.setCrnStrTime(now); -// try { -// wrkMastService.updateById(wrkMast); -// break; -// } catch (Exception e) { -// log.error("鏇存柊灏忚溅浠诲姟澶辫触,浠诲姟鍙凤細" + wrkMast.getWrkNo()); -// } -// break runRgv; -// } else if (rgvProtocol != null -// && rgvProtocol.modeType == RgvModeType.AUTO -// && rgvProtocol.getStatusType() == RgvStatusType.WALK -// && rgvProtocol.getTaskNo1() == 0 -// && rgvProtocol.getAlarm() == 0) { -// if (rgvProtocol.getStatusType() == RgvStatusType.WALK) { -// double finalVelocity = 0.0; // 鏈�缁堥�熷害 (m/s) -// double distance = (Math.pow(finalVelocity, 2) - Math.pow(rgvProtocol.instantaneousSpeed / 60, 2)) / (2 * acceleration); -// BasDevpPosition basDevpPosition = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("dev_no", wrkMast.getSourceStaNo())); -// if ((distance * proportion + (rgvProtocol.instantaneousSpeed / 60) * proportion * rgvDate) > (SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPosition.getPlcPosition(), rgvProtocol.getRgvPos(), perimeter) )) { -//// List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position", true)); -//// if (basDevpPositions.isEmpty()) { -//// log.error("鑾峰彇鎵�鏈夌珯鐐逛俊鎭紓甯�,RGV浠诲姟涓嬪彂澶辫触锛岃鑱旂郴绠$悊鍛橈紒锛侊紒"); -//// break runRgv; -//// } -//// List<Integer> devpList = SortTheExecutionOfTheCarUtil.BasDevpPositionExtractSites(basDevpPositions); -//// -//// if (!SortTheExecutionOfTheCarUtil.calculateShortestDistanceDirection(devpList,rgvProtocol.getEndStaM(),wrkMast.getSourceStaNo())){ -// continue; -//// } -// } -// } -// RgvCommand rgvCommand = new RgvCommand(); -// rgvCommand.setRgvNo(rgvProtocol.getRgvNo()); -// rgvCommand.setAckFinish1((short) 0); // 宸ヤ綅1浠诲姟瀹屾垚纭浣� -// rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); -// rgvCommand.setTaskMode1(RgvTaskModeType.X_MOVE); // 宸ヤ綅1浠诲姟妯″紡: 鍙栨斁璐� -// rgvCommand.setSourceStaNo1(wrkMast.getSourceStaNo().shortValue()); //宸ヤ綅1璧风偣 -// rgvCommand.setDestinationStaNo1(wrkMast.getStaNo().shortValue()); //宸ヤ綅1鐩爣绔欑偣 -// rgvCommand.setCommand((short) 1); //宸ヤ綅1浠诲姟纭 -// rgvCommand.setRgvSome(basCircularShuttle.getRgvSome()==1 ? (short) 1 : (short) 0); -// if (!MessageQueue.offer(SlaveType.Rgv, rgvProtocol.getRgvNo(), new Task(3, rgvCommand))) { -// // -// log.error("RGV鍛戒护涓嬪彂澶辫触锛孯GV鍙�={}锛屼换鍔℃暟鎹�={}", rgvId, JSON.toJSON(rgvCommand)); -// break runRgv; -// } -// log.info("RGV鍛戒护涓嬪彂鎴愬姛锛孯GV鍙�={}锛屼换鍔℃暟鎹�={}", rgvId, JSON.toJSON(rgvCommand)); -// -// wrkMast.setWrkSts(2L); -// wrkMast.setRgvNo(rgvProtocol.getRgvNo()); -// Date now = new Date(); -// wrkMast.setAppeTime(now); -// wrkMast.setCrnStrTime(now); -// try { -// wrkMastService.updateById(wrkMast); -// break; -// } catch (Exception e) { -// log.error("鏇存柊灏忚溅浠诲姟澶辫触,浠诲姟鍙凤細" + wrkMast.getWrkNo()); -// } -// break runRgv; -// } else { -// break runRgv; -// } -// } -// } -// } -// } public synchronized void taskDown(List<List<List<WrkMast>>> wrkMastListAll) { -//0灏忚溅杞﹀彿 1灏忚溅缂栧彿 List<Integer> rgvNoM = new ArrayList<>(); List<Integer> rgvNoR = new ArrayList<>(); int wrkMastRunCount = 0; @@ -602,7 +466,7 @@ } } catch (Exception e){ - log.error("RGV婕父鍚姩鍛戒护涓嬪彂澶辫触锛屼换鍔℃暟鎹�===> "+JSON.toJSON(wrkMastListAll)); + log.error("RGV鍙栨斁璐у惎鍔ㄥ懡浠や笅鍙戝け璐ワ紝浠诲姟鏁版嵁===> "+JSON.toJSON(wrkMastListAll)); return; } try{ @@ -639,8 +503,8 @@ //浠诲姟瀹屾垚 public synchronized void rgvCompleteWrkMastSta(int[] autoZ) { - try { - for (RgvSlave rgvSlave : slaveProperties.getRgv()) { + for (RgvSlave rgvSlave : slaveProperties.getRgv()) { + try { RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId()); RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); if (rgvProtocol == null) { @@ -713,9 +577,67 @@ } catch (Exception e){} wrkMastService.updateById(wrkMast); } + } catch (Exception e) { + log.error("灏忚溅澶嶄綅绾跨▼鎶ラ敊锛�" + e); } - } catch (Exception e) { - log.error("灏忚溅澶嶄綅绾跨▼鎶ラ敊锛�" + e); + } + } + public synchronized void rgvCancelWrkMastSta() { + for (RgvSlave rgvSlave : slaveProperties.getRgv()) { + try { + RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId()); + RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); + if (rgvProtocol == null) { + continue; + } + if (rgvProtocol.getStatusType() == RgvStatusType.CANCEL) { + log.info("{}鍙峰皬杞︾瓑寰厀cs鍙栨秷锛岀姸鎬亄}锛屽弬鏁皗}", rgvProtocol.getRgvNo(), rgvProtocol.getStatusType(), rgvProtocol); + } + // 鍙湁褰揜GV绛夊緟WCS纭銆佽嚜鍔� + if (rgvProtocol.getStatusType() == RgvStatusType.CANCEL + && rgvProtocol.getModeType() == RgvModeType.AUTO + && rgvProtocol.getTaskNo1() != 0 + ) { + WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", rgvProtocol.getTaskNo1().longValue())); + if (Cools.isEmpty(wrkMast) || !wrkMast.getWrkSts().equals(2L)) { + log.error("鏈煡鍒板皬杞︽墽琛屼换鍔℃垨鑰呮墽琛屼换鍔$姸鎬佷笉绗﹀悎锛�" + wrkMast); + continue; + } + + RgvCommand rgvCommand = new RgvCommand(); + rgvCommand.setRgvNo(rgvProtocol.getRgvNo()); + rgvCommand.setAckFinish1((short) 0); // 宸ヤ綅1浠诲姟瀹屾垚纭浣� + rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); + rgvCommand.setTaskMode1(RgvTaskModeType.CANCEL); // 宸ヤ綅1浠诲姟妯″紡: 鍙栨秷 + rgvCommand.setSourceStaNo1((short)-1); //宸ヤ綅1璧风偣 + rgvCommand.setDestinationStaNo1((short)-1); //宸ヤ綅1鐩爣绔欑偣 + rgvCommand.setCommand((short) 1); //宸ヤ綅1浠诲姟纭 + rgvCommand.setRgvSome((short) 1); + if (!MessageQueue.offer(SlaveType.Rgv, rgvProtocol.getRgvNo(), new Task(2, rgvCommand))) { + // + log.error("RGV鍙栨秷鍛戒护涓嬪彂澶辫触锛孯GV鍙�={}锛屼换鍔℃暟鎹�={}", rgvProtocol.getRgvNo(), JSON.toJSON(rgvCommand)); + wrkMast.setLogErrTime(new Date()); + wrkMast.setLogErrMemo("RGV鍙栨秷鍛戒护涓嬪彂澶辫触锛孯GV鍙�={"+rgvProtocol.getRgvNo()+"}===>璺宠繃"); + wrkMastService.updateById(wrkMast); + continue; + } + log.info("RGV鍙栨秷鍛戒护涓嬪彂鎴愬姛锛孯GV鍙�={}锛屼换鍔℃暟鎹�={}", rgvProtocol.getRgvNo(), JSON.toJSON(rgvCommand)); + + + Date now = new Date(); + wrkMast.setWrkSts(1L); + wrkMast.setAppeTime(now); + wrkMast.setLogErrTime(now); + wrkMast.setRgvNo(null); + + wrkMast.setLogErrMemo("RGV鐢宠鍙栨秷浠诲姟锛孯GV鍙�={"+rgvProtocol.getRgvNo()+"}锛屽彇娑堟椂闂达細"+now); + + wrkMastService.updateById(wrkMast); + + } + } catch (Exception e) { + log.error("灏忚溅鍙栨秷绾跨▼鎶ラ敊锛�" + e); + } } } -- Gitblit v1.9.1