From 69e1880e5486ebc62da4806642ca817afda9c84c Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期四, 05 十月 2023 14:09:45 +0800 Subject: [PATCH] # --- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 416 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 340 insertions(+), 76 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 f3475c9..4563418 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java @@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.mapper.Wrapper; import com.core.common.Cools; import com.core.exception.CoolException; import com.zy.asrs.entity.*; @@ -224,7 +225,7 @@ param.setBarcode(barcode); param.setIoType(1); param.setSourceStaNo(inSta.getStaNo()); -// param.setLocType1(locTypeDto.getLocType1()); + param.setLocType1(locTypeDto.getLocType1()); String response = new HttpHandler.Builder() .setUri(wmsUrl) .setPath("/rpc/pakin/loc/v1") @@ -238,14 +239,14 @@ StartupDto dto = jsonObject.getObject("data", StartupDto.class); // plc 澶勭悊 barcodeThread.setBarcode(""); - staProtocol.setWorkNo(dto.getWorkNo().shortValue()); - staProtocol.setStaNo(dto.getStaNo().shortValue()); - devpThread.setPakMk(staProtocol.getSiteId(), false); - - boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); - if (!result) { - throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触"); - } +// staProtocol.setWorkNo(dto.getWorkNo().shortValue()); +// staProtocol.setStaNo(dto.getStaNo().shortValue()); +// devpThread.setPakMk(staProtocol.getSiteId(), false); +// +// boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); +// if (!result) { +// throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触"); +// } // 鍒ゆ柇閲嶅宸ヤ綔妗� WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo()); @@ -267,10 +268,10 @@ } News.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response); } else if (code == 700) { - staProtocol.setWorkNo((short) 32002); - staProtocol.setRollback102(1);//102绔欏洖閫�淇″彿 - devpThread.setPakMk(staProtocol.getSiteId(), false); - MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol)); +// staProtocol.setWorkNo((short) 32002); +// staProtocol.setRollback102(1);//102绔欏洖閫�淇″彿 +// devpThread.setPakMk(staProtocol.getSiteId(), false); +// MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol)); // led 寮傚父鏄剧ず if (ledThread != null) { @@ -405,8 +406,8 @@ } if (staProtocol.isAutoing() && staProtocol.isLoading() - && (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9999) - && staProtocol.getStaNo().equals(staProtocol.getSiteId().shortValue()) +// && (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9999) +// && staProtocol.getStaNo().equals(staProtocol.getSiteId().shortValue()) && staProtocol.isPakMk()){ // 鑾峰彇鏉$爜鎵弿浠俊鎭� @@ -507,12 +508,18 @@ } String sourceLocNo = wrkMast.getSourceLocNo().trim(); + LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(sourceLocNo));//鑾峰彇鍥炲簱鎻愬崌鏈虹洰鏍囩珯 + if (liftStaProtocol == null) { + continue; + } + // 鏇存柊宸ヤ綔妗f暟鎹姸鎬� wrkMast.setIoType(wrkMast.getIoType() - 50); // 鍏ュ嚭搴撶被鍨�: 103->53,104->54,107->57 wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵��: 2.璁惧涓婅蛋 wrkMast.setSourceStaNo(pickSta.getStaNo()); // 婧愮珯 - wrkMast.setStaNo(dto.getStaNo()); // 鐩爣绔� - wrkMast.setCrnNo(dto.getCrnNo()); +// wrkMast.setStaNo(dto.getStaNo()); // 鐩爣绔� +// wrkMast.setCrnNo(dto.getCrnNo()); + wrkMast.setStaNo(liftStaProtocol.getStaNo());//鐩爣绔� wrkMast.setLocNo(sourceLocNo); // 鐩爣搴撲綅 = 鍑哄簱鏃剁殑婧愬簱浣� wrkMast.setShuttleNo(null); // 绌挎杞︽竻绌� wrkMast.setModiTime(new Date()); @@ -531,14 +538,16 @@ throw new CoolException("淇敼搴撲綅鐘舵�佸け璐�"); } - // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护 - staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue()); - staProtocol.setStaNo(wrkMast.getStaNo().shortValue()); - devpThread.setPakMk(staProtocol.getSiteId(), false); - boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); - if (!result) { - News.error("鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId()); - } +// // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护 +// staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue()); +// staProtocol.setStaNo(wrkMast.getStaNo().shortValue()); +// devpThread.setPakMk(staProtocol.getSiteId(), false); +// boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); +// if (!result) { +// News.error("鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId()); +// } + + barcodeThread.setBarcode("");//娓呯悊鏉$爜 } else if (code == 500){ if (ledThread != null) { @@ -549,10 +558,10 @@ } News.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response); } else { - staProtocol.setWorkNo((short) 32002); - staProtocol.setStaNo(pickSta.getBackSta().shortValue()); - devpThread.setPakMk(staProtocol.getSiteId(), false); - MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); +// staProtocol.setWorkNo((short) 32002); +// staProtocol.setStaNo(pickSta.getBackSta().shortValue()); +// devpThread.setPakMk(staProtocol.getSiteId(), false); +// MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); // led 寮傚父鏄剧ず if (ledThread != null) { @@ -794,6 +803,12 @@ return false;//灏忚溅宸茶鐙崰锛岀姝㈠啀娲惧彂浠诲姟 } + //鍒ゆ柇灏忚溅鏄惁瀛樺湪绉诲姩浠诲姟 + WrkMast hasMoveWorking = wrkMastMapper.selectShuttleHasMoveWorking(wrkMast.getShuttleNo()); + if (hasMoveWorking != null) { + return false;//瀛樺湪绉诲姩浠诲姟锛岀姝㈡墽琛屽叆搴撲换鍔� + } + //鍒ゆ柇灏忚溅鏄惁鍒拌揪杈撻�佺珯鐐瑰簱浣� if (!shuttleProtocol.getCurrentLocNo().equals(liftStaProtocol.getLocNo())) { //灏忚溅涓嶅湪杈撻�佺珯鐐逛綅缃� @@ -873,7 +888,7 @@ return false;//鎵句笉鍒扮珯鐐� } - if (liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && !liftStaProtocol.getHasTray()) { + if (!(liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && !liftStaProtocol.getHasTray())) { return false;//绔欑偣蹇呴』鑷姩銆佺┖闂层�佹病鏈夋墭鐩� } @@ -946,6 +961,8 @@ } //鍥涘悜绌挎杞︾姸鎬佷负绛夊緟纭銆佸皬杞﹀浜庣┖闂茬姸鎬� + + if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.WAITING.id //浠诲姟瀹屾垚绛夊緟纭 && shuttleProtocol.getTaskNo() != 0 && shuttleProtocol.getFree() == ShuttleStatusType.IDLE.id @@ -956,14 +973,16 @@ switch (wrkMast.getWrkSts().intValue()) { case 5://5.灏忚溅鎼繍涓� ==> 9.鍏ュ簱瀹屾垚 wrkMast.setWrkSts(9L); - if (shuttleProtocol.getToken() == wrkMast.getWrkNo()) { + shuttleProtocol.setTaskNo(0); + if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) { //閲婃斁灏忚溅浠ょ墝 shuttleProtocol.setToken(0); } break; case 22://22.灏忚溅鎼繍涓� ==> 23.灏忚溅鎼繍瀹屾垚 wrkMast.setWrkSts(23L); - if (shuttleProtocol.getToken() == wrkMast.getWrkNo()) { + shuttleProtocol.setTaskNo(0); + if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) { //閲婃斁灏忚溅浠ょ墝 shuttleProtocol.setToken(0); } @@ -973,6 +992,7 @@ break; case 104://104.灏忚溅杩佸叆鎻愬崌鏈轰腑 ==> 105.灏忚溅杩佸叆鎻愬崌鏈哄畬鎴� wrkMast.setWrkSts(105L); + shuttleProtocol.setTaskNo(0);//娓呯悊宸ヤ綔鍙� break; case 108://108.灏忚溅杩佸嚭鎻愬崌鏈轰腑 ==> 109.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴� wrkMast.setWrkSts(109L); @@ -980,7 +1000,7 @@ case 110://110.灏忚溅绉诲姩涓� ==> 111.灏忚溅绉诲姩瀹屾垚 wrkMast.setWrkSts(111L); shuttleProtocol.setTaskNo(0); - if (shuttleProtocol.getToken() == wrkMast.getWrkNo()) { + if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) { //閲婃斁灏忚溅浠ょ墝 shuttleProtocol.setToken(0); } @@ -1156,6 +1176,12 @@ //鑾峰彇鎻愬崌鏈哄懡浠� NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, startSta, targetSta, wrkMast.getWrkNo()); + if (wrkMast.getIoType() == 53) { + //鎷f枡鍐嶅洖搴擄紝閲嶆柊鍒嗛厤璁惧宸ヤ綔鍙� + Random random = new Random(); + int deviceWrk = Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999)));//鑾峰彇璁惧宸ヤ綔鍙� + liftCommand.setTaskNo((short) deviceWrk); + } ArrayList<NyLiftCommand> commands = new ArrayList<>(); commands.add(liftCommand); @@ -1191,6 +1217,17 @@ //23.灏忚溅鎼繍瀹屾垚 ==> 24.鎻愬崌鏈烘惉杩愪腑 if (wrkMast.getWrkSts() == 23) { + NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); + if (shuttleThread == null) { + return false; + } + + //璋冨害灏忚溅閬胯 + boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getShuttleNo(), shuttleThread); + if (!result) { + return false; + } + //鑾峰彇鍑哄簱绔欑偣(鐩爣绔�) BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo()); if (basDevp == null) { @@ -1281,7 +1318,6 @@ && liftProtocol.getTaskNo() != 0 && !liftProtocol.getBusy() ) { - //灏嗕换鍔℃。鏍囪涓哄畬鎴� WrkMast wrkMast = wrkMastMapper.selectByWorkNo324104(liftProtocol.getTaskNo().intValue()); if (wrkMast != null) { @@ -1289,7 +1325,7 @@ case 3://3.鎻愬崌鏈烘惉杩愪腑 ==> 4.鎻愬崌鏈烘惉杩愬畬鎴� wrkMast.setWrkSts(4L); wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈� - if (liftProtocol.getToken() == wrkMast.getWrkNo()) { + if (liftProtocol.getToken().equals(wrkMast.getWrkNo())) { //閲婃斁鎻愬崌鏈轰护鐗� liftProtocol.setToken(0); } @@ -1299,10 +1335,16 @@ if (wrkMast.getIoType() == 11) {//搴撲綅绉昏浆 wrkMast.setWrkSts(4L);//4.鎻愬崌鏈烘惉杩愬畬鎴� } - if (liftProtocol.getToken() == wrkMast.getWrkNo()) { + if (liftProtocol.getToken().equals(wrkMast.getWrkNo())) { //閲婃斁鎻愬崌鏈轰护鐗� liftProtocol.setToken(0); } + + if (wrkMast.getMk() == null || !wrkMast.getMk().equals("Y")) { + //涓嶉渶瑕佺敤鍒版満姊拌噦锛岀洿鎺ヨ浆29.鍑哄簱瀹屾垚 + wrkMast.setWrkSts(29L); + } + break; case 106://106.鎻愬崌鏈烘惉杩愪腑 ==> 107.鎻愬崌鏈烘惉杩愬畬鎴� wrkMast.setWrkSts(107L); @@ -1319,8 +1361,19 @@ } else { News.error("鎻愬崌鏈哄凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅澶辫触锛屼絾鏈壘鍒板伐浣滄。銆傛彁鍗囨満鍙�={}锛屽伐浣滃彿={}", liftProtocol.getLiftNo(), liftProtocol.getTaskNo()); } + }else { + LiftAssignCommand assignCommand = liftProtocol.getAssignCommand(); + if (assignCommand != null) { + if (!assignCommand.getAuto()) { + //鎵嬪姩鎿嶄綔 + //璁剧疆鎻愬崌鏈轰负绌洪棽鐘舵�� + liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE); + //浠诲姟鎸囦护娓呴浂 + liftProtocol.setAssignCommand(null); + News.info("鎻愬崌鏈哄凡纭鎵嬪姩鎿嶄綔銆傛彁鍗囨満鍙�={}", liftProtocol.getLiftNo()); + } + } } - } } } @@ -1878,6 +1931,13 @@ } } + if (!Cools.isEmpty(barcode)) { + WrkMast wrkMast = wrkMastMapper.selectByBarcode(barcode);//鏉$爜瀛樺湪宸ヤ綔妗� + if (wrkMast != null) { + continue; + } + } + LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, emptyInSta.getLed()); try { @@ -1900,15 +1960,15 @@ Integer code = jsonObject.getInteger("code"); if (code.equals(200)) { StartupDto dto = jsonObject.getObject("data", StartupDto.class); - - // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护 - staProtocol.setWorkNo(dto.getWorkNo().shortValue()); - staProtocol.setStaNo(dto.getStaNo().shortValue()); - devpThread.setPakMk(staProtocol.getSiteId(), false); - boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); - if (!result) { - throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触"); - } + barcodeThread.setBarcode(""); +// // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护 +// staProtocol.setWorkNo(dto.getWorkNo().shortValue()); +// staProtocol.setStaNo(dto.getStaNo().shortValue()); +// devpThread.setPakMk(staProtocol.getSiteId(), false); +// boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); +// if (!result) { +// throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触"); +// } } else { if (ledThread != null) { String errorMsg = jsonObject.getString("msg"); @@ -1926,6 +1986,97 @@ } + } + } + } + + /** + * AGV琛ヨ揣 => 鏈烘鑷傛嫞鏂� + */ + public void agvRestockByRobot() { + //妫�娴�300绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗┿�佸伐浣滃彿 + for (DevpSlave devp : slaveProperties.getDevp()) { + // 鑾峰彇鍏ュ簱绔欎俊鎭� + DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); + StaProtocol staProtocol = devpThread.getStation().get(300); + if (staProtocol == null) { + continue; + } + if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() != 0) { + //鏌ヨ鏄惁鏈夊伐浣滄。 + WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue()); + if (wrkMast == null) { + continue; + } + + if (wrkMast.getWrkSts() != 25) {//25.鎻愬崌鏈烘惉杩愬畬鎴� + continue; + } + + if (wrkMast.getMk() != null && wrkMast.getMk().equals("Y")) {//鏍囪涓篩琛ㄧず闇�瑕佺敤鍒版満姊拌噦鎷f枡 + Short targetSta = null;//鐩爣绔� + //鍒ゆ柇鏈烘鑷傛嫞鏂欑珯鏄惁绌洪棽 + StaProtocol staProtocol303 = devpThread.getStation().get(303); + StaProtocol staProtocol317 = devpThread.getStation().get(317); + if (staProtocol303.isAutoing() && !staProtocol303.isLoading()) { + //鑷姩銆佹棤鐗� + targetSta = (short) 303; + } else if (staProtocol317.isAutoing() && !staProtocol317.isLoading()) { + //鑷姩銆佹棤鐗� + targetSta = (short) 317; + }else { + continue;//娌℃湁绌洪棽绔欑偣 + } + + targetSta = (short) 317; + + if (wrkMast.getStaNo() != 303 && wrkMast.getStaNo() != 317) { + //瑕嗙洊宸ヤ綔妗g洰鏍囩珯 + wrkMast.setStaNo(targetSta.intValue()); + if (wrkMastMapper.updateById(wrkMast) > 0) { + //鍚�300绔欏啓鍏ョ洰鏍囩珯 + staProtocol = staProtocol.clone(); + staProtocol.setStaNo(targetSta);//绉诲姩鍒扮洰鏍囩珯 + boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); + try { + Thread.sleep(500); + } catch (Exception e) { + e.printStackTrace(); + } + continue; + } + } + } + } + + StaProtocol staProtocol303 = devpThread.getStation().get(303); + StaProtocol staProtocol317 = devpThread.getStation().get(317); + if (staProtocol303.isAutoing() && staProtocol303.isLoading() && staProtocol303.getWorkNo() != 0) { + //璋冨害鏈烘鑷� +// //鏌ヨ鏄惁鏈夊伐浣滄。 +// WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol303.getWorkNo().intValue()); +// if (wrkMast == null) { +// continue; +// } +// WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo()); +// if (wrkDetl == null) { +// continue; +// } +// RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "303"); + RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), -1, "303"); + }else if (staProtocol317.isAutoing() && staProtocol317.isLoading() && staProtocol317.getWorkNo() != 0) { + //璋冨害鏈烘鑷� +// //鏌ヨ鏄惁鏈夊伐浣滄。 +// WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol317.getWorkNo().intValue()); +// if (wrkMast == null) { +// continue; +// } +// WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo()); +// if (wrkDetl == null) { +// continue; +// } +// RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "317"); + RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), -1, "317"); } } } @@ -2116,11 +2267,39 @@ continue; } + //灏忚溅鎵�鍦ㄦゼ灞� + int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo()); ShuttleChargeType shuttleCharge = null; + + //鎼滅储灏忚溅鎵�鍦ㄦゼ灞傛湁娌℃湁鍏呯數妗� for (ShuttleChargeType chargeType : ShuttleChargeType.values()) { + if (lev != Utils.getLev(chargeType.locNo)) { + continue;//灏忚溅鍜屽厖鐢垫々涓嶅湪鍚屼竴灞� + } + + //灏忚溅鍜屽厖鐢垫々鍦ㄥ悓涓�灞� if (wrkChargeService.selectWorkingOfCharge(chargeType.id) == null) { shuttleCharge = chargeType; break; + } + } + + if (shuttleCharge == null) { + //鍚屾ゼ灞傛病鏈夋壘鍒板厖鐢垫々锛屾壘鍙敤鍏呯數妗� + //灏忚溅鍚屾ゼ灞傛病鏈夊厖鐢垫々锛屽彧瑕佸厖鐢垫々鍙敤灏辩敓鎴愬厖鐢典换鍔� + for (ShuttleChargeType chargeType : ShuttleChargeType.values()) { + if (wrkChargeService.selectWorkingOfCharge(chargeType.id) == null) { + //鍒ゆ柇褰撳墠鍏呯數妗╂ゼ灞傛槸鍚︽湁灏忚溅锛屽鏈夊皬杞︼紝涓嶅垎閰嶈鍏呯數妗� + int chargeLev = Utils.getLev(chargeType.locNo);//鍏呯數妗╂ゼ灞� + boolean checkLevHasShuttle = Utils.checkLevHasShuttle(chargeLev);//妫�娴嬫ゼ灞傛槸鍚︽湁绌挎杞� + if (checkLevHasShuttle) { + //褰撳墠鍏呯數妗╂ゼ灞傛湁绌挎杞︼紝涓嶅垎閰嶈鍏呯數妗� + continue; + } + + shuttleCharge = chargeType; + break; + } } } @@ -2143,7 +2322,6 @@ continue; } - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING);//鍏呯數涓� News.info("淇濆瓨{}鍙峰洓鍚戠┛姊溅鍏呯數浠诲姟鎴愬姛!!!", shuttle.getId()); } } @@ -2198,7 +2376,8 @@ } } else if (wrkCharge.getWrkSts() == 52) { //妫�娴嬪皬杞︽槸鍚︽弧鐢� - if (shuttleProtocol.getPowerPercent() < 100) { + int maxPower = 95; + if (shuttleProtocol.getPowerPercent() < maxPower) { continue; } @@ -2214,21 +2393,34 @@ assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣�(灏忚溅褰撳墠浣嶇疆) assignCommand.setCommands(commands);//杩愯鍛戒护 + //涓嬪彂浠诲姟 + MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); + try { + Thread.sleep(3000); + } catch (Exception e) { + e.printStackTrace(); + } + wrkCharge.setWrkSts(53L);//52.灏忚溅鍘诲厖鐢典腑 => 53.灏忚溅鍏呯數瀹屾垚 wrkCharge.setModiTime(new Date()); if (wrkChargeMapper.updateById(wrkCharge) > 0) { - //涓嬪彂浠诲姟 - MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); + shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE.id); + shuttleProtocol.setTaskNo(0); + shuttleProtocol.setPakMk(false); } } else if (wrkCharge.getWrkSts() == 53) { - boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkCharge.getLocNo()), shuttleThread.getSlave().getId(), shuttleThread); - if (!result) { - continue; - } + if (shuttleProtocol.getChargState() == 0) {//灏忚溅澶勪簬鏈厖鐢电姸鎬� + boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkCharge.getLocNo()), shuttleThread.getSlave().getId(), shuttleThread); + if (!result) { + continue; + } - wrkCharge.setWrkSts(60L);//53.灏忚溅鍏呯數瀹屾垚 => 60.鍏呯數浠诲姟瀹屾垚 - wrkCharge.setModiTime(new Date()); - wrkChargeMapper.updateById(wrkCharge); + wrkCharge.setWrkSts(60L);//53.灏忚溅鍏呯數瀹屾垚 => 60.鍏呯數浠诲姟瀹屾垚 + wrkCharge.setModiTime(new Date()); + if (wrkChargeMapper.updateById(wrkCharge) > 0) { + + } + } } } @@ -2321,8 +2513,14 @@ return false;//鎵句笉鍒扮珯鐐� } + //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟(璇ヤ换鍔¢渶瑕佹崲灞傚繀椤绘彁鍓嶇嫭鍗犳彁鍗囨満) + WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftSta.getLiftNo()); + if (liftWrkMast != null) { + return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇� + } + //鑾峰彇灏忚溅鍒拌緭閫佺珯鐐硅璧板懡浠� - NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo()); + NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.NORMAL.id); List<NyShuttleHttpCommand> commands = result.getCommands(); ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); @@ -2335,6 +2533,7 @@ wrkMast.setWrkSts(102L);//灏忚溅绉诲姩鍒版彁鍗囨満涓� 101.鐢熸垚灏忚溅绉诲簱浠诲姟 ==> 102.灏忚溅绉诲姩鑷崇珯鐐� wrkMast.setModiTime(now); + wrkMast.setLiftNo(liftSta.getLiftNo());//鎻愬墠閿佸畾鎻愬崌鏈� shuttleProtocol.setToken(wrkMast.getWrkNo());//鐙崰璇ュ皬杞︿护鐗� if (wrkMastMapper.updateById(wrkMast) > 0) { //涓嬪彂浠诲姟 @@ -2382,7 +2581,9 @@ //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟 WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(basLift.getLiftNo()); if (liftWrkMast != null) { - return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇� + if (!liftWrkMast.getWrkNo().equals(wrkMast.getWrkNo())) {//鎻愬崌鏈轰换鍔″拰褰撳墠浠诲姟涓嶇浉鍚� + return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇� + } } LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSta.getLiftNo()); @@ -2394,7 +2595,7 @@ return false; } - if (!liftProtocol.isIdle()) { + if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) { return false; } @@ -2409,7 +2610,12 @@ } //灏忚溅澶勪簬绌洪棽鐘舵�� - if (!shuttleProtocol.isIdleNoCharge()) { + if (!shuttleProtocol.isIdleNoCharge(wrkMast.getWrkNo())) { + return false; + } + + //灏忚溅浠ょ墝鏄惁琚换鍔$嫭鍗� + if (!shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) { return false; } @@ -2425,6 +2631,10 @@ //鑾峰彇鎻愬崌鏈哄懡浠わ紝璋冨害鎻愬崌鏈哄埌婧愮珯浣嶇疆 NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceLiftSta.getStaNo(), sourceLiftSta.getStaNo(), wrkMast.getWrkNo()); + Random random = new Random(); + int deviceWrk = Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999)));//鑾峰彇璁惧宸ヤ綔鍙� + liftCommand.setTaskNo((short) deviceWrk);//鏇存崲闅忔満浠诲姟鍙� + ArrayList<NyLiftCommand> commands = new ArrayList<>(); commands.add(liftCommand); @@ -2434,6 +2644,7 @@ assignCommand.setLiftNo(liftProtocol.getLiftNo()); assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_CAR.id.shortValue()); + assignCommand.setAuto(false); wrkMast.setLiftNo(liftThread.getSlave().getId());//閿佸畾鎻愬崌鏈洪槻姝㈣鍗犵敤 wrkMast.setModiTime(now); @@ -2445,13 +2656,19 @@ return false;//绛夊緟鎻愬崌鏈哄埌灏忚溅妤煎眰 } + if (liftProtocol.getToken() == 0) {//鎻愬崌鏈轰护鐗屾湭琚崰鐢� + //鐙崰鎻愬崌鏈� + liftProtocol.setToken(wrkMast.getShuttleNo()); + return false;//绛夊緟涓嬩竴娆℃墽琛� + } + //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚︿负褰撳墠灏忚溅 - if (liftProtocol.getToken() != wrkMast.getShuttleNo()) { + if (!liftProtocol.getToken().equals(wrkMast.getShuttleNo())) { return false;//鎻愬崌鏈哄凡琚嫭鍗狅紝绂佹鍐嶆淳鍙戜换鍔� } //鍒ゆ柇灏忚溅鏄惁涓哄綋鍓嶄换鍔$嫭鍗� - if (shuttleProtocol.getToken() != wrkMast.getWrkNo()) { + if (!shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) { return false; } @@ -2460,7 +2677,7 @@ //鎻愬崌鏈鸿妭鐐� NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY()); - liftNode.setZ(basLift.getPoint$().getZ()); + liftNode.setZ(staNode.getZ()); //鑾峰彇灏忚溅杩涙彁鍗囨満琛岃蛋鍛戒护 NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), staNode, liftNode, true); @@ -2516,8 +2733,16 @@ if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) { return false; } + //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟 + WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId()); + if (liftWrkMast != null) { + if (!liftWrkMast.getWrkNo().equals(wrkMast.getWrkNo())) {//鎻愬崌鏈轰换鍔″拰褰撳墠浠诲姟涓嶇浉鍚� + return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇� + } + } + //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚︿负褰撳墠灏忚溅 - if (liftProtocol.getToken() != wrkMast.getShuttleNo()) { + if (!liftProtocol.getToken().equals(wrkMast.getShuttleNo())) { return false;//鎻愬崌鏈轰护鐗屽拰褰撳墠灏忚溅涓嶄竴鑷达紝绂佹娲惧彂 } @@ -2542,7 +2767,7 @@ } //鍒ゆ柇灏忚溅鏄惁涓哄綋鍓嶄换鍔$嫭鍗� - if (shuttleProtocol.getToken() != wrkMast.getWrkNo()) { + if (!shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) { return false; } @@ -2602,8 +2827,16 @@ return false; } + //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟 + WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId()); + if (liftWrkMast != null) { + if (!liftWrkMast.getWrkNo().equals(wrkMast.getWrkNo())) {//鎻愬崌鏈轰换鍔″拰褰撳墠浠诲姟涓嶇浉鍚� + return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇� + } + } + //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚︿负褰撳墠灏忚溅 - if (liftProtocol.getToken() != wrkMast.getShuttleNo()) { + if (!liftProtocol.getToken().equals(wrkMast.getShuttleNo())) { return false;//鎻愬崌鏈轰护鐗屽拰褰撳墠灏忚溅涓嶄竴鑷达紝绂佹娲惧彂 } @@ -2623,7 +2856,7 @@ } //鍒ゆ柇灏忚溅鏄惁涓哄綋鍓嶄换鍔$嫭鍗� - if (shuttleProtocol.getToken() != wrkMast.getWrkNo()) { + if (!shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) { return false; } @@ -2642,9 +2875,13 @@ return false;//娌℃湁璁剧疆鎻愬崌鏈虹偣浣嶅潗鏍� } NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY()); - liftNode.setZ(basLift.getPoint$().getZ()); + liftNode.setZ(liftSta.getLev()); List<NyShuttleHttpCommand> commands = new ArrayList<>(); + //鑾峰彇灏忚溅鏇存柊妤煎眰鍛戒护 + NyShuttleHttpCommand updateZCommand = NyHttpUtils.getUpdateZCommand(shuttleThread.getSlave().getId(), liftProtocol.getLev().intValue(), wrkMast.getWrkNo()); + commands.add(updateZCommand); + //鑾峰彇灏忚溅鍑烘彁鍗囨満琛岃蛋鍛戒护 NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), liftNode, NavigatePositionConvert.locNoToNode(liftSta.getLocNo()), false); commands.add(moveCommand);//娣诲姞灏忚溅杩佸嚭鎻愬崌鏈哄懡浠� @@ -2697,7 +2934,7 @@ } //鍒ゆ柇灏忚溅浠ょ墝鏄惁涓哄綋鍓嶄换鍔� - if (shuttleProtocol.getToken() != 0 && shuttleProtocol.getToken() != wrkMast.getWrkNo()) { + if (shuttleProtocol.getToken() != 0 && !shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) { return false; } @@ -2718,8 +2955,32 @@ // NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY()); // liftNode.setZ(basLift.getPoint$().getZ()); + //灏忚溅宸茬粡鍦ㄧ洰鏍囧簱浣嶏紝鐩存帴璁ゅ畾灏忚溅绉诲姩浠诲姟瀹屾垚 + if (shuttleProtocol.getCurrentLocNo().equals(wrkMast.getLocNo())) { + if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) { + //閲婃斁灏忚溅浠ょ墝 + shuttleProtocol.setToken(0); + } + wrkMast.setWrkSts(111L);//111.灏忚溅绉诲姩瀹屾垚 + wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈� + wrkMast.setModiTime(now); + wrkMastMapper.updateById(wrkMast); + + if (wrkMast.getWrkSts() == 111) { + // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗� + if (wrkMastLocMapper.save(wrkMast.getWrkNo()) <= 0) { + log.info("淇濆瓨宸ヤ綔鍘嗗彶妗workNo={0}]澶辫触", wrkMast.getWrkNo()); + } + // 鍒犻櫎宸ヤ綔涓绘。 + if (!wrkMastService.deleteById(wrkMast)) { + log.info("鍒犻櫎宸ヤ綔涓绘。[workNo={0}]澶辫触", wrkMast.getWrkNo()); + } + } + return false; + } + //鑾峰彇灏忚溅鍒扮洰鏍囧簱浣嶅懡浠� - NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo()); + NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.NORMAL.id); if (result == null) { return false;//璺緞璁$畻澶辫触 } @@ -2732,10 +2993,8 @@ assignCommand.setAuto(true);//鑷姩妯″紡 assignCommand.setCommands(commands); assignCommand.setNodes(result.getNodes()); - - wrkMast.setWrkSts(110L);//灏忚溅绉诲姩鍒扮洰鏍囧簱浣嶄腑 109.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴� ==> 110.灏忚溅绉诲姩涓� - wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈� - wrkMast.setModiTime(now); + assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣� + assignCommand.setLocNo(wrkMast.getLocNo());//鐩爣搴撲綅 if (wrkMast.getLiftNo() != null) { LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo()); @@ -2746,10 +3005,15 @@ if (liftProtocol == null) { return false; } - if (liftProtocol.getToken() == shuttleProtocol.getShuttleNo().intValue()) { + if (liftProtocol.getToken().equals(shuttleProtocol.getShuttleNo().intValue())) { liftProtocol.setToken(0);//閲婃斁鎻愬崌鏈轰护鐗� } } + + wrkMast.setWrkSts(110L);//灏忚溅绉诲姩鍒扮洰鏍囧簱浣嶄腑 109.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴� ==> 110.灏忚溅绉诲姩涓� + wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈� + wrkMast.setModiTime(now); + if (wrkMastMapper.updateById(wrkMast) > 0) { //涓嬪彂浠诲姟 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); -- Gitblit v1.9.1