From ed265ddfb8f08f69af064a9adf65fcbf06289ffe Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期二, 11 二月 2025 14:07:54 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/action/ShuttleAction.java |  109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 104 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/zy/core/action/ShuttleAction.java b/src/main/java/com/zy/core/action/ShuttleAction.java
index fb12232..09fc279 100644
--- a/src/main/java/com/zy/core/action/ShuttleAction.java
+++ b/src/main/java/com/zy/core/action/ShuttleAction.java
@@ -2,19 +2,25 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.zy.asrs.entity.BasShuttleOpt;
+import com.zy.asrs.entity.LocMast;
+import com.zy.asrs.entity.WrkMast;
 import com.zy.asrs.service.BasShuttleOptService;
 import com.zy.asrs.service.BasShuttleService;
 import com.zy.asrs.service.LocMastService;
+import com.zy.asrs.service.WrkMastService;
 import com.zy.asrs.utils.Utils;
 import com.zy.common.ExecuteSupport;
 import com.zy.common.model.NavigateNode;
 import com.zy.common.utils.NavigateMapUtils;
 import com.zy.common.utils.RedisUtil;
+import com.zy.common.utils.ShuttleOperaUtils;
 import com.zy.core.News;
 import com.zy.core.cache.SlaveConnection;
+import com.zy.core.dispatcher.ShuttleDispatchUtils;
 import com.zy.core.enums.*;
 import com.zy.core.model.CommandResponse;
 import com.zy.core.model.command.ShuttleAssignCommand;
@@ -22,11 +28,13 @@
 import com.zy.core.model.command.ShuttleRedisCommand;
 import com.zy.core.model.protocol.ShuttleProtocol;
 import com.zy.core.thread.ShuttleThread;
+import com.zy.system.entity.Config;
 import com.zy.system.service.ConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -47,6 +55,10 @@
     private ConfigService configService;
     @Autowired
     private BasShuttleOptService basShuttleOptService;
+    @Autowired
+    private WrkMastService wrkMastService;
+    @Autowired
+    private ShuttleDispatchUtils shuttleDispatchUtils;
 
     public synchronized boolean assignWork(Integer shuttleNo, ShuttleAssignCommand assignCommand) {
         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
@@ -61,7 +73,7 @@
         redisCommand.setCommandStep(0);//鍛戒护鎵ц姝ュ簭
         redisCommand.setAssignCommand(assignCommand);//鍛戒护
         //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-        if (redisUtil.set(RedisKeyType.SHUTTLE.key + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect))) {
+        if (redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect))) {
             shuttleThread.setSyncTaskNo(assignCommand.getTaskNo());
             return true;
         }
@@ -69,7 +81,7 @@
     }
 
     public synchronized boolean executeWork(Integer shuttleNo, Integer taskNo) {
-        Object obj = redisUtil.get(RedisKeyType.SHUTTLE.key + taskNo);
+        Object obj = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + taskNo);
         if (obj == null) {
             return false;
         }
@@ -192,7 +204,7 @@
 
             if(updateCommand) {
                 // 鏇存柊redis鏁版嵁
-                redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
+                redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
             }
 
             if (!command.getComplete()) {
@@ -226,7 +238,7 @@
                 }
 
                 //鍒犻櫎redis
-                redisUtil.del(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo());
+                redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo());
                 return false;//绂佹鍐嶄笅鍙戝懡浠�
             }
         }
@@ -264,10 +276,97 @@
         //鏇存柊redis鏁版嵁
         redisCommand.setCommandStep(commandStep);
         //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-        redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
+        redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
         return true;
     }
 
+    //婕旂ず妯″紡
+    public synchronized void demo(Integer shuttleNo) {
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+        if (shuttleThread == null) {
+            return;
+        }
+
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null) {
+            return;
+        }
+
+        if (!shuttleProtocol.getDemo()) {
+            return;
+        }
+
+        WrkMast moveWorking = wrkMastService.selectShuttleHasMoveWorking(shuttleNo);
+        if (moveWorking != null) {
+            return;
+        }
+
+        WrkMast shuttleWorking = wrkMastService.selectShuttleWorking(shuttleNo);
+        if(shuttleWorking != null) {
+            return;
+        }
+
+        WrkMast chargeWorking = wrkMastService.selectChargeWorking(shuttleNo);
+        if (chargeWorking != null) {
+            return;
+        }
+
+        if (shuttleThread.isRequireCharge()) {
+            return;
+        }
+
+        if (!shuttleThread.isIdle()) {
+            return;
+        }
+
+        boolean demoSwitchLev = false;
+        Config demoSwitchLevConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoSwitchLev"));
+        if (demoSwitchLevConfig != null) {
+            if (demoSwitchLevConfig.getValue().equals("Y")) {
+                demoSwitchLev = true;
+            }
+        }
+
+        Config demoRunLevConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoRunLev"));
+        if (demoRunLevConfig == null) {
+            return;
+        }
+        List<Integer> levList = JSON.parseArray(demoRunLevConfig.getValue(), Integer.class);
+
+        if (!demoSwitchLev) {
+            String currentLocNo = shuttleProtocol.getCurrentLocNo();
+            levList = new ArrayList<>();
+            levList.add(Utils.getLev(currentLocNo));
+        }
+
+        LocMast targetLoc = null;
+        EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
+        wrapper.in("lev1", levList);
+        wrapper.eq("loc_sts", "O");
+        wrapper.last("ORDER BY RAND() LIMIT 1");
+        for (int i = 0; i < 3; i++) {
+            LocMast locMast = locMastService.selectOne(wrapper);
+            if(locMast == null) {
+                continue;
+            }
+
+            ArrayList<String> locs = new ArrayList<>();
+            locs.add(locMast.getLocNo());
+            Integer shuttle = Utils.checkGroupLocHasShuttle(locs);
+            if(shuttle != null) {
+                continue;
+            }
+
+            targetLoc = locMast;
+        }
+
+        if(targetLoc == null) {
+            return;
+        }
+
+        shuttleDispatchUtils.dispatchShuttle(null, targetLoc.getLocNo(), shuttleNo);
+    }
+
 //    //璺戝簱绋嬪簭
 //    public synchronized void moveLoc(Integer shuttleNo) {
 //        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);

--
Gitblit v1.9.1