From e22952465f1ab08a58f84c2f01e7d4e89b6bd61e Mon Sep 17 00:00:00 2001 From: Junjie <xjj@123> Date: 星期一, 18 八月 2025 17:10:34 +0800 Subject: [PATCH] # --- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 284 +++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 187 insertions(+), 97 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 b37c954..ef9d076 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java @@ -62,7 +62,6 @@ */ @Slf4j @Service("mainService") -@Transactional public class MainServiceImpl { public static final long COMMAND_TIMEOUT = 5 * 1000; @@ -234,6 +233,12 @@ .eq("loc_no", dto.getLocNo())); short staNo = dto.getStaNo().shortValue(); + + int sourceStaNo = dto.getSourceStaNo(); + if (sourceStaNo == 1007) { + staNo = 2002; + } + if (inSta.getStaNo() == 1002) { staNo = 2002; } @@ -650,75 +655,73 @@ * 鍫嗗灈鏈虹珯鍑哄簱鍒板嚭搴撶珯 */ public synchronized void crnStnToOutStn(Integer mark) { + List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() + .eq("wrk_sts", 12) + ); - for (CrnSlave crnSlave : slaveProperties.getCrn()) { - // 閬嶅巻鍫嗗灈鏈哄嚭搴撶珯 - for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) { - // 鑾峰彇鍫嗗灈鏈哄嚭搴撶珯淇℃伅 - DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId()); - StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo()); - if (staProtocol == null) { - continue; - } else { - staProtocol = staProtocol.clone(); + for (WrkMast wrkMast : wrkMasts) { + // 鍒ゆ柇宸ヤ綔妗f潯浠� + if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) { + continue; + } + + Integer devpId = null; + Integer sourceStaNo = wrkMast.getSourceStaNo(); + for (CrnSlave crnSlave : slaveProperties.getCrn()) { + for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) { + if (crnStn.getStaNo().equals(sourceStaNo)) { + devpId = crnStn.getDevpPlcId(); + break; + } } - if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) { - // 鏌ヨ宸ヤ綔妗� - WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(staProtocol.getSiteId()); - if (wrkMast == null) { + } + + if (devpId == null) { + News.error("" + mark + " - 0" + " - 鍫嗗灈鏈虹珯鍑哄簱鍒板嚭搴撶珯锛屾湭鎵惧埌瀵瑰簲PLC"); + continue; + } + + DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devpId); + StaProtocol staProtocol = devpThread.getStation().get(sourceStaNo); + if (staProtocol == null) { + continue; + } else { + staProtocol = staProtocol.clone(); + } + + if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) { + CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo()); + CrnProtocol crnProtocol = crnThread.getCrnProtocol(); + + if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue()) + && (crnProtocol.statusType == CrnStatusType.PUTTING || crnProtocol.statusType == CrnStatusType.WAITING)) { + //鏀捐揣涓� 鎴� 绛夊緟纭 + News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�"); + + // 鍛戒护涓嬪彂鍖� -------------------------------------------------------------------------- + LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() + .eq("loc_no", wrkMast.getSourceLocNo())); + + // 涓嬪彂绔欑偣淇℃伅 + staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue()); + staProtocol.setStaNo(wrkMast.getStaNo().shortValue()); + staProtocol.setPalletSize(locMast.getLocType2()); + if (!MessageQueue.offer(SlaveType.Devp, devpId, new Task(2, staProtocol))) { continue; } - // 鍒ゆ柇宸ヤ綔妗f潯浠� - if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) { - continue; - } - // 鍒ゆ柇鍚婅溅鏄惁瀹為檯宸插畬鎴愶紝涓旂數鑴戠姸鎬佸湪move涓紝浠ュ鐢佃剳杩涜鏇存柊宸ヤ綔妗� - CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo()); - CrnProtocol crnProtocol = crnThread.getCrnProtocol(); - if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) { - // 绉诲姩涓� - continue; - } - // 鍒ゆ柇鍫嗗灈鏈虹姸鎬佺瓑寰呯‘璁� - if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue()) - && crnProtocol.statusType == CrnStatusType.WAITING - && crnProtocol.forkPosType == CrnForkPosType.HOME) { - News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�"); - // 鍛戒护涓嬪彂鍖� -------------------------------------------------------------------------- - - LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() - .eq("loc_no", wrkMast.getSourceLocNo())); - - // 涓嬪彂绔欑偣淇℃伅 - staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue()); - staProtocol.setStaNo(wrkMast.getStaNo().shortValue()); - staProtocol.setPalletSize(locMast.getLocType2()); - if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) { - continue; - } - - // 鏇存柊宸ヤ綔妗g姸鎬佷负14澶辫触 - wrkMast.setWrkSts(14L); - wrkMast.setCrnEndTime(new Date()); - if (wrkMastMapper.updateById(wrkMast) != 0) { - // 澶嶄綅鍫嗗灈鏈� - crnThread.setResetFlag(true); - } else { - News.error("" + mark + " - 1" + " - 鏇存柊宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负14澶辫触锛侊紒锛� [宸ヤ綔鍙�:{}]", wrkMast.getWrkNo()); - } - + // 鏇存柊宸ヤ綔妗g姸鎬佷负14澶辫触 + wrkMast.setWrkSts(14L); + wrkMast.setCrnEndTime(new Date()); + if (wrkMastMapper.updateById(wrkMast) != 0) { + News.info("" + mark + " - 1" + " - 鏇存柊宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负14鎴愬姛锛侊紒锛� [宸ヤ綔鍙�:{}]", wrkMast.getWrkNo()); } else { - News.errorNoLog("" + mark + " - 6" + " - 鍫嗗灈鏈轰俊鎭笉绗﹀悎鍏ュ簱鏉′欢锛侊紒锛�" - + " 鍫嗗灈鏈虹姸鎬侊細" + crnProtocol.modeType + "==鑷姩AUTO锛�" + CrnModeType.AUTO - + "銆佸爢鍨涙満浠诲姟鍙凤細" + crnProtocol.getTaskNo() + "==宸ヤ綔妗d换鍔″彿锛�" + wrkMast.getWrkNo().shortValue() - + "銆佺姸鎬佹灇涓撅細" + crnProtocol.statusType + "==WAITING锛�90 //浠诲姟瀹屾垚绛夊緟WCS纭)锛�" + CrnStatusType.WAITING - + "銆佽揣鍙変綅缃細" + crnProtocol.forkPosType + "==HOME锛�0 // 璐у弶鍘熶綅锛�" + CrnForkPosType.HOME); + News.error("" + mark + " - 1" + " - 鏇存柊宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负14澶辫触锛侊紒锛� [宸ヤ綔鍙�:{}]", wrkMast.getWrkNo()); } - } } } + News.infoNoLog("" + mark + " - 0" + " - 鍫嗗灈鏈虹珯鍑哄簱鍒板嚭搴撶珯 ===銆嬫墽琛屽畬鎴�"); } @@ -744,6 +747,12 @@ // if(crnThread.isBackHpFlag()){ // continue; // } + + //鍫嗗灈鏈哄洖鍘熺偣浠诲姟涓� + Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK + crn.getId()); + if (object != null) { + continue; + } // 鍙湁褰撳爢鍨涙満绌洪棽 骞朵笖 鏃犱换鍔℃椂鎵嶇户缁墽琛� if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO @@ -812,7 +821,7 @@ continue; } - Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK); + Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK + crn.getId()); if (object != null) { continue; } @@ -844,7 +853,7 @@ News.error("鍫嗗灈鏈虹Щ鍔ㄥ懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand)); } crnThread.setBackHpFlag(true); - redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60); + redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 10); try { Thread.sleep(500); } catch (Exception e) { @@ -884,7 +893,7 @@ continue; } - Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK); + Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK + crn.getId()); if (object != null) { continue; } @@ -916,7 +925,7 @@ News.error("鍫嗗灈鏈虹Щ鍔ㄥ懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand)); } crnThread.setBackHpFlag(true); - redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60); + redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 10); try { Thread.sleep(500); } catch (Exception e) { @@ -1204,8 +1213,7 @@ // continue; } // 鍒ゆ柇鍫嗗灈鏈哄嚭搴撶珯鐘舵�� - if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y") - && staProtocol.getWorkNo() == 0) { + if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")) { //鏍规嵁鍙傛暟鍒ゆ柇鏄惁鏍¢獙鍙嚭淇″彿 String crnOutVerifyOut = "Y"; @@ -1217,6 +1225,10 @@ if (crnOutVerifyOut.equals("Y")) { if (!staProtocol.isOutEnable()) { + continue; + } + + if (staProtocol.getWorkNo() > 0) { continue; } } @@ -1231,12 +1243,22 @@ } if (crnProtocol.getCrnNo() == 1) { - //鍒ゆ柇鍫嗗灈鏈哄拰褰撳墠浠诲姟鏄惁澶勪簬涓�涓贩閬� - if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) { - //鍒ゆ柇鍫嗗灈鏈烘墍鍦ㄥ贩閬撴槸鍚﹀瓨鍦ㄥ叾浠栦换鍔★紝濡傚瓨鍦ㄥ垯浼樺厛鎵ц - List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false); - if (!currentWrkMasts.isEmpty()) { - continue;//褰撳墠鍫嗗灈鏈烘墍鍦ㄥ贩閬撳瓨鍦ㄤ换鍔� + String turnCrnExecuteCurrentChannel = "Y"; + Config turnCrnExecuteCurrentChannelConfig = configService.selectOne(new EntityWrapper<Config>() + .eq("code", "turnCrnExecuteCurrentChannel") + ); + if (turnCrnExecuteCurrentChannelConfig != null) { + turnCrnExecuteCurrentChannel = turnCrnExecuteCurrentChannelConfig.getValue(); + } + + if(turnCrnExecuteCurrentChannel.equals("Y")) { + //鍒ゆ柇鍫嗗灈鏈哄拰褰撳墠浠诲姟鏄惁澶勪簬涓�涓贩閬� + if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) { + //鍒ゆ柇鍫嗗灈鏈烘墍鍦ㄥ贩閬撴槸鍚﹀瓨鍦ㄥ叾浠栦换鍔★紝濡傚瓨鍦ㄥ垯浼樺厛鎵ц + List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false); + if (!currentWrkMasts.isEmpty()) { + continue;//褰撳墠鍫嗗灈鏈烘墍鍦ㄥ贩閬撳瓨鍦ㄤ换鍔� + } } } } @@ -1522,6 +1544,7 @@ if (wrkMastMapper.updateById(wrkMast) == 0) { News.error("" + mark + " - 3" + " - 5" + " - 銆愬簱浣嶇Щ杞�� 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo()); } + crnProtocol.setLastIo("I"); } News.infoNoLog("" + mark + " - 3" + " - 0" + " - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氬簱浣嶇Щ杞畬鎴�"); @@ -1627,26 +1650,46 @@ if (crnProtocol.getTaskNo() == 9999) { // 鍫嗗灈鏈哄浣� crnThread.setResetFlag(true); - } else { - // 鑾峰彇鍏ュ簱寰呯‘璁ゅ伐浣滄。 - WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue()); - if (wrkMast == null) { - News.error("" + mark + " - 1" + " - 鍫嗗灈鏈哄浜庣瓑寰呯‘璁や笖浠诲姟瀹屾垚鐘舵�侊紝浣嗘湭鎵惧埌宸ヤ綔妗c�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crn.getId(), crnProtocol.getTaskNo()); - continue; - } + redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 8);//闃叉鍥炲師鐐瑰悗涓嬪彂鎸囦护杩囧揩 + continue; + } + + // 鑾峰彇寰呯‘璁ゅ伐浣滄。 + WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue()); + if (wrkMast == null) { + News.error("" + mark + " - 1" + " - 鍫嗗灈鏈哄浜庣瓑寰呯‘璁や笖浠诲姟瀹屾垚鐘舵�侊紝浣嗘湭鎵惧埌宸ヤ綔妗c�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crn.getId(), crnProtocol.getTaskNo()); + continue; + } + + Date now = new Date(); + if(wrkMast.getIoType() < 100){ // 鍏ュ簱 + 搴撲綅杞Щ ==> 4.鍏ュ簱瀹屾垚 if (wrkMast.getWrkSts() == 3 || (wrkMast.getWrkSts() == 12 && (wrkMast.getIoType() == 11 || wrkMast.getIoType() == 111))) { wrkMast.setWrkSts(4L); } else { continue; } - Date now = new Date(); + wrkMast.setCrnEndTime(now); wrkMast.setModiTime(now); // 淇敼鎴愬姛鍚庡浣嶅爢鍨涙満 if (wrkMastMapper.updateById(wrkMast) > 0) { // 鍫嗗灈鏈哄浣� News.warnNoLog("" + mark + " - 2" + " - 淇敼鎴愬姛鍚庡浣嶅爢鍨涙満 : 鍫嗗灈鏈哄彿={}", crnThread.getCrnProtocol().getCrnNo()); + crnThread.setResetFlag(true); + } + }else { + List<Long> list = new ArrayList<>(); + list.add(14L); + list.add(15L); + if (!list.contains(wrkMast.getWrkSts())) { + News.error("" + mark + " - 1" + " - 鍫嗗灈鏈哄浜庣瓑寰呯‘璁や絾宸ヤ綔妗g姸鎬佹湭瀹屾垚銆傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crn.getId(), crnProtocol.getTaskNo()); + continue; + } + + wrkMast.setCrnEndTime(now); + if (wrkMastMapper.updateById(wrkMast) != 0) { + // 澶嶄綅鍫嗗灈鏈� crnThread.setResetFlag(true); } } @@ -1863,9 +1906,13 @@ if (jsonObject.getInteger("code").equals(200)) { StartupDto dto = jsonObject.getObject("data", StartupDto.class); + LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() + .eq("loc_no", dto.getLocNo())); + // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护 staProtocol.setWorkNo(dto.getWorkNo().shortValue()); staProtocol.setStaNo(dto.getStaNo().shortValue()); + staProtocol.setPalletSize(locMast.getLocType2()); devpThread.setPakMk(staProtocol.getSiteId(), false); boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); if (!result) { @@ -1973,7 +2020,7 @@ wrkMast1.setIoType(3); // 鍏ュ嚭搴撶姸鎬侊細3.绔欏埌绔� wrkMast1.setIoPri(13D); // 浼樺厛绾� wrkMast1.setSourceStaNo(emptyInSta.getStaNo()); - wrkMast1.setStaNo(1007); + wrkMast1.setStaNo(1004); wrkMast1.setBarcode(barcode); // 鎿嶄綔浜哄憳鏁版嵁 wrkMast1.setAppeTime(new Date()); @@ -1986,6 +2033,7 @@ // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护 staProtocol.setWorkNo((short) workNo); staProtocol.setStaNo((short) 2003); + staProtocol.setPalletSize((short) 1); devpThread.setPakMk(staProtocol.getSiteId(), false); boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); if (!result) { @@ -2092,22 +2140,64 @@ // }catch (Exception e){ // log.error("宸ヤ綔妗f鏄庣粏杈撳叆鐢佃鏈哄け璐�1锛氬紓甯镐俊鎭�==銆�"+e); // } - wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto( - wrkDetl.getMatnr() - , wrkDetl.getMaktx() - , wrkDetl.getAnfme() - , wrkDetl.getWeight() - , wrkDetl.getStockNum() - , wrkDetl.getStockNum2() - , wrkDetl.getSpecs() - , wrkDetl.getSku() - , wrkDetl.getZpallet() - , wrkDetl.getModel() - , wrkDetl.getSupp() - , wrkDetl.getKpCstmrName() - , wrkDetl.getOrderNo() - , wrkDetl.getCstateid$() - ))); + + if (!wrkDetls.isEmpty()) { + WrkDetl wrkDetl = wrkDetls.get(0); + double anfme = 0D; + double weight = 0D; + for (WrkDetl detl : wrkDetls) { + anfme += detl.getAnfme(); + weight += detl.getWeight(); + wrkDetl.setAnfme(anfme); + wrkDetl.setWeight(weight); + } + + List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>() + .eq("loc_no", wrkMast.getSourceLocNo())); + double totalAnfme = 0D; + double totalWeight = 0D; + for (LocDetl locDetl : locDetls) { + totalAnfme += locDetl.getAnfme(); + totalWeight += locDetl.getWeight(); + } + wrkDetl.setStockNum(totalAnfme); + wrkDetl.setStockNum2(totalWeight); + + ledCommand.getMatDtos().add(new MatDto( + wrkDetl.getMatnr() + , wrkDetl.getMaktx() + , wrkDetl.getAnfme() + , wrkDetl.getWeight() + , wrkDetl.getStockNum() + , wrkDetl.getStockNum2() + , wrkDetl.getSpecs() + , wrkDetl.getSku() + , wrkDetl.getZpallet() + , wrkDetl.getModel() + , wrkDetl.getSupp() + , wrkDetl.getKpCstmrName() + , wrkDetl.getOrderNo() + , wrkDetl.getCstateid$() + )); + +// wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto( +// wrkDetl.getMatnr() +// , wrkDetl.getMaktx() +// , wrkDetl.getAnfme() +// , wrkDetl.getWeight() +// , wrkDetl.getStockNum() +// , wrkDetl.getStockNum2() +// , wrkDetl.getSpecs() +// , wrkDetl.getSku() +// , wrkDetl.getZpallet() +// , wrkDetl.getModel() +// , wrkDetl.getSupp() +// , wrkDetl.getKpCstmrName() +// , wrkDetl.getOrderNo() +// , wrkDetl.getCstateid$() +// ))); + } + } commands.add(ledCommand); } -- Gitblit v1.9.1