From 627f9f28c8a19d9deae694c11c10dec1d4593270 Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期四, 06 六月 2024 16:58:28 +0800 Subject: [PATCH] # --- zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 226 insertions(+), 4 deletions(-) diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java index 8176068..ad71444 100644 --- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java @@ -7,6 +7,7 @@ import com.zy.asrs.framework.common.Cools; import com.zy.asrs.framework.common.SnowflakeIdWorker; import com.zy.asrs.wcs.core.domain.dto.RedisMapDto; +import com.zy.asrs.wcs.core.domain.dto.StaDto; import com.zy.asrs.wcs.core.entity.*; import com.zy.asrs.wcs.core.kernel.AnalyzeService; import com.zy.asrs.wcs.core.model.MapNode; @@ -26,6 +27,7 @@ import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol; import com.zy.asrs.wcs.rcs.model.protocol.StaProtocol; import com.zy.asrs.wcs.rcs.service.DeviceService; +import com.zy.asrs.wcs.rcs.thread.BarcodeThread; import com.zy.asrs.wcs.rcs.thread.DevpThread; import com.zy.asrs.wcs.rcs.thread.ShuttleThread; import com.zy.asrs.wcs.system.entity.Dict; @@ -68,13 +70,201 @@ private ShuttleDispatcher shuttleDispatcher; @Autowired private RedisUtil redisUtil; + @Autowired + private BasConveyorService basConveyorService; /** * 缁勬墭 * 鍏ュ簱绔欙紝鏍规嵁鏉$爜鎵弿鐢熸垚鍏ュ簱宸ヤ綔妗o紝宸ヤ綔鐘舵�� 2 */ public synchronized void generateInboundWrk() { + try { + // 鏍规嵁杈撻�佺嚎plc閬嶅巻 + List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>() + .eq(Device::getDeviceType, DeviceCtgType.CONVEYOR.val()) + .eq(Device::getStatus, 1)); + for (Device devp : list) { + BasConveyor basConveyor = basConveyorService.getOne(new LambdaQueryWrapper<BasConveyor>().eq(BasConveyor::getDeviceId, devp.getId()).eq(BasConveyor::getHostId, devp.getHostId())); + // 閬嶅巻鍏ュ簱鍙� + for (StaDto inSta : JSON.parseArray(basConveyor.getInSta(), StaDto.class)) { + // 鑾峰彇鍏ュ簱绔欎俊鎭� + DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId().intValue()); + StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo()); + if (staProtocol == null) { + continue; + } else { + staProtocol = staProtocol.clone(); + } + Short workNo = staProtocol.getWorkNo(); + // 灏哄妫�娴嬪紓甯� + boolean back = false; + String errMsg = "寮傚父锛�"; + if (staProtocol.isFrontErr()) { + errMsg = errMsg + "鍓嶈秴闄愶紱"; + back = true; + } + if (staProtocol.isBackErr()) { + errMsg = errMsg + "鍚庤秴闄�"; + back = true; + } + if (staProtocol.isHighErr()) { + errMsg = errMsg + "楂樿秴闄�"; + back = true; + } + if (staProtocol.isLeftErr()) { + errMsg = errMsg + "宸﹁秴闄�"; + back = true; + } + if (staProtocol.isRightErr()) { + errMsg = errMsg + "鍙宠秴闄�"; + back = true; + } + if (staProtocol.isWeightErr()) { + errMsg = errMsg + "瓒呴噸"; + back = true; + } + if (staProtocol.isBarcodeErr()) { + errMsg = errMsg + "鎵爜澶辫触"; + back = true; + } + // 閫�鍥� + if (back) { +// // led 寮傚父鏄剧ず +// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); +// if (ledThread != null) { +// MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg)); +// } + continue; + } + // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢 + if (staProtocol.isAutoing() && staProtocol.isLoading() + && staProtocol.isInEnable() + && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999)) + ) { + + // 鑾峰彇鏉$爜鎵弿浠俊鎭� + BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode()); + if (barcodeThread == null) { + continue; + } + String barcode = barcodeThread.getBarcode(); + if (!Cools.isEmpty(barcode)) { +// News.info("{}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", inSta.getBarcode(), barcode); + if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode) || "00000000".equals(barcode)) { +// staProtocol.setWorkNo((short) 32002); +// staProtocol.setStaNo(inSta.getBackSta().shortValue()); +// devpThread.setPakMk(staProtocol.getSiteId(), false); +// MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); + +// // led 寮傚父鏄剧ず +// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); +// if (ledThread != null) { +// String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯"; +// MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); +// } + continue; + } + } else { +// staProtocol.setWorkNo((short) 32002); +// staProtocol.setStaNo(inSta.getBackSta().shortValue()); +// devpThread.setPakMk(staProtocol.getSiteId(), false); +// MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); + +// // led 寮傚父鏄剧ず +// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); +// if (ledThread != null) { +// String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯"; +// MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); +// } + continue; + } + +// // 杩囨护鐩樼偣/鎷f枡/骞舵澘浠诲姟 +// WrkMast wrkMast1 = wrkMastMapper.selectPickStepByBarcode(barcode); +// if (null != wrkMast1) { +// continue; +// } +// +// // 鍒ゆ柇閲嶅宸ヤ綔妗� +// WrkMast wrkMast2 = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode); +// if (wrkMast2 != null) { +// News.error("宸ヤ綔妗d腑宸插瓨鍦ㄨ绔欑姸鎬佷负锛� 2.璁惧涓婅蛋 锛夌殑鏁版嵁,宸ヤ綔鍙�={}", wrkMast2.getWrkNo()); +// continue; +// } +// +// try { +// LocTypeDto locTypeDto = new LocTypeDto(staProtocol); +// SearchLocParam param = new SearchLocParam(); +// param.setBarcode(barcode); +// param.setIoType(1); +// param.setSourceStaNo(inSta.getStaNo()); +// param.setLocType1(locTypeDto.getLocType1()); +// String response = new HttpHandler.Builder() +// .setUri(wmsUrl) +// .setPath("/rpc/pakin/loc/v2") +// .setJson(JSON.toJSONString(param)) +// .build() +// .doPost(); +// JSONObject jsonObject = JSON.parseObject(response); +// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); +// Integer code = jsonObject.getInteger("code"); +// if (code.equals(200)) { +// StartupDto dto = jsonObject.getObject("data", StartupDto.class); +//// 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()); +// if (wrkMast == null) { +// continue; +// } +// +// // 鏇存柊宸ヤ綔涓绘。 +// wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵�侊細2.璁惧涓婅蛋 +// wrkMast.setModiTime(new Date()); +// if (wrkMastMapper.updateById(wrkMast) == 0) { +// News.error("鏇存柊宸ヤ綔妗eけ璐ワ紒锛侊紒 [宸ヤ綔鍙凤細{}]", wrkMast.getWrkNo()); +// } +// +// } else if (code == 500) { +// if (ledThread != null) { +// String errorMsg = jsonObject.getString("msg"); +// if (!Cools.isEmpty(errorMsg)) { +// MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); +// ledThread.setLedMk(false); +// } +// } +// News.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v2", 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)); +// +// // led 寮傚父鏄剧ず +// if (ledThread != null) { +// String errorMsg = barcode + "鎵樼洏璇嗗埆寮傚父锛岃鍏堣繘琛岀粍鎵橈紒"; +// MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); +// ledThread.setLedMk(false); +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); +// } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } } /** @@ -83,7 +273,7 @@ public synchronized void initRealtimeBasMap() { try { List<Dict> dicts = dictService.list(new LambdaQueryWrapper<Dict>() - .like(Dict::getFlag, "map") + .like(Dict::getFlag, "map-") .eq(Dict::getStatus, 1)); TreeMap<Integer, ArrayList<ArrayList<MapNode>>> levData = new TreeMap<>(); @@ -134,7 +324,36 @@ } }); - list.add(nodes); + ArrayList<MapNode> sortNodes = new ArrayList<>(); + int defaultBay = 1;//榛樿浠�1鍒楀紑濮� + for (MapNode node : nodes) { + if (node.getBay() == defaultBay) { + defaultBay++; + sortNodes.add(node); + continue; + } + + //瀛樺湪绌虹己鑺傜偣锛岃嚜鍔ㄨˉ瓒� + for (int i = defaultBay; i < node.getBay(); i++) { + MapNode mapNode = new MapNode(); + mapNode.setValue(-1); + mapNode.setTop(1000); + mapNode.setBottom(1000); + mapNode.setLeft(1000); + mapNode.setRight(1000); + mapNode.setRow(node.getRow()); + mapNode.setBay(i); + mapNode.setNo(node.getRow() + "-" + i); + mapNode.setXBase(0); + mapNode.setYBase(0); + sortNodes.add(mapNode); + } + + defaultBay = node.getBay() + 1; + sortNodes.add(node); + } + + list.add(sortNodes); } levData.put(lev, list); @@ -185,8 +404,11 @@ map.setUpdateTime(now); map.setLev(lev); - //灏嗗湴鍥炬暟鎹瓨鍏edis - redisUtil.set(DeviceRedisConstant.MAP + lev, JSON.toJSONString(map)); + Object data = redisUtil.get(DeviceRedisConstant.MAP + lev); + if (data == null) { + //灏嗗湴鍥炬暟鎹瓨鍏edis + redisUtil.set(DeviceRedisConstant.MAP + lev, JSON.toJSONString(map)); + } } } catch (Exception e) { e.printStackTrace(); -- Gitblit v1.9.1