From 728ad81fa10d2879654c5f9ae4314db94eafb865 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期五, 01 八月 2025 08:08:18 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/NyShuttleThread.java |  223 +++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 149 insertions(+), 74 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
index e8a72d4..312b527 100644
--- a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -9,10 +9,8 @@
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.zy.asrs.entity.BasShuttle;
 import com.zy.asrs.entity.DeviceConfig;
-import com.zy.asrs.entity.DeviceDataLog;
 import com.zy.asrs.entity.LocMast;
 import com.zy.asrs.service.BasShuttleService;
-import com.zy.asrs.service.DeviceDataLogService;
 import com.zy.asrs.service.LocMastService;
 import com.zy.asrs.utils.Utils;
 import com.zy.common.ExecuteSupport;
@@ -22,10 +20,12 @@
 import com.zy.common.utils.NavigateMapData;
 import com.zy.common.utils.NavigatePositionConvert;
 import com.zy.common.utils.RedisUtil;
+import com.zy.common.utils.ShuttleOperaUtils;
 import com.zy.core.News;
-import com.zy.core.model.DeviceCommandMsgModel;
-import com.zy.core.utils.DeviceMsgUtils;
 import com.zy.core.action.ShuttleAction;
+import com.zy.core.model.DeviceCommandMsgModel;
+import com.zy.core.model.command.ShuttleAssignCommand;
+import com.zy.core.utils.DeviceMsgUtils;
 import com.zy.core.cache.OutputQueue;
 import com.zy.core.enums.*;
 import com.zy.core.model.CommandResponse;
@@ -52,6 +52,7 @@
     private DeviceConfig deviceConfig;
     private RedisUtil redisUtil;
     private ShuttleProtocol shuttleProtocol;
+    private ShuttleAction shuttleAction = null;
 
     private static final boolean DEBUG = false;//璋冭瘯妯″紡
 
@@ -79,19 +80,6 @@
                     readStatus();
                     Thread.sleep(100);
 
