Browse Source

配置定时任务

k 2 years ago
parent
commit
24afddb404

+ 37 - 12
ruoyi-admin/src/main/java/com/ruoyi/init/StartService.java

@@ -1,10 +1,8 @@
 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.AciServiceThread;
-import com.ruoyi.ams.agv.ndc.thread.AutoTaskThread;
-import com.ruoyi.ams.agv.ndc.thread.AutoTranSitTaskThread;
+import com.ruoyi.ams.agv.ndc.config.InitTaskConfig;
+import com.ruoyi.ams.agv.ndc.thread.*;
 import com.ruoyi.ams.business.IBusinessService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
@@ -16,30 +14,57 @@ public class StartService implements CommandLineRunner {
     @Autowired
     private IBusinessService businessService;
     @Autowired
-    private TestTagConfig testTagConfig;
+    private InitTaskConfig initTaskConfig;
     @Autowired
     private AciService aciService;
+    @Autowired
+    private AutoTranSitTask autoTranSitTask;
+    @Autowired
+    private AutoRfidReaderTask autoRfidReaderTask;
+    @Autowired
+    private AutoButtonBoxTask autoButtonBoxTask;
 
     @Override
     public void run(String... args) throws Exception {
         //自动下发任务
-        if (testTagConfig.getAutoSend()) {
+        if (initTaskConfig.getAutoSend()) {
             Thread thread = new Thread(new AutoTaskThread(businessService));
             thread.start();
         }
 
         //ndc下发
-        if (testTagConfig.getAciService()) {
+        if (initTaskConfig.getAciService()) {
             Thread thread = new Thread(new AciServiceThread(aciService));
             thread.start();
         }
+    }
 
-        //接驳位自动下发任务
-        if (testTagConfig.getAutoSendTran()) {
-            Thread thread = new Thread(new AutoTranSitTaskThread(businessService));
-            thread.start();
-        }
 
+    /**
+     * 自动接驳位任务
+     */
+    public void autoTranSitTask() {
+        autoTranSitTask.run();
+    }
+
+    /**
+     * 自动RFID读取任务(墙外)
+     */
+    public void autoRfidReaderTask() {
+        autoRfidReaderTask.run();
+    }
+
+    /**
+     * 自动RFID读取任务(室内)
+     */
+    public void autoRfidReaderTask01() {
+        autoRfidReaderTask.run01();
+    }
 
+    /**
+     * 自动按钮盒监控任务
+     */
+    public void autoButtonBoxTask() {
+        autoButtonBoxTask.run();
     }
 }

+ 4 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warewms/test/ModbusTestController.java

@@ -14,4 +14,8 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/api/modbus")
 public class ModbusTestController {
 
+    public static void main(String[] args) {
+        System.out.println("test");
+    }
+
 }

+ 4 - 7
ruoyi-admin/src/main/resources/application-dev.yml

@@ -56,19 +56,16 @@ spring:
                     config:
                         multi-statement-allow: true
 
-
-# 是否开启服务
-testtag:
-    autosend: false
-    aciservice: false
-    autosendtran: true
-
 # 日志配置
 logging:
     level:
         com.ruoyi: info
         org.springframework: info
 
+# 是否开启服务
+init-task:
+    autosend: false # 自动下发任务
+    aciservice: false # ndc通讯
 
 modbus:
     tcp-master:

+ 4 - 6
ruoyi-admin/src/main/resources/application-prod.yml

@@ -56,18 +56,16 @@ spring:
                     config:
                         multi-statement-allow: true
 
-# 是否开启服务
-testtag:
-    autosend: true
-    aciservice: true
-    autosendtran: true
-
 # 日志配置
 logging:
     level:
         com.ruoyi: info
         org.springframework: info
 
+# 是否开启服务
+init-task:
+    autosend: true # 自动下发任务
+    aciservice: true # ndc通讯
 
 modbus:
     tcp-master:

+ 45 - 45
ruoyi-quartz/src/main/java/com/ruoyi/quartz/config/ScheduleConfig.java

@@ -8,50 +8,50 @@ import java.util.Properties;
 
 /**
  * 定时任务配置(单机部署建议删除此类和qrtz数据库表,默认走内存会最高效)
- * 
+ *
  * @author ruoyi
  */
-@Configuration
-public class ScheduleConfig
-{
-    @Bean
-    public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource)
-    {
-        SchedulerFactoryBean factory = new SchedulerFactoryBean();
-        factory.setDataSource(dataSource);
-
-        // quartz参数
-        Properties prop = new Properties();
-        prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler");
-        prop.put("org.quartz.scheduler.instanceId", "AUTO");
-        // 线程池配置
-        prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
-        prop.put("org.quartz.threadPool.threadCount", "20");
-        prop.put("org.quartz.threadPool.threadPriority", "5");
-        // JobStore配置
-        prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore");
-        // 集群配置
-        prop.put("org.quartz.jobStore.isClustered", "true");
-        prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
-        prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
-        prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
-
-        // sqlserver 启用
-        // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
-        prop.put("org.quartz.jobStore.misfireThreshold", "12000");
-        prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
-        factory.setQuartzProperties(prop);
-
-        factory.setSchedulerName("RuoyiScheduler");
-        // 延时启动
-        factory.setStartupDelay(1);
-        factory.setApplicationContextSchedulerContextKey("applicationContextKey");
-        // 可选,QuartzScheduler
-        // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
-        factory.setOverwriteExistingJobs(true);
-        // 设置自动启动,默认为true
-        factory.setAutoStartup(true);
-
-        return factory;
-    }
-}
+//@Configuration
+//public class ScheduleConfig
+//{
+//    @Bean
+//    public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource)
+//    {
+//        SchedulerFactoryBean factory = new SchedulerFactoryBean();
+//        factory.setDataSource(dataSource);
+//
+//        // quartz参数
+//        Properties prop = new Properties();
+//        prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler");
+//        prop.put("org.quartz.scheduler.instanceId", "AUTO");
+//        // 线程池配置
+//        prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
+//        prop.put("org.quartz.threadPool.threadCount", "20");
+//        prop.put("org.quartz.threadPool.threadPriority", "5");
+//        // JobStore配置
+//        prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore");
+//        // 集群配置
+//        prop.put("org.quartz.jobStore.isClustered", "true");
+//        prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
+//        prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
+//        prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
+//
+//        // sqlserver 启用
+//        // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
+//        prop.put("org.quartz.jobStore.misfireThreshold", "12000");
+//        prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
+//        factory.setQuartzProperties(prop);
+//
+//        factory.setSchedulerName("RuoyiScheduler");
+//        // 延时启动
+//        factory.setStartupDelay(1);
+//        factory.setApplicationContextSchedulerContextKey("applicationContextKey");
+//        // 可选,QuartzScheduler
+//        // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
+//        factory.setOverwriteExistingJobs(true);
+//        // 设置自动启动,默认为true
+//        factory.setAutoStartup(true);
+//
+//        return factory;
+//    }
+//}

+ 19 - 0
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/config/InitTaskConfig.java

@@ -0,0 +1,19 @@
+package com.ruoyi.ams.agv.ndc.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@ConfigurationProperties(prefix = "init-task")
+public class InitTaskConfig {
+    /**
+     * 自动下发任务
+     */
+    private Boolean autoSend;
+    /**
+     * ndc通讯
+     */
+    private Boolean aciService;
+}

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

@@ -1,21 +0,0 @@
-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;
-    /**
-     * 接驳位自动任务
-     */
-    @Value("${testtag.autosendtran}")
-    private Boolean autoSendTran;
-}

