liuyongxin 6 månader sedan
förälder
incheckning
c7034d25b2
1 ändrade filer med 23 tillägg och 74 borttagningar
  1. 23 74
      src/main/java/com/lutao/uav/mqtt/MqttConfig.java

+ 23 - 74
src/main/java/com/lutao/uav/mqtt/MqttConfig.java

@@ -64,6 +64,7 @@ public class MqttConfig {
     @PostConstruct
     public void init() {
         log.info("-------------------初始化MQTT配置-------------------");
+        initDatabase();
         //initPointData();
         executorService = Executors.newSingleThreadExecutor();
         connectWithReconnect();
@@ -86,80 +87,28 @@ public class MqttConfig {
 
     //初始化数据库
     public void initDatabase() {
-        boolean remove = northSeaGasPointService.remove(null);
-        log.info("-------------------初始化北海点位数据库-------------------");
-        NorthSeaGasPoint northSeaGasPoint = new NorthSeaGasPoint();
-        northSeaGasPoint.setId(UUID.randomUUID().toString());
-        northSeaGasPoint.setPointName("氨气");
-        northSeaGasPoint.setPointCode("wrj-aq");
-        northSeaGasPoint.setPointCode2("wrj-aq");
-        northSeaGasPoint.setPointType("氨气");
-        northSeaGasPoint.setUnit("ppm");
-        northSeaGasPoint.setHighReport("26");
-        northSeaGasPoint.setHighHighReport("52");
-
-        NorthSeaGasPoint northSeaGasPoint1 = new NorthSeaGasPoint();
-        northSeaGasPoint1.setId(UUID.randomUUID().toString());
-        northSeaGasPoint1.setPointName("甲烷");
-        northSeaGasPoint1.setPointCode("wrj-jw");
-        northSeaGasPoint1.setPointCode2("wrj-jw");
-        northSeaGasPoint1.setPointType("甲烷");
-        northSeaGasPoint1.setUnit("%LEL");
-        northSeaGasPoint1.setHighReport("25");
-        northSeaGasPoint1.setHighHighReport("50");
-
-        NorthSeaGasPoint northSeaGasPoint2 = new NorthSeaGasPoint();
-        northSeaGasPoint2.setId(UUID.randomUUID().toString());
-        northSeaGasPoint2.setPointName("硫化氢");
-        northSeaGasPoint2.setPointCode("wrj-liuhq");
-        northSeaGasPoint2.setPointCode2("wrj-liuhq");
-        northSeaGasPoint2.setPointType("硫化氢");
-        northSeaGasPoint2.setUnit("PPM");
-        northSeaGasPoint2.setHighReport("2.5");
-        northSeaGasPoint2.setHighHighReport("5");
-
-        NorthSeaGasPoint northSeaGasPoint3 = new NorthSeaGasPoint();
-        northSeaGasPoint3.setId(UUID.randomUUID().toString());
-        northSeaGasPoint3.setPointName("一氧化碳");
-        northSeaGasPoint3.setPointCode("wrj-yyht");
-        northSeaGasPoint3.setPointCode2("wrj-yyht");
-        northSeaGasPoint3.setPointType("一氧化碳");
-        northSeaGasPoint3.setUnit("PPM");
-
-        NorthSeaGasPoint northSeaGasPoint4 = new NorthSeaGasPoint();
-        northSeaGasPoint4.setId(UUID.randomUUID().toString());
-        northSeaGasPoint4.setPointName("二氧化氮");
-        northSeaGasPoint4.setPointCode("wrj-eyhd");
-        northSeaGasPoint4.setPointCode2("wrj-eyhd");
-        northSeaGasPoint4.setPointType("二氧化氮");
-        northSeaGasPoint4.setUnit("PPM");
-        northSeaGasPoint4.setHighReport("2.4");
-        northSeaGasPoint4.setHighHighReport("4.8");
-
-        NorthSeaGasPoint northSeaGasPoint5 = new NorthSeaGasPoint();
-        northSeaGasPoint5.setId(UUID.randomUUID().toString());
-        northSeaGasPoint5.setPointName("二氧化硫");
-        northSeaGasPoint5.setPointCode("wrj-eyhl");
-        northSeaGasPoint5.setPointCode2("wrj-eyhl");
-        northSeaGasPoint5.setPointType("二氧化硫");
-        northSeaGasPoint5.setUnit("PPM");
-
-        NorthSeaGasPoint northSeaGasPoint6 = new NorthSeaGasPoint();
-        northSeaGasPoint6.setId(UUID.randomUUID().toString());
-        northSeaGasPoint6.setPointName("氯化氢");
-        northSeaGasPoint6.setPointCode("wrj-lvhq");
-        northSeaGasPoint6.setPointCode2("wrj-lvhq");
-        northSeaGasPoint6.setPointType("氯化氢");
-        northSeaGasPoint6.setUnit("PPM");
-        northSeaGasPoint4.setHighReport("2.5");
-        northSeaGasPoint4.setHighHighReport("5");
-
-        boolean b = northSeaGasPointService.saveBatch(Arrays.asList(northSeaGasPoint, northSeaGasPoint1, northSeaGasPoint2, northSeaGasPoint3, northSeaGasPoint4, northSeaGasPoint5, northSeaGasPoint6));
-        if (b){
-            log.info("-------------------初始化成功-------------------");
-            initPointData();
-        }else {
-            log.info("-------------------初始化失败-------------------");
+        try {
+            northSeaGasPointService.remove(null);
+            log.info("-------------------初始化北海点位数据库-------------------");
+
+            List<NorthSeaGasPoint> gasPoints = Arrays.asList(
+                    createGasPoint("氨气", "wrj-aq", "氨气", "ppm", "26", "52"),
+                    createGasPoint("甲烷", "wrj-jw", "甲烷", "%LEL", "25", "50"),
+                    createGasPoint("硫化氢", "wrj-liuhq", "硫化氢", "PPM", "2.5", "5"),
+                    createGasPoint("一氧化碳", "wrj-yyht", "一氧化碳", "PPM", null, null),
+                    createGasPoint("二氧化氮", "wrj-eyhd", "二氧化氮", "PPM", "2.4", "4.8"),
+                    createGasPoint("二氧化硫", "wrj-eyhl", "二氧化硫", "PPM", null, null),
+                    createGasPoint("氯化氢", "wrj-lvhq", "氯化氢", "PPM", "2.5", "5")
+            );
+
+            boolean success = northSeaGasPointService.saveBatch(gasPoints);
+            if (success) {
+                log.info("-------------------初始化成功-------------------");
+            } else {
+                log.error("-------------------初始化失败-------------------");
+            }
+        } catch (Exception e) {
+            log.error("初始化过程中发生异常: ", e);
         }
 
     }