From 3ceabb21c1fd2b7fbdbc5c77c23f26152ec7f9aa Mon Sep 17 00:00:00 2001 From: 1 <1@123> Date: 星期五, 09 五月 2025 18:57:25 +0800 Subject: [PATCH] # --- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 193 +++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 159 insertions(+), 34 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 d0fc70b..7918153 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java @@ -12,24 +12,22 @@ import com.zy.asrs.entity.*; import com.zy.asrs.mapper.*; import com.zy.asrs.service.*; -import com.zy.asrs.utils.CommandUtils; -import com.zy.asrs.utils.RouteUtils; -import com.zy.asrs.utils.TrackRangeUtils; -import com.zy.asrs.utils.Utils; +import com.zy.asrs.utils.*; +import com.zy.common.model.MatDto; import com.zy.common.service.CommonService; +import com.zy.common.utils.CollectionUtils; import com.zy.common.utils.HttpHandler; import com.zy.core.CrnThread; import com.zy.core.DevpThread; import com.zy.core.cache.*; import com.zy.core.enums.*; -import com.zy.core.model.CrnSlave; -import com.zy.core.model.DevpSlave; -import com.zy.core.model.RgvSlave; -import com.zy.core.model.Task; +import com.zy.core.model.*; import com.zy.core.model.command.CrnCommand; +import com.zy.core.model.command.LedCommand; import com.zy.core.model.protocol.*; import com.zy.core.properties.SlaveProperties; import com.zy.core.thread.BarcodeThread; +import com.zy.core.thread.LedThread; import com.zy.core.thread.RgvThread; import com.zy.core.thread.SiemensDevpThread; import lombok.extern.slf4j.Slf4j; @@ -42,6 +40,7 @@ import java.io.IOException; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; /** * 绔嬩綋浠撳簱WCS绯荤粺涓绘祦绋嬩笟鍔� @@ -192,7 +191,7 @@ String barcode = barcodeThread.getBarcode(); if (!Cools.isEmpty(barcode) && !barcode.equals("99999999")) { // 璇锋眰wms鎺ュ彛锛岃幏鍙栧伐浣滃彿鍜岀洰鏍囧簱浣� - ToWmsDTO toWmsDTO = new ToWmsDTO(barcode, staProtocol.getSiteId(), 0); + ToWmsDTO toWmsDTO = new ToWmsDTO(staProtocol.getSiteId(),staProtocol.getGrossWt(),barcode, 0); TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode)); if (!Cools.isEmpty(taskWrk1)) { log.info("鎵樼洏鐮侊細" + barcode + "浠诲姟妗e瓨鍦�"); @@ -463,7 +462,8 @@ // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢 if (staProtocol.isAutoing() && staProtocol.isLoading() - && staProtocol.isInEnable() && (workNo == 0 || (workNo>9000 && workNo<10000)) +// && staProtocol.isInEnable() + && (workNo == 0 || (workNo>9000 && workNo<10000)) && staProtocol.isPakMkWalk() ) { if (inSta.isBarcodeSign()){ @@ -508,6 +508,7 @@ } else { staProtocol.setWorkNo(taskWrk1.getWrkNo()); staProtocol.setStaNo(staDesc.getCrnStn()); + devpThread.setPakMkWalk(staProtocol.getSiteId(), false); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); } } @@ -515,7 +516,7 @@ } } } else { - TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>()); + TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("IO_TYPE",1).eq("WRK_STS",1).eq("START_POINT",staProtocol.getSiteId().toString())); if (!Cools.isEmpty(taskWrk1)) { if (taskWrk1.getIoType() == 1 && taskWrk1.getStartPoint().equals(staProtocol.getSiteId().toString())) { @@ -526,8 +527,21 @@ return; } else { staProtocol.setWorkNo(taskWrk1.getWrkNo()); - staProtocol.setStaNo(staDesc.getCrnStn()); + staProtocol.setStaNo(BarcodeUtils.getStaNo(staProtocol.getSiteId())); + devpThread.setPakMkWalk(staProtocol.getSiteId(), false); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); + + Date now = new Date(); +// taskWrk1.setStatus(TaskStatusType.DISTRIBUTE.id);//娲惧彂鐘舵�� +// taskWrk.setAssignTime(now);//娲惧彂鏃堕棿 + taskWrk1.setExecuteTime(now); + taskWrk1.setWrkSts(2);//宸ヤ綔鐘舵�� 3.鍚婅溅鍏ュ簱 + taskWrk1.setCrnNo(staDesc.getCrnNo());//鍫嗗灈鏈哄彿 + taskWrk1.setModiTime(now); + taskWrk1.setModiUser(9988L); + taskWrkService.updateById(taskWrk1); + + } } return; @@ -591,7 +605,7 @@ log.info("涓嬪彂杈撻�佺嚎浠诲姟锛歵askWrk:" + JSON.toJSONString(taskWrk)); // R r = siteController.siteDetlUpdate(Integer.valueOf(taskWrk.getTargetPoint()), taskWrk.getWrkNo().shortValue(), (short) 0, "Y", false, false); staProtocol.setWorkNo(taskWrk.getWrkNo()); - staProtocol.setStaNo(staDesc.getCrnStn()); + staProtocol.setStaNo(BarcodeUtils.getStaNo(staProtocol.getSiteId())); boolean offer = false; try { offer = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol)); @@ -603,7 +617,7 @@ if (offer) { log.info("涓嬪彂杈撻�佺嚎浠诲姟鎴愬姛锛歵askWrk:" + JSON.toJSONString(taskWrk)); Date now = new Date(); - taskWrk.setStatus(5); + taskWrk.setStatus(9); taskWrk.setWrkSts(14); taskWrk.setModiTime(now); taskWrk.setCompleteTime(now); @@ -781,7 +795,7 @@ crnCommand.setDestinationPosY(Utils.getBayShort(taskWrk.getTargetPoint())); // 鐩爣搴撲綅灞� crnCommand.setDestinationPosZ(Utils.getLevShort(taskWrk.getTargetPoint())); // 鐩爣搴撲綅鎺� crnCommand.setCommand((short) 1); - if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand), false)) { + if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) { log.error("鍫嗗灈鏈哄懡浠ょ敓鎴愬け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); throw new CoolException("鍫嗗灈鏈哄懡浠ょ敓鎴愬け璐�"); } else { @@ -795,7 +809,7 @@ HashMap<String, Object> headParam = new HashMap<>(); headParam.put("taskNo", taskWrk.getTaskNo()); headParam.put("status", taskWrk.getStatus()); - headParam.put("ioType", taskWrk.getIoType()); + headParam.put("ioType", taskWrk.getIoTypeWms()); headParam.put("barcode", taskWrk.getBarcode()); String response; response = new HttpHandler.Builder() @@ -893,7 +907,7 @@ command.setDestinationPosY(crnStn.getBay().shortValue()); // 鐩爣搴撲綅鍒� command.setDestinationPosZ(crnStn.getLev().shortValue()); // 鐩爣搴撲綅灞� command.setCommand((short) 1); - if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, command), false)) { + if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, command))) { log.error("鍫嗗灈鏈哄懡浠ょ敓鎴愬け璐ワ紝鍫嗗灈鏈哄彿={}锛屽贩閬�={}锛屼换鍔℃暟鎹�={}", slave.getId(), taskWrk.getCrnNo(), JSON.toJSON(command)); throw new CoolException("鍫嗗灈鏈哄懡浠ょ敓鎴愬け璐�"); } else { @@ -915,7 +929,7 @@ HashMap<String, Object> headParam = new HashMap<>(); headParam.put("taskNo", taskWrk.getTaskNo()); headParam.put("status", taskWrk.getStatus()); - headParam.put("ioType", taskWrk.getIoType()); + headParam.put("ioType", taskWrk.getIoTypeWms()); headParam.put("barcode", taskWrk.getBarcode()); String response; response = new HttpHandler.Builder() @@ -1003,7 +1017,7 @@ crnCommand.setDestinationPosY(Utils.getBayShort(taskWrk.getTargetPoint())); // 鐩爣搴撲綅鍒� crnCommand.setDestinationPosZ(Utils.getLevShort(taskWrk.getTargetPoint())); // 鐩爣搴撲綅灞� crnCommand.setCommand((short) 1); - if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand), false)) { + if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) { log.error("鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); } else { // 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓� @@ -1019,7 +1033,7 @@ HashMap<String, Object> headParam = new HashMap<>(); headParam.put("taskNo", taskWrk.getTaskNo()); headParam.put("status", taskWrk.getStatus()); - headParam.put("ioType", taskWrk.getIoType()); + headParam.put("ioType", taskWrk.getIoTypeWms()); headParam.put("barcode", taskWrk.getBarcode()); String response; response = new HttpHandler.Builder() @@ -1071,14 +1085,14 @@ } // 鐘舵�侊細绛夊緟纭 骞朵笖 浠诲姟瀹屾垚浣� = 1 - if (!Cools.isEmpty(crnProtocol.getTaskFinish()) && crnProtocol.getTaskFinish() == 0 && crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.getTaskNo() != 0) { + if (crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.getTaskNo() != 0) { //鑾峰彇鍏ュ簱寰呯‘璁ゅ伐浣滄。 TaskWrk taskWrk = taskWrkMapper.selectCrnNoInWorking(crnProtocol.getLaneNo(), crnProtocol.getTaskNo().intValue()); if (Cools.isEmpty(taskWrk) && crnProtocol.getTaskNo() != 999) { log.error("鍫嗗灈鏈哄浜庣瓑寰呯‘璁や笖浠诲姟瀹屾垚鐘舵�侊紝浣嗘湭鎵惧埌宸ヤ綔妗c�傚爢鍨涙満鍙�={}锛屽贩閬撳彿={}锛屽伐浣滃彿={}", crn.getId(), crnProtocol.getLaneNo(), crnProtocol.getTaskNo()); continue; } - Thread.sleep(300); +// Thread.sleep(300); //纭瀹屾垚淇″彿 CrnOperatorParam crnOperatorParam = new CrnOperatorParam(); crnOperatorParam.setCrnNo(crn.getId()); @@ -1133,7 +1147,7 @@ HashMap<String, Object> headParam = new HashMap<>(); headParam.put("taskNo", taskWrk.getTaskNo()); headParam.put("status", taskWrk.getStatus()); - headParam.put("ioType", taskWrk.getIoType()); + headParam.put("ioType", taskWrk.getIoTypeWms()); headParam.put("barcode", taskWrk.getBarcode()); String response; log.error("wcs瀹岀粨浠诲姟涓婃姤wms==銆�", headParam); @@ -1341,7 +1355,7 @@ if (rgvProtocol == null || rgvTaskProtocol == null) { return false; } - if (!rgvProtocol.getModeType().equals(RgvModeType.AUTO) || rgvProtocol.getRgvPos().equals(0L) || rgvTaskProtocol.getAvoid() == -1 || rgvProtocol.getRgvPosDestination() == 0L + if (!rgvProtocol.getModeType().equals(RgvModeType.AUTO) || rgvProtocol.getRgvPos().equals(0L) || rgvTaskProtocol.getAvoid() == -1 || (!rgvProtocol.getStatusType().equals(RgvStatusType.IDLE) && !rgvProtocol.getStatusType().equals(RgvStatusType.ROAM))) { return false; } @@ -1369,8 +1383,9 @@ // 鍒ゆ柇鏄惁婊¤冻鍙栬揣鏉′欢 if (staProtocol.isAutoing() // && staProtocol.isLoading() + && staProtocol.isStaOk() && staProtocol.getWorkNo() != 0) { - TaskWrk taskWrk = taskWrkService.selectByTaskNo(staProtocol.getWorkNo().toString()); + TaskWrk taskWrk = taskWrkService.selectByWrkNo(staProtocol.getWorkNo()); if (taskWrk != null) { return taskWrk; } @@ -1592,12 +1607,9 @@ if (taskWrk == null) { return false; } - Integer targetPointConvert = taskWrk.getTargetPointConvert(); +// Integer targetPointConvert = taskWrk.getTargetPointConvert(); + Integer targetPointConvert = BarcodeUtils.getOutStaNo(taskWrk.getOriginTargetPoint()); if (targetPointConvert == null) { - return false; - } - RgvSlave.RgvStn rgvStnEnd = getRgvStnNow(rgvSlave, targetPointConvert); - if (rgvStnEnd == null) { return false; } @@ -1605,19 +1617,19 @@ BasDevpPosition basDevpPositionEnd = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("DEV_NO", targetPointConvert)); //鎵ц issuedTake.setTaskNo(Long.valueOf(taskWrk.getTaskNo())); - issuedTake.setTaskStatus(1); + issuedTake.setTaskStatus(2); issuedTake.setTaskNoDirection(issuedTake.gettaskNoDirection$(issuedTake.getTaskNo(), issuedTake.getTaskStatus())); issuedTake.setTargetPosition(basDevpPositionSou.getPlcPosition()); issuedTake.setIsRunning(1); - issuedTake.setDirection(rgvStn.isDirection()); + issuedTake.setDirection(basDevpPositionSou.getRgvSign()==1); issuedPut.setTaskNo(Long.valueOf(taskWrk.getTaskNo())); - issuedPut.setTaskStatus(2); + issuedPut.setTaskStatus(3); issuedPut.setTaskNoDirection(issuedPut.gettaskNoDirection$(issuedPut.getTaskNo(), issuedPut.getTaskStatus())); issuedPut.setTargetPosition(basDevpPositionEnd.getPlcPosition()); issuedPut.setIsRunning(1); - issuedPut.setDirection(rgvStnEnd.isDirection()); + issuedPut.setDirection(basDevpPositionEnd.getRgvSign()==1); } catch (Exception e) { log.error("浠诲姟鐢熸垚澶辫触issued1===銆嬪紓甯镐俊鎭細{}", e.getMessage()); return false; @@ -1641,5 +1653,118 @@ return true; } + /** + * 鍑哄簱 ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣� + */ + public synchronized void ledExecute(Integer mark) { + + for (LedSlave led : slaveProperties.getLed()) { + // 鑾峰彇杈撻�佺嚎plc绾跨▼ + DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId()); + // 鍛戒护闆嗗悎 + List<LedCommand> commands = new ArrayList<>(); + // 宸ヤ綔妗i泦鍚� + List<WrkMast> wrkMasts = new ArrayList<>(); + for (Integer staNo : led.getStaArr()) { + // 鑾峰彇鍙夎溅绔欑偣 + StaProtocol staProtocol = devpThread.getStation().get(staNo); + if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) { + continue; + } else { + staProtocol = staProtocol.clone(); + } + // 鑾峰彇宸ヤ綔妗f暟鎹� + LedCommand ledCommand = new LedCommand(); + +// +// ledCommand.setWorkNo(wrkMast.getWrkNo()); +// ledCommand.setIoType(wrkMast.getIoType()); +// ledCommand.setTitle("绌烘澘鍑哄簱"); +// ledCommand.setEmptyMk(true); +// ledCommand.setSourceLocNo(wrkMast.getSourceLocNo()); +// ledCommand.setLocNo(wrkMast.getLocNo()); +// ledCommand.setStaNo(wrkMast.getStaNo()); + MatDto matDto = new MatDto(); + ledCommand.getMatDtos().add(matDto); + commands.add(ledCommand); + } + Set<Integer> workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet()); + // 鑾峰彇LED绾跨▼ + LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId()); + // 鐩稿悓宸ヤ綔鍙烽泦鍚堝垯杩囨护 + if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) { + continue; + } + // 鍛戒护涓嬪彂 ------------------------------------------------------------------------------- + if (!commands.isEmpty()) { + if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) { +// News.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort()); + continue; + }else { + ledThread.setLedMk(false); + } + } + + try { + // 淇敼涓绘。led鏍囪 + for (WrkMast wrkMast : wrkMasts) { + wrkMast.setOveMk("Y"); + wrkMast.setModiTime(new Date()); + if (wrkMastMapper.updateById(wrkMast) == 0) { +// News.errorNoLog(""+mark+" - 4"+" - 鏇存柊宸ヤ綔妗eけ璐�"); + throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�"); + } + } + + // 鏇存柊绾跨▼褰撳墠宸ヤ綔鍙烽泦鍚� + ledThread.setWorkNos(workNos); + + } catch (Exception e) { + e.printStackTrace(); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + } + + } +// News.infoNoLog(""+mark+" - 0"+" - 鍑哄簱 ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣ㄦ墽琛屽畬鎴�"); + } + + /** + * 鍏朵粬 ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅 + */ + public synchronized void ledReset(Integer mark) { + +// News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛�:鍏朵粬 ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅"); + for (LedSlave led : slaveProperties.getLed()) { + + // 鑾峰彇杈撻�佺嚎plc绾跨▼ + DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId()); + // 鍛戒护闆嗗悎 + boolean reset = true; + for (Integer staNo : led.getStaArr()) { + // 鑾峰彇鍙夎溅绔欑偣 + StaProtocol staProtocol = devpThread.getStation().get(staNo); + if (staProtocol == null) { + continue; + } + if (staProtocol.getWorkNo() != 0 && staProtocol.isLoading()) { + reset = false; + break; + } + } + // 鑾峰彇led绾跨▼ + LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId()); + // led鏄剧ず榛樿鍐呭 + if (reset && !ledThread.isLedMk()) { + ledThread.setLedMk(true); + if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) { +// News.error(""+mark+" - 1"+" - {}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort()); + } else { + + } + } + } +// News.infoNoLog(""+mark+" - 0"+" - 鎵ц瀹屾垚锛氬叾浠� ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅"); + } + } -- Gitblit v1.9.1