+ 17 - 0
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/thread/AutoButtonBoxTask.java

@@ -0,0 +1,17 @@
+package com.ruoyi.ams.agv.ndc.thread;
+
+import com.ruoyi.hard.modbus.tcp.ButtonBoxClient;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class AutoButtonBoxTask {
+
+    @Autowired
+    private ButtonBoxClient buttonBoxClient;
+
+    public void run() {
+    }
+}

+ 23 - 0
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/thread/AutoRfidReaderTask.java

@@ -0,0 +1,23 @@
+package com.ruoyi.ams.agv.ndc.thread;
+
+import com.ruoyi.hard.modbus.tcp.AutoDoorClient;
+import com.ruoyi.hard.rfid.RFIDReaderClient;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class AutoRfidReaderTask {
+
+    @Autowired
+    private RFIDReaderClient rfidReaderClient;
+    @Autowired
+    private AutoDoorClient autoDoorClient;
+
+    public void run() {
+    }
+
+    public void run01() {
+    }
+}

+ 18 - 0
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/thread/AutoTranSitTask.java

@@ -0,0 +1,18 @@
+package com.ruoyi.ams.agv.ndc.thread;
+
+import com.ruoyi.ams.business.IBusinessService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class AutoTranSitTask {
+
+    @Autowired
+    private IBusinessService businessService;
+
+    public void run() {
+        businessService.autoSendTranSit();
+    }
+}

+ 0 - 29
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/thread/AutoTranSitTaskThread.java

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