From ed66b0b468efc3f1f51c68712d82e234c7bba2bf Mon Sep 17 00:00:00 2001 From: ytfl <ytfl@qq.com> Date: 星期五, 18 七月 2025 08:29:20 +0800 Subject: [PATCH] # --- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 200 +++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 173 insertions(+), 27 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 072defd..efa0e33 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java @@ -13,7 +13,7 @@ import com.zy.asrs.mapper.WrkMastMapper; import com.zy.asrs.service.*; import com.zy.asrs.utils.Utils; -import com.zy.asrs.utils.VersionUtils; +import com.zy.common.constant.RedisConstantType; import com.zy.common.model.LocTypeDto; import com.zy.common.model.MatDto; import com.zy.common.model.SearchLocParam; @@ -22,6 +22,7 @@ import com.zy.common.utils.CollectionUtils; import com.zy.common.utils.HttpHandler; import com.zy.common.utils.News; +import com.zy.common.utils.RedisUtil; import com.zy.core.CrnThread; import com.zy.core.DevpThread; import com.zy.core.cache.MessageQueue; @@ -95,6 +96,8 @@ private WrkMastLogService wrkMastLogService; @Autowired private ConfigService configService; + @Autowired + private RedisUtil redisUtil; @Value("${wms.url}") private String wmsUrl; @@ -229,9 +232,14 @@ LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() .eq("loc_no", dto.getLocNo())); + short staNo = dto.getStaNo().shortValue(); + if (inSta.getStaNo() == 1002) { + staNo = 2002; + } + barcodeThread.setBarcode(""); staProtocol.setWorkNo(dto.getWorkNo().shortValue()); - staProtocol.setStaNo(dto.getStaNo().shortValue()); + staProtocol.setStaNo(staNo); staProtocol.setPalletSize(locMast.getLocType2()); devpThread.setPakMk(staProtocol.getSiteId(), false); boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); @@ -454,6 +462,7 @@ wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 鐩爣搴撲綅 = 鍑哄簱鏃剁殑婧愬簱浣� wrkMast.setSourceLocNo(""); // 婧愬簱浣嶆竻绌� wrkMast.setModiTime(now); + wrkMast.setUpdMk("");//鍏佽鍐嶆绉诲簱 if (wrkMastMapper.updateById(wrkMast) == 0) { throw new CoolException("鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�"); } @@ -635,6 +644,10 @@ */ public synchronized void crnMove() { for (CrnSlave crn : slaveProperties.getCrn()) { + if (crn.getId() == 1) { + continue; + } + // 鑾峰彇鍫嗗灈鏈轰俊鎭� CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); CrnProtocol crnProtocol = crnThread.getCrnProtocol(); @@ -656,8 +669,15 @@ continue; } + Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK); + if (object != null) { + continue; + } + List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() - .eq("crn_no", crn.getId())); + .eq("crn_no", crn.getId()) + .eq("wrk_sts", 2) + ); if (!wrkMasts.isEmpty()) { continue; } @@ -677,10 +697,88 @@ crnCommand.setDestinationPosX((short) 0); // 鐩爣搴撲綅鎺� crnCommand.setDestinationPosY((short) 0); // 鐩爣搴撲綅鍒� crnCommand.setDestinationPosZ((short) 0); // 鐩爣搴撲綅灞� - if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(4, crnCommand))) { + if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, crnCommand))) { News.error("鍫嗗灈鏈虹Щ鍔ㄥ懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand)); } crnThread.setBackHpFlag(true); + redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60); + try { + Thread.sleep(500); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + /** + * 鍫嗗灈鏈烘湁鍏ュ簱浠诲姟鏃讹紝鍥炲叆搴撳彛寰呮満 + */ + public synchronized void crnMoveByInTask() { + for (CrnSlave crn : slaveProperties.getCrn()) { + if (crn.getId() == 1) { + continue; + } + + // 鑾峰彇鍫嗗灈鏈轰俊鎭� + CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); + CrnProtocol crnProtocol = crnThread.getCrnProtocol(); + if (crnProtocol == null) { + continue; + } + BasCrnp basCrnp = basCrnpService.selectById(crn.getId()); + if (basCrnp == null) { + log.error("{}鍙峰爢鍨涙満灏氭湭鍦ㄦ暟鎹簱杩涜缁存姢锛�", crn.getId()); + continue; + } + + if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) { + if (crnProtocol.getBay() == 1 && crnProtocol.getLevel() == 1) { + continue; + } + + if (System.currentTimeMillis() - crnProtocol.getLastCommandTime() < 1000 * 60) { + continue; + } + + Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK); + if (object != null) { + continue; + } + + List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() + .eq("crn_no", crn.getId()) + .notIn("wrk_sts", 5, 14, 15) + ); + if (!wrkMasts.isEmpty()) { + continue; + } + + CrnSlave.CrnStn crnStn = crn.getCrnInStn().get(0); + + News.info("鍫嗗灈鏈烘棤浠诲姟鑷姩鍥炲叆搴撳彛寰呮満==>>" + crnProtocol.getCrnNo() + "鍙峰爢鍨涙満"); + // 鍛戒护涓嬪彂鍖� -------------------------------------------------------------------------- + CrnCommand crnCommand = new CrnCommand(); + crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 鍫嗗灈鏈虹紪鍙� + crnCommand.setTaskNo((short) 9999); // 宸ヤ綔鍙� + crnCommand.setAckFinish((short) 0); // 浠诲姟瀹屾垚纭浣� + crnCommand.setTaskMode(CrnTaskModeType.CRN_MOVE); // 浠诲姟妯″紡: 鍫嗗灈鏈虹Щ鍔� + crnCommand.setSourcePosX(crnStn.getRow().shortValue()); // 婧愬簱浣嶆帓 + crnCommand.setSourcePosY((short) 1); // 婧愬簱浣嶅垪 + crnCommand.setSourcePosZ((short) 1); // 婧愬簱浣嶅眰 + crnCommand.setDestinationPosX((short) 0); // 鐩爣搴撲綅鎺� + crnCommand.setDestinationPosY((short) 0); // 鐩爣搴撲綅鍒� + crnCommand.setDestinationPosZ((short) 0); // 鐩爣搴撲綅灞� + if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, crnCommand))) { + News.error("鍫嗗灈鏈虹Щ鍔ㄥ懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand)); + } + crnThread.setBackHpFlag(true); + redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60); + try { + Thread.sleep(500); + } catch (Exception e) { + e.printStackTrace(); + } } } } @@ -770,12 +868,14 @@ if (null == waitWrkMast) { News.error(""+mark+" - 1"+" - 10"+" - {}搴撲綅寮傚父锛屾湭妫�绱㈠埌鐩稿簲宸ヤ綔妗o紒", shallowLocNo); } else { - waitWrkMast.setIoPri(15D); - waitWrkMast.setModiTime(new Date()); - if (wrkMastMapper.updateById(waitWrkMast) == 0) { - News.error(""+mark+" - 1"+" - 11"+" - 璋冩暣宸ヤ綔妗d紭鍏堢骇澶辫触锛佸伐浣滃彿={}", waitWrkMast.getWrkNo()); + if (waitWrkMast.getWrkSts() != 14 && waitWrkMast.getIoType() > 100) { + waitWrkMast.setIoPri(15D); + waitWrkMast.setModiTime(new Date()); + if (wrkMastMapper.updateById(waitWrkMast) == 0) { + News.error(""+mark+" - 1"+" - 11"+" - 璋冩暣宸ヤ綔妗d紭鍏堢骇澶辫触锛佸伐浣滃彿={}", waitWrkMast.getWrkNo()); + } + continue; } - continue; } } else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) { @@ -941,7 +1041,7 @@ if (crnProtocol.getCrnNo() == 1) { //鍒ゆ柇鍫嗗灈鏈哄拰褰撳墠浠诲姟鏄惁澶勪簬涓�涓贩閬� - if (Utils.getLaneByLocNo(wrkMast.getLocNo()) != crnProtocol.getCrnLane()) { + if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) { //鍒ゆ柇鍫嗗灈鏈烘墍鍦ㄥ贩閬撴槸鍚﹀瓨鍦ㄥ叾浠栦换鍔★紝濡傚瓨鍦ㄥ垯浼樺厛鎵ц List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false); if (!currentWrkMasts.isEmpty()) { @@ -1842,10 +1942,11 @@ List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", shallowLoc.getLocNo())); for (LocDetl locDetl : locDetls) { WrkDetl wrkDetl = new WrkDetl(); + wrkDetl.sync(locDetl); wrkDetl.setWrkNo(workNo); wrkDetl.setIoTime(now); wrkDetl.setAnfme(locDetl.getAnfme()); - VersionUtils.setWrkDetl(wrkDetl, locDetl); // 鐗堟湰鎺у埗 +// VersionUtils.setWrkDetl(wrkDetl, locDetl); // 鐗堟湰鎺у埗 wrkDetl.setAppeTime(now); wrkDetl.setModiTime(now); if (!wrkDetlService.insert(wrkDetl)) { @@ -1966,10 +2067,11 @@ for (LocDetl locDetl : locDetls) { WrkDetl wrkDetl = new WrkDetl(); + wrkDetl.sync(locDetl); wrkDetl.setWrkNo(workNo); wrkDetl.setIoTime(new Date()); wrkDetl.setAnfme(locDetl.getAnfme()); - VersionUtils.setWrkDetl(wrkDetl, locDetl); // 鐗堟湰鎺у埗 +// VersionUtils.setWrkDetl(wrkDetl, locDetl); // 鐗堟湰鎺у埗 wrkDetl.setAppeTime(new Date()); wrkDetl.setModiTime(new Date()); if (!wrkDetlService.insert(wrkDetl)) { @@ -2180,16 +2282,19 @@ // RGV ===>> 鎵ц瀵筊GV鎿嶄綔 public synchronized void rgvExecute(Integer mark) { - ArrayList<Integer> list = new ArrayList<Integer>(){{add(1090);add(1091);}}; + ArrayList<Integer> list = new ArrayList<Integer>(){{add(2003);add(2002);}}; for (Integer staNo : list) { Integer devpId = null; + Integer rgvStaNoDevpId = null; Integer rgvStaNo = null; - if (staNo == 1090) { + if (staNo == 2003) { devpId = 1; - rgvStaNo = 1091; + rgvStaNo = 2002; + rgvStaNoDevpId = 2; }else { devpId = 2; - rgvStaNo = 1090; + rgvStaNo = 2003; + rgvStaNoDevpId = 1; } SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devpId); @@ -2210,7 +2315,49 @@ ) { WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>() .eq("wrk_no", staProtocol.getWorkNo())); + + if (wrkMast == null) { + continue; + } + if (wrkMast.getWrkSts() == 201) { + continue; + } + + SiemensDevpThread devpThread2 = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, rgvStaNoDevpId); + if (devpThread2 == null) { + continue; + } + StaProtocol staProtocolRgvStaNo = devpThread2.getStation().get(rgvStaNo); + if (staProtocolRgvStaNo == null) { + continue; + } + + if (!staProtocolRgvStaNo.isAutoing()) { + continue; + } + + if (staProtocolRgvStaNo.isLoading()) { + continue; + } + + // 鑾峰彇RGV淇℃伅 + RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, 1); + if (rgvThread == null) { + continue; + } + + RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); + if (rgvProtocol == null) { + continue; + } + + if (rgvProtocol.statusType1 != RgvStatusType.IDLE && rgvProtocol.getTaskNo1() != 0) { + continue; + } + + Object object = redisUtil.get(RedisConstantType.RGV_MOVE_LOCK + wrkMast.getWrkNo()); + if (object != null) { continue; } @@ -2231,6 +2378,7 @@ wrkMast.setWrkSts(201L);//201.RGV鎼繍涓� wrkMast.setModiTime(new Date()); wrkMastService.updateById(wrkMast); + redisUtil.set(RedisConstantType.RGV_MOVE_LOCK + wrkMast.getWrkNo(), "lock", 60 * 60); } } } @@ -2250,7 +2398,7 @@ } // 鐘舵�侊細绛夊緟纭 骞朵笖 浠诲姟瀹屾垚浣� = 1 - if (rgvProtocol.statusType == RgvStatusType.WAITING && rgvProtocol.getTaskNo1() != 0) { + if (rgvProtocol.statusType1 == RgvStatusType.WAITING && rgvProtocol.getTaskNo1() != 0) { News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛屽RGV宸ヤ綔妗g殑瀹屾垚鎿嶄綔"); // 鑾峰彇鍏ュ簱寰呯‘璁ゅ伐浣滄。 WrkMast wrkMast = wrkMastMapper.selectPakInStep3(rgvProtocol.getTaskNo1().intValue()); @@ -2259,25 +2407,25 @@ continue; } - if (Cools.isEmpty(wrkMast.getMemo())) { - News.error(""+mark+" - 1"+" - RGV澶勪簬绛夊緟纭涓斾换鍔″畬鎴愮姸鎬侊紝浣嗗伐浣滄。鏁版嵁寮傚父銆俁GV鍙�={}锛屽伐浣滃彿={}", rgvSlave.getId(), rgvProtocol.getTaskNo1()); + if (wrkMast.getWrkSts() != 201) { continue; } Integer devpId = null; Integer devpStaNo = null; String locNo = null; + Long updateWrkSts = null; if (wrkMast.getIoType() < 100) { //鍏ュ簱 - wrkMast.setWrkSts(2L); + updateWrkSts = 2L; devpId = 1; - devpStaNo = 1090; + devpStaNo = 2003; locNo = wrkMast.getLocNo(); }else { //鍑哄簱 - wrkMast.setWrkSts(15L); + updateWrkSts = 15L; devpId = 2; - devpStaNo = 1091; + devpStaNo = 2002; locNo = wrkMast.getSourceLocNo(); } @@ -2304,10 +2452,8 @@ if (!result) { throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触"); } - - Date now = new Date(); - wrkMast.setModiTime(now); - wrkMastMapper.updateById(wrkMast); + wrkMastMapper.updateWrkSts(updateWrkSts, wrkMast.getWrkNo()); + rgvThread.setResetFlag1(true); } } } -- Gitblit v1.9.1