|
@@ -26,8 +26,10 @@ import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.ZonedDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
@@ -61,6 +63,7 @@ public class MqttConfig {
|
|
|
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
+ log.info("-------------------初始化MQTT配置-------------------");
|
|
|
//initPointData();
|
|
|
executorService = Executors.newSingleThreadExecutor();
|
|
|
connectWithReconnect();
|
|
@@ -81,6 +84,99 @@ public class MqttConfig {
|
|
|
log.info("-------------------初始化成功-------------------");
|
|
|
}
|
|
|
|
|
|
+ //初始化数据库
|
|
|
+ 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("-------------------初始化失败-------------------");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private NorthSeaGasPoint createGasPoint(String pointName, String pointCode, String pointType, String unit, String highReport, String highHighReport) {
|
|
|
+ NorthSeaGasPoint gasPoint = new NorthSeaGasPoint();
|
|
|
+ gasPoint.setId(UUID.randomUUID().toString());
|
|
|
+ gasPoint.setPointName(pointName);
|
|
|
+ gasPoint.setPointCode(pointCode);
|
|
|
+ gasPoint.setPointCode2(pointCode);
|
|
|
+ gasPoint.setPointType(pointType);
|
|
|
+ gasPoint.setUnit(unit);
|
|
|
+ if (highReport != null) gasPoint.setHighReport(highReport);
|
|
|
+ if (highHighReport != null) gasPoint.setHighHighReport(highHighReport);
|
|
|
+ return gasPoint;
|
|
|
+ }
|
|
|
+
|
|
|
private void connectWithReconnect() {
|
|
|
new Thread(() -> {
|
|
|
while (!Thread.currentThread().isInterrupted()) {
|
|
@@ -161,8 +257,10 @@ public class MqttConfig {
|
|
|
//NH3/NO2/CH4/H2S/SO2/HCL/CO
|
|
|
//3 有毒气体 4 可燃气体
|
|
|
String pointType = gasMessage.getPointType();
|
|
|
+ log.info("气体类型{}", pointType);
|
|
|
if ("氨气".equals(pointType)) { //可燃 同时有毒
|
|
|
String NH3 = jsonObject.getJSONObject("airData").getString("NH3(ppm)");
|
|
|
+ log.info("气体{},内容{}", pointType, kafkaSendMessage);
|
|
|
kafkaSendMessage.put("monitorType", "4");
|
|
|
kafkaSendMessage.put("realtimeValue", NH3);
|
|
|
if (StringUtils.isBlank(NH3)){
|