From 42af11ca3a84e13d1f55207b2770e2454a861983 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期五, 01 八月 2025 17:05:03 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java |   98 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 68 insertions(+), 30 deletions(-)

diff --git a/src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java b/src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java
index 9020af6..a3d5036 100644
--- a/src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java
+++ b/src/main/java/com/zy/core/task/ShuttleExecuteScheduler.java
@@ -4,43 +4,81 @@
 import com.zy.asrs.entity.DeviceConfig;
 import com.zy.asrs.service.DeviceConfigService;
 import com.zy.common.utils.RedisUtil;
+import com.zy.core.News;
 import com.zy.core.action.ShuttleAction;
 import com.zy.core.enums.RedisKeyType;
 import com.zy.core.enums.SlaveType;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
 import java.util.List;
 
-@Slf4j
-@Component
-public class ShuttleExecuteScheduler {
+public class ShuttleExecuteScheduler implements Runnable {
 
-//    @Autowired
-//    private ShuttleAction shuttleAction;
-//    @Autowired
-//    private DeviceConfigService deviceConfigService;
-//    @Autowired
-//    private RedisUtil redisUtil;
-//
-//    @Scheduled(cron = "0/1 * * * * ? ")
-//    public void execute() {
-//        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
-//                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
-//        for (DeviceConfig deviceConfig : shuttleList) {
-//            Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
-//            if (object == null) {
-//                continue;
-//            }
-//
-//            int taskNo = Integer.parseInt(String.valueOf(object));
-//            if (taskNo != 0) {
-//                //瀛樺湪浠诲姟闇�瑕佹墽琛�
-//                boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
-//            }
-//        }
-//    }
+    private ShuttleAction shuttleAction;
+    private DeviceConfigService deviceConfigService;
+    private RedisUtil redisUtil;
+    private int threadControlCount;
 
+    @Scheduled(cron = "0/1 * * * * ? ")
+    public void execute() {
+
+    }
+
+    public ShuttleExecuteScheduler(ShuttleAction shuttleAction, DeviceConfigService deviceConfigService, RedisUtil redisUtil, int threadControlCount) {
+        this.shuttleAction = shuttleAction;
+        this.deviceConfigService = deviceConfigService;
+        this.redisUtil = redisUtil;
+        this.threadControlCount = threadControlCount;
+    }
+
+    @Override
+    public void run() {
+        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
+
+        List<List<DeviceConfig>> lists = new ArrayList<>();
+        List<DeviceConfig> tmp = new ArrayList<>();
+
+        for (int i = 0; i < shuttleList.size(); i++) {
+            DeviceConfig deviceConfig = shuttleList.get(i);
+            if (i != 0 && i % threadControlCount == 0) {
+                lists.add(tmp);
+                tmp = new ArrayList<>();
+            }
+            tmp.add(deviceConfig);
+        }
+        lists.add(tmp);
+
+        for (List<DeviceConfig> list : lists) {
+            if (list.isEmpty()) {
+                continue;
+            }
+
+            new Thread(() -> {
+                while (true) {
+                    try {
+                        for (DeviceConfig deviceConfig : list) {
+                            Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
+                            if (object == null) {
+                                continue;
+                            }
+
+                            int taskNo = Integer.parseInt(String.valueOf(object));
+                            if (taskNo != 0) {
+                                //瀛樺湪浠诲姟闇�瑕佹墽琛�
+                                long startTime = System.currentTimeMillis();
+                                News.info("execute {},{}", deviceConfig.getDeviceNo(), taskNo);
+                                boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
+                                Thread.sleep(100);
+                                News.info("execute end {},{},{}", deviceConfig.getDeviceNo(), taskNo, System.currentTimeMillis() - startTime);
+                            }
+                        }
+                    }catch (Exception e){
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+        }
+    }
 }

--
Gitblit v1.9.1