Browse Source

修改中文解释

wukai 2 weeks ago
parent
commit
e2edead67c

+ 19 - 10
jjt-admin/src/main/java/com/jjt/biz/mqtt/MqttSubscriber.java

@@ -12,6 +12,7 @@ import org.eclipse.paho.client.mqttv3.*;
 import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.core.env.Environment;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Component;
 
@@ -20,9 +21,6 @@ import javax.annotation.PreDestroy;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -35,7 +33,8 @@ public class MqttSubscriber {
 
     private static final Logger logger = LoggerFactory.getLogger(MqttSubscriber.class);
     private static final ObjectMapper objectMapper = new ObjectMapper();
-
+    @Resource
+    private Environment env;
     /**
      * 注入Ruoyi的线程池
      */
@@ -58,10 +57,20 @@ public class MqttSubscriber {
 
     @PostConstruct
     public void connect() {
-        // 使用Ruoyi的线程池执行MQTT连接任务
-        threadPoolTaskExecutor.execute(() -> {
-            connectWithRetry();
-        });
+        String[] activeProfiles = env.getActiveProfiles();
+        boolean prod = false;
+        for (String profile : activeProfiles) {
+            if (profile.equals("prod")) {
+                prod = true;
+                System.err.println("Active Profile: " + profile);
+            }
+        }
+        if (prod) {
+            // 使用Ruoyi的线程池执行MQTT连接任务
+            threadPoolTaskExecutor.execute(() -> {
+                connectWithRetry();
+            });
+        }
     }
 
     /**
@@ -181,7 +190,7 @@ public class MqttSubscriber {
                 // 解析烟雾报警状态
                 JsonNode smokeNode = rootNode.path("YG").path("SMOKE");
                 int smoke = smokeNode.asInt(0);
-
+                String smokeStatus = smoke == 1 ? "异常" : "正常";
                 // 解析温度和湿度
                 JsonNode tmpNode = rootNode.path("TH").path("TMP");
                 JsonNode rhNode = rootNode.path("TH").path("RH");
@@ -200,7 +209,7 @@ public class MqttSubscriber {
                 if ((sensorConfig.getLastTime() == null || (System.currentTimeMillis() - sensorConfig.getLastTime().getTime()) / 1000 / 60 > sensorConfig.getAlarmTime())
                         && (smoke > smokeThreshold || temperature > tmpThreshold.doubleValue() || humidity > rhThreshold.doubleValue())) {
                     String value = "烟雾状态:{},温度:{}℃,湿度:{}%";
-                    value = StringUtils.format(value, smoke, temperature, humidity);
+                    value = StringUtils.format(value, smokeStatus, temperature, humidity);
                     FlowsUtils.create(sensorConfig.getHouseName(), value);
                     sensorConfig.setLastTime(new Date());
                     sensorConfigService.updateSensorConfig(sensorConfig);

+ 9 - 5
jjt-admin/src/main/java/com/jjt/biz/service/impl/FlowsRecordServiceImpl.java

@@ -16,10 +16,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.time.OffsetDateTime;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * 流程记录Service业务层处理
@@ -109,6 +106,13 @@ public class FlowsRecordServiceImpl implements IFlowsRecordService {
      */
     @Override
     public void syncFlowsRecord() {
+        Map<String, String> statusMap = new HashMap<>();
+        statusMap.put("processing", "正在处理中");
+        statusMap.put("receding", "回退中");
+        statusMap.put("cancelled", "已撤销");
+        statusMap.put("suspended", "异常");
+        statusMap.put("finished", "完成");
+        statusMap.put("aborted", "管理员终止");
         Date end = new Date();
         List<FlowsConfig> flowsConfigList = flowsConfigService.selectFlowsConfigList(new FlowsConfig());
         for (FlowsConfig flowsConfig : flowsConfigList) {
@@ -137,7 +141,7 @@ public class FlowsRecordServiceImpl implements IFlowsRecordService {
                 String name = object.getJSONObject("user").getStr("name");
                 FlowsRecord flowsRecord = new FlowsRecord();
                 flowsRecord.setRecordId(id);
-                flowsRecord.setStatus(status);
+                flowsRecord.setStatus(statusMap.get(status));
                 java.time.OffsetDateTime offsetDateTime = OffsetDateTime.parse(time);
                 Date date = Date.from(offsetDateTime.toInstant());
                 flowsRecord.setCreateTime(date);

+ 56 - 57
jjt-quartz/src/main/java/com/jjt/quartz/config/ScheduleConfig.java

@@ -1,57 +1,56 @@
-//package com.jjt.quartz.config;
-//
-//import org.springframework.context.annotation.Bean;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.scheduling.quartz.SchedulerFactoryBean;
-//import javax.sql.DataSource;
-//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", "10");
-//        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;
-//    }
-//}
+package com.jjt.quartz.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.quartz.SchedulerFactoryBean;
+
+import javax.sql.DataSource;
+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", "10");
+        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;
+    }
+}