From 98e6dd8f3597a36512699151a7f74b6cf733268f Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期五, 19 九月 2025 14:06:03 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/NyLiftThread.java |  110 +++++++++++++++++++++++-------------------------------
 1 files changed, 47 insertions(+), 63 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 e5a01e7..b495438 100644
--- a/src/main/java/com/zy/core/thread/impl/NyLiftThread.java
+++ b/src/main/java/com/zy/core/thread/impl/NyLiftThread.java
@@ -45,10 +45,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 +58,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);//绔欑偣搴撲綅鍙�
@@ -160,7 +161,7 @@
             if (null == liftProtocol) {
                 liftProtocol = new LiftProtocol();
                 liftProtocol.setLiftNo(device.getDeviceNo());
-                liftProtocol.setProtocolStatus(LiftProtocolStatusType.NONE);
+                liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
 
                 InnerLiftExtend innerLiftExtend = new InnerLiftExtend();
                 liftProtocol.setExtend(innerLiftExtend);
@@ -171,8 +172,8 @@
             liftProtocol.setModel(data.getInteger("model"));
             //PLC浠诲姟鍙�
             liftProtocol.setPlcTaskNo(data.getInteger("plcTaskNo"));
-            //浠诲姟鐘舵��
-            liftProtocol.setProtocolStatus(data.getInteger("protocolStatus"));
+            //璁惧鐘舵��
+            liftProtocol.setDeviceStatus(data.getInteger("deviceStatus"));
             //浠诲姟妯″紡
             liftProtocol.setTaskMode(data.getInteger("taskMode"));
             //鍙栬揣鏁版嵁
@@ -200,19 +201,33 @@
             liftExtend.setOverHeight(data.getBoolean("overHeight"));
             liftExtend.setOverWeight(data.getBoolean("overWeight"));
 
-            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);
+            //璇诲彇绔欑偣
+            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"));
+                }
             }
 
-            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);
-            }
+            this.realtimeOriginData = JSON.toJSONString(data);
 
             if (System.currentTimeMillis() - liftProtocol.getDeviceDataLog() > 1000 * 5) {
                 //閲囬泦鏃堕棿瓒呰繃5s锛屼繚瀛樹竴娆℃暟鎹褰�
@@ -230,27 +245,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()));
@@ -381,30 +376,10 @@
 
     @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());//鎸囦护涓嬪彂鏃堕棿
-            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
@@ -422,7 +397,7 @@
         InnerLiftExtend extend = (InnerLiftExtend) this.liftProtocol.getExtend();
 
         boolean res = this.liftProtocol.getProtocolStatus() == LiftProtocolStatusType.IDLE.id
-                && this.liftProtocol.getPlcTaskNo() == 0
+//                && this.liftProtocol.getPlcTaskNo() == 0
                 && this.liftProtocol.getTaskNo() == 0
                 && this.liftProtocol.getModel() == 2
                 && this.liftProtocol.getErrorCode() == 0
@@ -481,7 +456,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;
     }
 
@@ -496,6 +472,11 @@
             return null;
         }
         return Utils.getLocNo(liftPointModel.getRow(), liftPointModel.getBay(), liftProtocol.getLev());
+    }
+
+    @Override
+    public String getRealtimeOriginData() {
+        return this.realtimeOriginData;
     }
 
     @Override
@@ -691,5 +672,8 @@
          */
         private Boolean overWeight;
 
+        //鎻愬崌鏈虹珯鐐�
+        private List<LiftStaProtocol> liftStaProtocols;
+
     }
 }

--
Gitblit v1.9.1