From 94e8a0258a696ecd8a9a1400eabb802bf8628397 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期二, 14 十月 2025 13:47:05 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/impl/NyLiftThread.java | 306 +++++++++++++++++++++++++++++---------------------
1 files changed, 178 insertions(+), 128 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/NyLiftThread.java b/src/main/java/com/zy/core/thread/impl/NyLiftThread.java
index 0ff3b77..d1ade24 100644
--- a/src/main/java/com/zy/core/thread/impl/NyLiftThread.java
+++ b/src/main/java/com/zy/core/thread/impl/NyLiftThread.java
@@ -3,13 +3,10 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
-import com.zy.asrs.entity.BasLift;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.entity.DeviceDataLog;
-import com.zy.asrs.service.BasLiftService;
import com.zy.asrs.service.DeviceDataLogService;
import com.zy.asrs.utils.Utils;
import com.zy.common.ExecuteSupport;
@@ -45,10 +42,11 @@
private DeviceConfig device;
private LiftProtocol liftProtocol;
private RedisUtil redisUtil;
- LiftPointModel liftPointModel;
+ private LiftPointModel liftPointModel;
private List<LiftStaProtocol> liftStaProtocols = new ArrayList<>();
private List<DeviceMsgModel> readResultList = new ArrayList<>();
private List<DeviceMsgModel> resultList = new ArrayList<>();
+ private String realtimeOriginData = "";
public NyLiftThread(DeviceConfig device, LiftPointModel liftPointModel, List<LiftStation> stationList, RedisUtil redisUtil) {
this.device = device;
@@ -57,7 +55,7 @@
//鍒濆鍖栫珯鐐�
for (LiftStation station : stationList) {
LiftStaProtocol liftStaProtocol = new LiftStaProtocol();
- liftStaProtocol.setStaNo(station.getStaNo());//绔欑偣鍙�
+ liftStaProtocol.setSiteId(station.getSiteId());//绔欑偣鍙�
liftStaProtocol.setLev(station.getLev());//绔欑偣妤煎眰
String locNo = Utils.getLocNo(station.getRow(), station.getBay(), station.getLev());
liftStaProtocol.setLocNo(locNo);//绔欑偣搴撲綅鍙�
@@ -87,7 +85,7 @@
try {
listenMessageFromRedis();
readStatus();
- Thread.sleep(100);
+ Thread.sleep(200);
} catch (Exception e) {
log.error("LiftThread Fail", e);
}
@@ -95,13 +93,18 @@
});
readThread.start();
- while (true) {
- try {
- execute();
- } catch (Exception e) {
- e.printStackTrace();
+ //璁惧鎵ц
+ Thread executeThread = new Thread(() -> {
+ while (true) {
+ try {
+ execute();
+ Thread.sleep(200);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
- }
+ });
+ executeThread.start();
}
private void execute() {
@@ -183,8 +186,6 @@
liftProtocol.setHasTray(data.getInteger("hasTray") == 1);
//鏈夊皬杞�
liftProtocol.setHasCar(data.getInteger("hasCar") == 1);
- //鍑哄叆搴撴ā寮�
- liftProtocol.setIOMode(data.getInteger("iOMode"));
//鏁呴殰鐮�
liftProtocol.setErrorCode(data.getInteger("errorCode"));
//褰撳墠灞�
@@ -193,28 +194,49 @@
//************琛ュ厖鎵╁睍瀛楁*************
InnerLiftExtend liftExtend = (InnerLiftExtend) liftProtocol.getExtend();
liftProtocol.setExtend(liftExtend);
- liftExtend.setFrontOverrun(data.getBoolean("frontOverrun"));
- liftExtend.setBackOverrun(data.getBoolean("backOverrun"));
- liftExtend.setLeftOverrun(data.getBoolean("leftOverrun"));
- liftExtend.setRightOverrun(data.getBoolean("rightOverrun"));
- liftExtend.setOverHeight(data.getBoolean("overHeight"));
- liftExtend.setOverWeight(data.getBoolean("overWeight"));
+ JSONObject extend = data.getJSONObject("extend");
+ liftExtend.setFrontOverrun(extend.getInteger("frontOverrun") == 1);
+ liftExtend.setBackOverrun(extend.getInteger("backOverrun") == 1);
+ liftExtend.setLeftOverrun(extend.getInteger("leftOverrun") == 1);
+ liftExtend.setRightOverrun(extend.getInteger("rightOverrun") == 1);
+ liftExtend.setOverHeight(extend.getInteger("overHeight") == 1);
+ liftExtend.setOverWeight(extend.getInteger("overWeight") == 1);
+ liftExtend.setPlcTaskNoComplete(extend.getInteger("plcTaskNoComplete"));
- JSONArray trayList = data.getJSONArray("trayList");
- for (int i = 0; i < trayList.size(); i++) {
- int hasTray = (int) trayList.get(i);
- LiftStaProtocol liftStaProtocol = liftStaProtocols.get(i);
- liftStaProtocol.setHasTray(hasTray == 1);
+ if (!liftExtend.getPlcTaskNoComplete().equals(liftProtocol.getPlcTaskNo())) {
+ //璁惧鐘舵��
+ liftProtocol.setDeviceStatus(LiftDeviceStatusType.BUSY.id);
}
- JSONArray carList = data.getJSONArray("carList");
- for (int i = 0; i < carList.size(); i++) {
- int hasCar = (int) carList.get(i);
- LiftStaProtocol liftStaProtocol = liftStaProtocols.get(i);
- liftStaProtocol.setHasCar(hasCar == 1);
+ //璇诲彇绔欑偣
+ JSONArray stationList = data.getJSONArray("stationList");
+ if (stationList != null) {
+ for (int i = 0; i < stationList.size(); i++) {
+ JSONObject staObj = stationList.getJSONObject(i);
+ LiftStaProtocol liftStaProtocol = null;
+ for (LiftStaProtocol staProtocol : liftStaProtocols) {
+ if(staProtocol.getSiteId().equals(staObj.getInteger("siteId"))){
+ liftStaProtocol = staProtocol;
+ break;
+ }
+ }
+
+ if(liftStaProtocol == null){
+ continue;
+ }
+
+ liftStaProtocol.setModel(staObj.getInteger("model") == 1);
+ liftStaProtocol.setBusy(staObj.getInteger("busy") == 1);
+ liftStaProtocol.setHasTray(staObj.getInteger("hasTray") == 1);
+ liftStaProtocol.setDeviceError(staObj.getInteger("deviceError") == 1);
+ liftStaProtocol.setTaskNo(staObj.getInteger("taskNo"));
+ liftStaProtocol.setBarcode(staObj.getString("barcode"));
+ }
}
- if (System.currentTimeMillis() - liftProtocol.getDeviceDataLog() > 1000 * 5) {
+ this.realtimeOriginData = JSON.toJSONString(data);
+
+ if (System.currentTimeMillis() - liftProtocol.getDeviceDataLog() > 1000 * 2) {
//閲囬泦鏃堕棿瓒呰繃5s锛屼繚瀛樹竴娆℃暟鎹褰�
//淇濆瓨鏁版嵁璁板綍
DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
@@ -230,27 +252,7 @@
liftProtocol.setDeviceDataLog(System.currentTimeMillis());
}
- //灏嗘彁鍗囨満鐘舵�佷繚瀛樿嚦鏁版嵁搴�
- BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class);
- BasLift basLift = basLiftService.selectOne(new EntityWrapper<BasLift>()
- .eq("lift_no", device.getDeviceNo()));
- if (basLift == null) {
- basLift = new BasLift();
- //鎻愬崌鏈哄彿
- basLift.setLiftNo(liftProtocol.getLiftNo());
- basLift.setStatus(1);
- basLiftService.insert(basLift);
- }
- //浠诲姟鍙�
- basLift.setWrkNo(liftProtocol.getTaskNo());
- //淇敼鏃堕棿
- basLift.setUpdateTime(new Date());
- //璁惧鐘舵��
- basLift.setDeviceStatus(JSON.toJSONString(liftProtocol));
- if (basLiftService.updateById(basLift)) {
- OutputQueue.LIFT.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), liftProtocol.getLiftNo()));
- }
-
+ OutputQueue.LIFT.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), liftProtocol.getLiftNo()));
} catch (Exception e) {
e.printStackTrace();
OutputQueue.LIFT.offer(MessageFormat.format("銆恵0}銆戣鍙栨彁鍗囨満鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), device.getDeviceNo(), device.getIp(), device.getPort()));
@@ -354,59 +356,18 @@
}
@Override
- public CommandResponse switchIOMode(LiftCommand command) {
- CommandResponse response = new CommandResponse(false);
- try {
- //鍙戝嚭璇锋眰
- String resultKey = requestCommand(command);
- //鏌ヨ璇锋眰缁撴灉
- JSONObject result = queryCommandStatus(resultKey);
- if (result == null) {
- return response;//璇锋眰澶辫触
- }
- if(!result.getString("result").equals("success")) {
- return response;//璇锋眰澶辫触
- }
-
- this.liftProtocol.setSendTime(System.currentTimeMillis());//鎸囦护涓嬪彂鏃堕棿
- response.setMessage(JSON.toJSONString(result));
- response.setResult(true);
- return response;
- } catch (Exception e) {
- e.printStackTrace();
- response.setMessage(e.getMessage());
- return response;
- }
+ public CommandResponse switchIOMode(LiftIoModeType type) {
+ CommandResponse response = new CommandResponse(true);
+ liftProtocol.setIOMode(type);
+ return response;
}
@Override
public CommandResponse reset() {
- CommandResponse response = new CommandResponse(false);
- try {
- LiftCommand resetCommand = getResetCommand(9999);
-
- //鍙戝嚭璇锋眰
- String resultKey = requestCommand(resetCommand);
- //鏌ヨ璇锋眰缁撴灉
- JSONObject result = queryCommandStatus(resultKey);
- if (result == null) {
- return response;//璇锋眰澶辫触
- }
- if(!result.getString("result").equals("success")) {
- return response;//璇锋眰澶辫触
- }
-
- this.liftProtocol.setSendTime(System.currentTimeMillis());//鎸囦护涓嬪彂鏃堕棿
- this.setSyncTaskNo(0);
- this.setProtocolStatus(LiftProtocolStatusType.IDLE);
- response.setMessage(JSON.toJSONString(result));
- response.setResult(true);
- return response;
- } catch (Exception e) {
- e.printStackTrace();
- response.setMessage(e.getMessage());
- return response;
- }
+ CommandResponse response = new CommandResponse(true);
+ this.setSyncTaskNo(0);
+ this.setProtocolStatus(LiftProtocolStatusType.IDLE);
+ return response;
}
@Override
@@ -415,6 +376,7 @@
|| this.liftProtocol.getPlcTaskNo() == null
|| this.liftProtocol.getProtocolStatus() == null
|| this.liftProtocol.getModel() == null
+ || this.liftProtocol.getDeviceStatus() == null
|| this.liftProtocol.getErrorCode() == null
|| this.liftProtocol.getExtend() == null
) {
@@ -423,19 +385,51 @@
InnerLiftExtend extend = (InnerLiftExtend) this.liftProtocol.getExtend();
- boolean res = this.liftProtocol.getProtocolStatus() == LiftProtocolStatusType.IDLE.id
-// && this.liftProtocol.getPlcTaskNo() == 0
- && this.liftProtocol.getTaskNo() == 0
- && this.liftProtocol.getModel() == 2
- && this.liftProtocol.getErrorCode() == 0
- && !extend.getFrontOverrun()
- && !extend.getBackOverrun()
- && !extend.getLeftOverrun()
- && !extend.getRightOverrun()
- && !extend.getOverHeight()
- && !extend.getOverWeight()
- ;
- return res;
+ if (this.liftProtocol.getProtocolStatus() != LiftProtocolStatusType.IDLE.id) {
+ return false;//浠诲姟涓嶇┖闂�
+ }
+
+ if (this.liftProtocol.getTaskNo() != 0) {
+ return false;//鏈変换鍔″彿
+ }
+
+ if (this.liftProtocol.getModel() != 2) {
+ return false;//闈炶嚜鍔�
+ }
+
+ if (this.liftProtocol.getDeviceStatus() != LiftDeviceStatusType.IDLE.id) {
+ return false;//闈炵┖闂�
+ }
+
+ if (this.liftProtocol.getErrorCode() != 0) {
+ return false;//鏈夋晠闅�
+ }
+
+ if (extend.getFrontOverrun()) {
+ return false;
+ }
+
+ if (extend.getBackOverrun()) {
+ return false;
+ }
+
+ if (extend.getLeftOverrun()) {
+ return false;
+ }
+
+ if (extend.getRightOverrun()) {
+ return false;
+ }
+
+ if (extend.getOverHeight()) {
+ return false;
+ }
+
+ if (extend.getOverWeight()) {
+ return false;
+ }
+
+ return true;
}
@Override
@@ -452,8 +446,8 @@
}
}
- if (this.liftProtocol.getProtocolStatus() == null
- || this.liftProtocol.getModel() == null
+ if (this.liftProtocol.getModel() == null
+ || this.liftProtocol.getDeviceStatus() == null
|| this.liftProtocol.getErrorCode() == null
|| this.liftProtocol.getExtend() == null
) {
@@ -462,17 +456,43 @@
InnerLiftExtend extend = (InnerLiftExtend) this.liftProtocol.getExtend();
- boolean res = this.liftProtocol.getProtocolStatus() == LiftProtocolStatusType.IDLE.id
- && this.liftProtocol.getModel() == 2
- && this.liftProtocol.getErrorCode() == 0
- && !extend.getFrontOverrun()
- && !extend.getBackOverrun()
- && !extend.getLeftOverrun()
- && !extend.getRightOverrun()
- && !extend.getOverHeight()
- && !extend.getOverWeight()
- ;
- return res;
+ if (this.liftProtocol.getModel() != 2) {
+ return false;//闈炶嚜鍔�
+ }
+
+ if (this.liftProtocol.getDeviceStatus() != LiftDeviceStatusType.IDLE.id) {
+ return false;//闈炵┖闂�
+ }
+
+ if (this.liftProtocol.getErrorCode() != 0) {
+ return false;//鏈夋晠闅�
+ }
+
+ if (extend.getFrontOverrun()) {
+ return false;
+ }
+
+ if (extend.getBackOverrun()) {
+ return false;
+ }
+
+ if (extend.getLeftOverrun()) {
+ return false;
+ }
+
+ if (extend.getRightOverrun()) {
+ return false;
+ }
+
+ if (extend.getOverHeight()) {
+ return false;
+ }
+
+ if (extend.getOverWeight()) {
+ return false;
+ }
+
+ return true;
}
@Override
@@ -483,7 +503,8 @@
@Override
public boolean setSyncTaskNo(Integer taskNo) {
- this.liftProtocol.setSyncTaskNo(taskNo);
+ redisUtil.setSync(RedisKeyType.LIFT_FLAG.key + liftProtocol.getLiftNo(), taskNo);
+ this.liftProtocol.setTaskNo(taskNo);
return true;
}
@@ -501,6 +522,11 @@
}
@Override
+ public String getRealtimeOriginData() {
+ return this.realtimeOriginData;
+ }
+
+ @Override
public LiftCommand getPickAndPutCommand(Integer taskNo, Integer pick, Integer put) {
LiftCommand command = new LiftCommand();
command.setLiftNo(device.getDeviceNo());
@@ -509,6 +535,10 @@
command.setPick(pick);
command.setPut(put);
+ LiftStaProtocol pickSta = findSta(pick);
+ LiftStaProtocol putSta = findSta(put);
+ command.setPickLev(pickSta.getLev());
+ command.setPutLev(putSta.getLev());
return command;
}
@@ -521,6 +551,10 @@
command.setPick(pick);
command.setPut(put);
+ LiftStaProtocol pickSta = findSta(pick);
+ LiftStaProtocol putSta = findSta(put);
+ command.setPickLev(pickSta.getLev());
+ command.setPutLev(putSta.getLev());
return command;
}
@@ -533,6 +567,10 @@
command.setPick(pick);
command.setPut(put);
+ LiftStaProtocol pickSta = findSta(pick);
+ LiftStaProtocol putSta = findSta(put);
+ command.setPickLev(pickSta.getLev());
+ command.setPutLev(putSta.getLev());
return command;
}
@@ -657,6 +695,15 @@
}
}
+ private LiftStaProtocol findSta(Integer staNo) {
+ for (LiftStaProtocol liftStaProtocol : this.liftStaProtocols) {
+ if (liftStaProtocol.getSiteId().equals(staNo)) {
+ return liftStaProtocol;
+ }
+ }
+ return null;
+ }
+
/**
* 鎵╁睍瀛楁
*/
@@ -693,5 +740,8 @@
*/
private Boolean overWeight;
+ //PLC宸插畬鎴愪换鍔″彿
+ private Integer plcTaskNoComplete;
+
}
}
--
Gitblit v1.9.1