Browse Source

自动下发任务

andy 2 years ago
parent
commit
10ac7f054b

+ 34 - 0
ruoyi-admin/src/main/java/com/ruoyi/init/StartService.java

@@ -0,0 +1,34 @@
+package com.ruoyi.init;
+
+import com.ruoyi.ams.agv.ndc.AciService;
+import com.ruoyi.ams.agv.ndc.config.TestTagConfig;
+import com.ruoyi.ams.agv.ndc.thread.AutoTaskThread;
+import com.ruoyi.ams.business.IBusinessService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+@Component
+public class StartService implements CommandLineRunner {
+
+    @Autowired
+    private IBusinessService businessService;
+    @Autowired
+    private TestTagConfig testTagConfig;
+
+    @Override
+    public void run(String... args) throws Exception {
+        //自动下发任务
+        if (testTagConfig.getAutoSend()) {
+            Thread thread = new Thread(new AutoTaskThread(businessService));
+            thread.start();
+        }
+
+        //ndc下发
+        if (testTagConfig.getAciService()) {
+            AciService aciService = new AciService();
+            aciService.start();
+        }
+    }
+}

+ 5 - 0
ruoyi-admin/src/main/resources/application.yml

@@ -118,3 +118,8 @@ xss:
   excludes: /system/notice
   # 匹配链接
   urlPatterns: /system/*,/monitor/*,/tool/*
+
+# 是否开启服务
+testtag:
+  autosend: true
+  aciservice: false

+ 16 - 0
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/config/TestTagConfig.java

@@ -0,0 +1,16 @@
+package com.ruoyi.ams.agv.ndc.config;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@ConfigurationProperties(prefix = "testtag")
+public class TestTagConfig {
+    @Value("${testtag.autosend}")
+    private Boolean autoSend;
+    @Value("${testtag.aciservice}")
+    private Boolean aciService;
+}

+ 28 - 0
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/thread/AutoTaskThread.java

@@ -0,0 +1,28 @@
+package com.ruoyi.ams.agv.ndc.thread;
+
+import com.ruoyi.ams.business.IBusinessService;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class AutoTaskThread implements Runnable {
+
+    private IBusinessService businessService;
+
+    public AutoTaskThread(IBusinessService businessService) {
+        this.businessService = businessService;
+    }
+
+    @Override
+    public void run() {
+        log.info("-------------------------自动下发任务服务启动---------------------->");
+        while (true) {
+            try {
+                Thread.sleep(200L);
+                businessService.autoSend();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+        }
+    }
+}