From 4e1a8e484888b3d3f28dc9629904e6e54d90ebc5 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 28 七月 2023 16:26:40 +0800
Subject: [PATCH] 穿梭车命令封装
---
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 250 ++++++++++++++++++++++++++++++++++++--------------
1 files changed, 180 insertions(+), 70 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 6ef1757..45518cf 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.common.SpringUtils;
import com.core.exception.CoolException;
@@ -202,25 +203,15 @@
// 杩囨护鐩樼偣/鎷f枡/骞舵澘浠诲姟
WrkMast wrkMast1 = wrkMastMapper.selectPickStepByBarcode(barcode);
if (null != wrkMast1) {
- // plc 澶勭悊
- barcodeThread.setBarcode("");
- staProtocol.setWorkNo(wrkMast1.getWrkNo().shortValue());
- staProtocol.setStaNo(wrkMast1.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绔欑偣淇℃伅澶辫触");
- }
continue;
}
// 鍒ゆ柇閲嶅宸ヤ綔妗�
-// WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
-// if (wrkMast != null) {
-// News.error("宸ヤ綔妗d腑宸插瓨鍦ㄨ绔欑姸鎬佷负锛� 2.璁惧涓婅蛋 锛夌殑鏁版嵁,宸ヤ綔鍙�={}", wrkMast.getWrkNo());
-// continue;
-// }
+ WrkMast wrkMast2 = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
+ if (wrkMast2 != null) {
+ News.error("宸ヤ綔妗d腑宸插瓨鍦ㄨ绔欑姸鎬佷负锛� 2.璁惧涓婅蛋 锛夌殑鏁版嵁,宸ヤ綔鍙�={}", wrkMast2.getWrkNo());
+ continue;
+ }
try {
LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
@@ -393,6 +384,7 @@
/**
* 鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱
*/
+ @Transactional
public synchronized void stnToCrnStnPick(){
for (DevpSlave devp : slaveProperties.getDevp()) {
// 閬嶅巻鎷f枡鍏ュ簱鍙�
@@ -408,48 +400,166 @@
}
if (staProtocol.isAutoing()
&& staProtocol.isLoading()
- // 0 - 9990 鎴栬�� 9996
- && (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9990)
+ && (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9999)
&& staProtocol.getStaNo().equals(staProtocol.getSiteId().shortValue())
&& staProtocol.isPakMk()){
// 鑾峰彇鏉$爜鎵弿浠俊鎭�
-// BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
-// if (barcodeThread == null) {
-// continue;
-// }
-
- WrkMast wrkMast = null;
- if (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9990) {
- wrkMast = wrkMastMapper.selectPickStep(staProtocol.getWorkNo());
- if (null == wrkMast) {
- continue;
- }
- } else {
+ BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
+ if (barcodeThread == null) {
continue;
}
+ String barcode = barcodeThread.getBarcode();
+
+ WrkMast wrkMast = null;
+ wrkMast = wrkMastMapper.selectPickStepByBarcode(barcode);
+ if (wrkMast == null) {
+ continue;
+ }
+// if (staProtocol.getWorkNo() == 9996) {
+// String barcode = barcodeThread.getBarcode();
+// if(!Cools.isEmpty(barcode)) {
+// News.info("{}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", pickSta.getBarcode(), barcode);
+// if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
+// 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 寮傚父鏄剧ず
+// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed());
+// if (ledThread != null) {
+// String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
+// MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg));
+// }
+// continue;
+// }
+// } 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));
+//
+// // led 寮傚父鏄剧ず
+// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed());
+// if (ledThread != null) {
+// String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
+// MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg));
+// }
+// continue;
+// }
+// wrkMast = wrkMastMapper.selectPickStepByBarcode(barcode);
+// if (null == wrkMast) {
+// News.error("{}鏉$爜閿欒锛屾殏鏃犳嫞鏂欎换鍔★紒", barcode);
+// }
+// }
if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107)
|| Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo()) ) {
continue;
}
- // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
- if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
- throw new CoolException(wrkMast.getWrkNo() + "淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗eけ璐�");
- }
+ try {
+ // 璁块棶 WMS 鑾峰彇鍏ュ簱搴撲綅
+ LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
+ SearchLocParam param = new SearchLocParam();
+ param.setWrkNo(wrkMast.getWrkNo());
+ param.setIoType(wrkMast.getIoType());
+ param.setSourceStaNo(pickSta.getStaNo());
+// param.setLocType1(locTypeDto.getLocType1());
+ String response = new HttpHandler.Builder()
+ .setUri(wmsUrl)
+ .setPath("/rpc/pakin/loc/v1")
+ .setJson(JSON.toJSONString(param))
+ .build()
+ .doPost();
+ JSONObject jsonObject = JSON.parseObject(response);
+ LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed());
+ Integer code = jsonObject.getInteger("code");
+ if (code.equals(200)) {
+ StartupDto dto = jsonObject.getObject("data", StartupDto.class);
- // 鏇存柊宸ヤ綔妗f暟鎹姸鎬�
- wrkMast.setIoType(wrkMast.getIoType() - 50); // 鍏ュ嚭搴撶被鍨�: 103->53,104->54,107->57
- wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵��: 2.璁惧涓婅蛋
- wrkMast.setSourceLocNo(""); // 婧愬簱浣嶆竻绌�
- wrkMast.setShuttleNo(null); // 绌挎杞︽竻绌�
- wrkMast.setModiTime(new Date());
- if (wrkMastMapper.updateById(wrkMast) == 0) {
- throw new CoolException(wrkMast.getWrkNo() + "鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
- }
- if (wrkMastMapper.setSteEmpty(wrkMast.getWrkNo()) == 0) {
- throw new CoolException(wrkMast.getWrkNo() + "鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
+// // 鑾峰彇鐩爣绔�
+// Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
+// .eq("type_no", wrkMast.getIoType() - 50)
+// .eq("stn_no", pickSta.getStaNo()) // 浣滀笟绔欑偣 = 鎷f枡鍑哄簱鐨勭洰鏍囩珯
+// .eq("crn_no", dto.getCrnNo()); // 鍫嗗灈鏈哄彿
+// StaDesc staDesc = staDescService.selectOne(wrapper);
+// if (Cools.isEmpty(staDesc)) {
+// News.error("鍏ュ簱璺緞涓嶅瓨鍦紒type_no={},stn_no={},crn_no={}", wrkMast.getIoType(), pickSta.getStaNo(), wrkMast.getCrnNo());
+// continue;
+// }
+// // 鍫嗗灈鏈虹珯鐐�(鐩爣绔�)
+// Integer staNo = staDesc.getCrnStn();
+
+ // 淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。
+// if (wrkMastMapper.saveWrkDetlLog(wrkMast.getWrkNo()) == 0) {
+// throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。澶辫触");
+// }
+ // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
+ if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
+ throw new CoolException(wrkMast.getWrkNo() + "淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗eけ璐�");
+ }
+
+ String sourceLocNo = wrkMast.getSourceLocNo().trim();
+ // 鏇存柊宸ヤ綔妗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.setLocNo(sourceLocNo); // 鐩爣搴撲綅 = 鍑哄簱鏃剁殑婧愬簱浣�
+ wrkMast.setShuttleNo(null); // 绌挎杞︽竻绌�
+ wrkMast.setModiTime(new Date());
+ if (wrkMastMapper.updateById(wrkMast) == 0) {
+ throw new CoolException(wrkMast.getWrkNo() + "鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
+ }
+ if (wrkMastMapper.setSteEmpty(wrkMast.getWrkNo()) == 0) {
+ throw new CoolException(wrkMast.getWrkNo() + "鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
+ }
+
+ // 淇敼搴撲綅鐘舵�� Q.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴�
+ LocMast locMast = locMastService.selectById(sourceLocNo);
+ locMast.setLocSts("Q");
+ locMast.setModiTime(new Date());
+ if (!locMastService.updateById(locMast)) {
+ 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());
+ }
+
+ } else if (code == 500){
+ if (ledThread != null) {
+ String errorMsg = jsonObject.getString("msg");
+ if (!Cools.isEmpty(errorMsg)) {
+ MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg));
+ }
+ }
+ 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));
+
+ // led 寮傚父鏄剧ず
+ if (ledThread != null) {
+ String errorMsg = jsonObject.getString("msg");
+// String errorMsg = barcode + "鎵樼洏璇嗗埆寮傚父锛岃鍏堣繘琛岀粍鎵橈紒";
+ MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg));
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
}
@@ -462,7 +572,7 @@
* 鍒濆鍖栧疄鏃跺湴鍥�
*/
public synchronized void initRealtimeBasMap() {
- for (int i = 1; i <= 4; i++) {//鎬诲叡鍥涘眰妤�
+ for (int i = 1; i <= 10; i++) {//鎬诲叡鍥涘眰妤�
Object data = redisUtil.get("realtimeBasMap_" + i);
if (data == null) {//redis鍦板浘鏁版嵁涓虹┖锛屼粠鏁版嵁搴撲腑鑾峰彇
BasMap basMap = basMapService.selectLatestMap(i);
@@ -675,7 +785,7 @@
if (commands == null) {
continue;//鎵句笉鍒拌矾寰勭瓑寰呬笅涓�娆�
}
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
//鍒嗛厤鐩爣搴撲綅
shuttleProtocol.setLocNo(wrkMast.getLocNo());
//鐩爣搴撲綅
@@ -701,7 +811,7 @@
shuttleProtocol.setLocNo(liftSiteLocNo);
//鐩爣搴撲綅
assignCommand.setLocNo(liftSiteLocNo);
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
wrkMast.setWrkSts(5L);//灏忚溅杩佺Щ鐘舵��
}
} else if (wrkMast.getWrkSts() == 8) {
@@ -722,7 +832,7 @@
ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, runDirection, null, null, 500);
commands.add(0, moveCommand);//灏嗚鎸囦护娣诲姞鍒伴槦澶�
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
//鍒嗛厤鐩爣搴撲綅
shuttleProtocol.setLocNo(wrkMast.getLocNo());
//鐩爣搴撲綅
@@ -799,12 +909,12 @@
//鑾峰彇灏忚溅绉诲姩閫熷害
BasShuttle basShuttle = basShuttleService.selectById(assignCommand.getShuttleNo());
Integer runSpeed = 1000;
- if (basShuttle != null) {
- Integer runSpeed1 = basShuttle.getRunSpeed();
- if (runSpeed1 != null) {
- runSpeed = runSpeed1;
- }
- }
+// if (basShuttle != null) {
+// Integer runSpeed1 = basShuttle.getRunSpeed();
+// if (runSpeed1 != null) {
+// runSpeed = runSpeed1;
+// }
+// }
//璁$畻灏忚溅璧风偣鍒颁腑鐐规墍闇�鍛戒护
List<NavigateNode> calc = NavigateUtils.calc(startLocNo, locNo, mapType, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(startLocNo)));
@@ -869,12 +979,12 @@
//鑾峰彇灏忚溅绉诲姩閫熷害
BasShuttle basShuttle = basShuttleService.selectById(assignCommand.getShuttleNo());
Integer runSpeed = 1000;
- if (basShuttle != null) {
- Integer runSpeed1 = basShuttle.getRunSpeed();
- if (runSpeed1 != null) {
- runSpeed = runSpeed1;
- }
- }
+// if (basShuttle != null) {
+// Integer runSpeed1 = basShuttle.getRunSpeed();
+// if (runSpeed1 != null) {
+// runSpeed = runSpeed1;
+// }
+// }
List<NavigateNode> allNode = new ArrayList<>();
@@ -1130,7 +1240,7 @@
shuttleProtocol.setSourceLocNo(currentLocNo);
//鐩爣搴撲綅
assignCommand.setLocNo(wrkMast.getSourceLocNo());
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
wrkMast.setWrkSts(26L);//灏忚溅鎼繍涓�
if (wrkMastMapper.updateById(wrkMast) > 0) {
@@ -1164,7 +1274,7 @@
//鐩爣搴撲綅
assignCommand.setLocNo(liftSiteLocNo);
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
wrkMast.setWrkSts(22L);//灏忚溅杩佺Щ鐘舵��
if (wrkMastMapper.updateById(wrkMast) > 0) {
@@ -1211,7 +1321,7 @@
shuttleProtocol.setSourceLocNo(liftSiteLocNo);
//鐩爣搴撲綅
assignCommand.setLocNo(wrkMast.getSourceLocNo());
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
wrkMast.setWrkSts(26L);//灏忚溅鎼繍涓�
if (wrkMastMapper.updateById(wrkMast) > 0) {
@@ -1762,7 +1872,7 @@
//鎵�闇�鍛戒护缁勫悎瀹屾瘯锛屾洿鏂版暟鎹簱锛屾彁浜ゅ埌绾跨▼鍘诲伐浣�
LiftAssignCommand assignCommand = new LiftAssignCommand();
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
assignCommand.setLiftNo(liftProtocol.getLiftNo());
assignCommand.setTaskNo(liftProtocol.getTaskNo());
if (wrkMastMapper.updateById(wrkMast) > 0) {
@@ -2016,7 +2126,7 @@
shuttleProtocol.setLocNo(liftSiteLocNo);
//鐩爣搴撲綅
assignCommand.setLocNo(liftSiteLocNo);
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
wrkMast.setWrkSts(5L);//灏忚溅杩佺Щ鐘舵��
if (wrkMastMapper.updateById(wrkMast) > 0) {
@@ -2123,7 +2233,7 @@
//鍒嗛厤婧愬簱浣�
shuttleProtocol.setSourceLocNo(wrkMast.getSourceLocNo());
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
//鍒嗛厤鐩爣搴撲綅
shuttleProtocol.setLocNo(wrkMast.getLocNo());
//鐩爣搴撲綅
@@ -2641,7 +2751,7 @@
commands.add(command);
//鎸囦护闆嗗垎閰�
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
wrkCharge.setWrkSts(56L);//鍏呯數涓姸鎬�
if (wrkChargeMapper.updateById(wrkCharge) > 0) {
@@ -2683,7 +2793,7 @@
assignCommand.setLocNo(chargeLocNo);
//婧愬簱浣�
assignCommand.setSourceLocNo(currentLocNo);
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
wrkCharge.setWrkSts(52L);//灏忚溅杩佺Щ鐘舵��
if (wrkChargeMapper.updateById(wrkCharge) > 0) {
//涓嬪彂浠诲姟
@@ -2721,7 +2831,7 @@
wrkCharge.setWrkSts(54L);//鎻愬崌鏈烘惉杩愪腑
//鎵�闇�鍛戒护缁勫悎瀹屾瘯锛屾洿鏂版暟鎹簱锛屾彁浜ゅ埌绾跨▼鍘诲伐浣�
LiftAssignCommand assignCommand = new LiftAssignCommand();
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
assignCommand.setLiftNo(liftProtocol.getLiftNo());
assignCommand.setTaskNo(liftProtocol.getTaskNo());
if (wrkChargeMapper.updateById(wrkCharge) > 0) {
@@ -2776,7 +2886,7 @@
commands.add(command);
//鎸囦护闆嗗垎閰�
- assignCommand.setCommands(commands);
+// assignCommand.setCommands(commands);
wrkCharge.setWrkSts(56L);//鍏呯數涓姸鎬�
if (wrkChargeMapper.updateById(wrkCharge) > 0) {
--
Gitblit v1.9.1