-                    ShuttleAction shuttleAction = null;
-                    try {
-                        shuttleAction = SpringUtils.getBean(ShuttleAction.class);
-                    }catch (Exception e){
-                        continue;
-                    }
-
-                    if (shuttleAction == null) {
-                        continue;
-                    }
-                    //婕旂ず妯″紡
-                    shuttleAction.demo(deviceConfig.getDeviceNo());
-
 //                    //灏忚溅绌洪棽涓旀湁璺戝簱绋嬪簭
 //                    shuttleAction.moveLoc(deviceConfig.getDeviceNo());
                 } catch (Exception e) {
@@ -105,14 +93,11 @@
         Thread executeThread = new Thread(() -> {
             while (true) {
                 try {
-                    ShuttleAction shuttleAction = null;
-                    try {
-                        shuttleAction = SpringUtils.getBean(ShuttleAction.class);
-                    }catch (Exception e){
-                        continue;
-                    }
-
                     if (shuttleAction == null) {
+                        try {
+                            shuttleAction = SpringUtils.getBean(ShuttleAction.class);
+                        }catch (Exception e){
+                        }
                         continue;
                     }
 
@@ -133,46 +118,6 @@
             }
         });
         executeThread.start();
-
-//        //鍏朵粬浠诲姟
-//        Thread otherThread = new Thread(() -> {
-//            while (true) {
-//                try {
-//                    saveLog();//淇濆瓨鏁版嵁
-//                } catch (Exception e) {
-//                    e.printStackTrace();
-//                }
-//            }
-//        });
-//        otherThread.start();
-    }
-
-    private void saveLog() {
-        if (shuttleProtocol == null) {
-            return;
-        }
-
-        if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 1000 * 5) {
-            if (this.originDeviceData != null) {
-                //閲囬泦鏃堕棿瓒呰繃5s锛屼繚瀛樹竴娆℃暟鎹褰�
-                //淇濆瓨鏁版嵁璁板綍
-                DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
-                if (deviceDataLogService == null) {
-                    return;
-                }
-                DeviceDataLog deviceDataLog = new DeviceDataLog();
-                deviceDataLog.setOriginData(JSON.toJSONString(this.originDeviceData));
-                deviceDataLog.setWcsData(JSON.toJSONString(shuttleProtocol));
-                deviceDataLog.setType(String.valueOf(SlaveType.Shuttle));
-                deviceDataLog.setDeviceNo(deviceConfig.getDeviceNo());
-                deviceDataLog.setCreateTime(new Date());
-                deviceDataLogService.insert(deviceDataLog);
-
-                //鏇存柊閲囬泦鏃堕棿
-                shuttleProtocol.setDeviceDataLog(System.currentTimeMillis());
-                OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), deviceConfig.getDeviceNo()));
-            }
-        }
     }
 
     private void listenMessageFromRedis() {
@@ -788,7 +733,7 @@
                 //灏嗚矾寰勯攣涓庡皬杞﹁矾寰勮繘琛屽尮閰�
                 ArrayList<NavigateNode> tmp = new ArrayList<>();
                 //妫�娴嬭矾寰勬槸鍚﹁閿佸畾
-                int[][] map = navigateMapData.getDataFromRedis(lev, NavigationMapType.DFX.id, null, null);
+                int[][] map = navigateMapData.getDataFromRedis(lev, NavigationMapType.getDfxWithDevice(), null, null);
                 for (NavigateNode node : path) {
                     if(map[node.getX()][node.getY()] == -999) {
                         tmp.add(node);
@@ -808,6 +753,9 @@
 
     @Override
     public synchronized boolean setProtocolStatus(ShuttleProtocolStatusType status) {
+        if (status.equals(ShuttleProtocolStatusType.IDLE)) {
+            this.shuttleProtocol.setIdleTime(System.currentTimeMillis());
+        }
         this.shuttleProtocol.setProtocolStatus(status);
         return true;
     }
@@ -877,6 +825,18 @@
     }
 
     @Override
+    public boolean setTrafficControl(boolean enable, List<NavigateNode> nodeList) {
+        shuttleProtocol.setTrafficControl(enable);
+        shuttleProtocol.setTrafficControlNodes(nodeList);
+        return true;
+    }
+
+    @Override
+    public void updateDeviceDataLogTime(long time) {
+        shuttleProtocol.setDeviceDataLog(time);
+    }
+
+    @Override
     public JSONObject parseStatusToMsg(ShuttleProtocol shuttleProtocol) {
         JSONObject result = new JSONObject();
         result.put("msgType", "responseMsg");
@@ -890,6 +850,116 @@
         body.put("responseType", "state");
 
         return null;
+    }
+
+    @Override
+    public boolean restartCalcPath() {
+        ConfigService configService = SpringUtils.getBean(ConfigService.class);
+        if (configService == null) {
+            return false;
+        }
+
+        ShuttleAction shuttleAction = SpringUtils.getBean(ShuttleAction.class);
+        if (shuttleAction == null) {
+            return false;
+        }
+
+        ShuttleOperaUtils shuttleOperaUtils = SpringUtils.getBean(ShuttleOperaUtils.class);
+        if (shuttleOperaUtils == null) {
+            return false;
+        }
+
+        ObjectMapper objectMapper = SpringUtils.getBean(ObjectMapper.class);
+        if (objectMapper == null) {
+            return false;
+        }
+
+        boolean trafficControlRestartCalcPath = false;
+        Config trafficControlRestartCalcPathConfig = configService.selectOne(new EntityWrapper<Config>()
+                .eq("code", "trafficControlRestartCalcPath")
+        );
+        if(trafficControlRestartCalcPathConfig != null) {
+            trafficControlRestartCalcPath = trafficControlRestartCalcPathConfig.getValue().equals("Y") ? true : false;
+        }
+
+        if (!trafficControlRestartCalcPath) {
+            return false;
+        }
+
+        if (shuttleProtocol.getTaskNo() == 0) {
+            return false;
+        }
+
+        if (!this.isDeviceIdle()) {
+            return false;
+        }
+
+        Object object = redisUtil.get(RedisKeyType.SHUTTLE_RESTART_CALC_PATH.key + shuttleProtocol.getShuttleNo());
+        if (object != null) {
+            return false;
+        }
+
+        Integer taskNo = shuttleProtocol.getTaskNo();
+        Object obj = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + taskNo);
+        if (obj == null) {
+            return false;
+        }
+
+        ShuttleRedisCommand redisCommand = null;
+        try {
+            redisCommand = objectMapper.readValue(String.valueOf(obj), ShuttleRedisCommand.class);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+        if (redisCommand == null) {
+            return false;
+        }
+
+        ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
+        String locNo = assignCommand.getLocNo();
+        List<NavigationMapType> mapTypes = assignCommand.getMapTypes();
+        if (locNo == null) {
+            return false;
+        }
+
+        if (mapTypes == null) {
+            return false;
+        }
+
+        String currentLocNo = shuttleProtocol.getCurrentLocNo();
+        List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(currentLocNo, locNo, mapTypes, assignCommand, this);
+        if (commands == null) {
+            return false;
+        }
+
+        if (assignCommand.getTaskMode() == ShuttleTaskModeType.TRANSPORT.id) {
+            List<ShuttleCommand> originCommands = assignCommand.getCommands();
+            if (originCommands == null) {
+                return false;
+            }
+
+            ShuttleCommand firstCommand = originCommands.get(0);
+            ShuttleCommand endCommand = originCommands.get(originCommands.size() - 1);
+
+            if (firstCommand.getMode() != ShuttleCommandModeType.PALLET_LIFT.id) {
+                return false;
+            }
+
+            if (endCommand.getMode() != ShuttleCommandModeType.PALLET_DOWN.id) {
+                return false;
+            }
+
+            commands.add(0, firstCommand);
+            commands.add(endCommand);
+        }
+
+        assignCommand.setCommands(commands);
+
+        //涓嬪彂浠诲姟
+        shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
+        redisUtil.set(RedisKeyType.SHUTTLE_RESTART_CALC_PATH.key + shuttleProtocol.getShuttleNo(), true, 60);
+        return true;
     }
 
     @Override
@@ -918,7 +988,7 @@
             int yp = Integer.parseInt(String.valueOf(nyNode.get("x")));
             int z = Integer.parseInt(String.valueOf(nyNode.get("z")));
 
-            List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.NONE.id, null, null);
+            List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);
             List<MapNode> mapNodes = mapData.get(node.getX());
             MapNode mapNode = mapNodes.get(node.getY());
 
@@ -1034,7 +1104,7 @@
             throw new CoolException("鍦板潃鐮佷笉瀛樺湪");
         }
 
-        List<List<MapNode>> mapData = navigateMapData.getJsonData(lev, NavigationMapType.NONE.id, null, null);
+        List<List<MapNode>> mapData = navigateMapData.getJsonData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);
         List<MapNode> mapNodes = mapData.get(locMast.getRow1());
         MapNode mapNode = mapNodes.get(locMast.getBay1());
 
@@ -1142,16 +1212,16 @@
 
     private JSONObject queryCommandStatus(String resultKey) {
         // 鑾峰彇鏈嶅姟鍣ㄥ搷搴�
-        // 灏濊瘯50娆�
         JSONObject result = null;
-        for (int i = 0; i < 50; i++) {
+        long startTime = System.currentTimeMillis();
+        while (true) {
+            if((System.currentTimeMillis() - startTime) > 1000 * 10) {
+                break;
+            }
+
             result = getRequestBody(resultKey);
             if (result == null) {
-                try {
-                    Thread.sleep(500);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
+                continue;
             }else {
                 break;
             }
@@ -1208,6 +1278,11 @@
         return new int[]{data.getInteger("y"), data.getInteger("x"), z};
     }
 
+    @Override
+    public Object getOriginDeviceData() {
+        return this.originDeviceData;
+    }
+
     @Data
     private class InnerSuhttleExtend {
 

--
Gitblit v1.9.1