‘liusuyi’
2023-09-25 e71d3d823093bafe0283a57aa640928709d09434
src/main/java/com/ard/alarm/tube/service/TubeAlarmService.java
@@ -1,14 +1,11 @@
package com.ard.alarm.tube.service;
import com.alibaba.fastjson2.JSON;
import com.ard.utils.DateUtils;
import com.ard.utils.other.DateUtils;
import com.ard.utils.mqtt.MqttConsumer;
import com.ard.utils.tcp.NettyTcpClient;
import com.ard.utils.udp.NettyUdpServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@@ -28,7 +25,7 @@
@Service
@Slf4j(topic = "tube")
@Order(3)
public class TubeAlarmService implements ApplicationRunner {
public class TubeAlarmService {
    @Resource
    NettyUdpServer nettyUdpServer;
@@ -36,13 +33,14 @@
    private Integer udpPort;
    @Value("${spring.netty.udp.enabled}")
    private String UdpServerEnable;
    @Override
    public void run(ApplicationArguments args) throws Exception {
    @PostConstruct
    public void init() {
        if (UdpServerEnable.equals("false")) {
            return;
        }
        nettyUdpServer.init(udpPort);
        log.info("管线泄露UDP服务已启动");
        log.debug("管线泄露UDP服务已启动");
    }
@@ -54,7 +52,7 @@
                String start = messages[0];
                String host = messages[1];
                String tubeId = messages[2];
                String alarmTime = DateUtils.convertDate(messages[3],"yyyy/M/d H:m:s");
                String alarmTime = DateUtils.convertDate(messages[3], "yyyy/M/d H:m:s");
                String position = messages[4];
                String type = messages[5];
                String watcher = messages[6];
@@ -67,14 +65,14 @@
                map.put("alarmType", start);
                map.put("position", position);
                map.put("watcher", watcher);
                log.info("开始解析" + start);
                log.info("主机:" + host);
                log.info("管线编号:" + tubeId);
                log.info("报警时间:" + alarmTime);
                log.info("报警类型:" + type);
                log.info("位置:" + position);
                log.info("值班人:" + watcher);
                log.info("结束解析" + stop);
                log.debug("开始解析" + start);
                log.debug("主机:" + host);
                log.debug("管线编号:" + tubeId);
                log.debug("报警时间:" + alarmTime);
                log.debug("报警类型:" + type);
                log.debug("位置:" + position);
                log.debug("值班人:" + watcher);
                log.debug("结束解析" + stop);
                MqttConsumer.publish(2, false, "tube", JSON.toJSONString(map));
            } else {
                log.error("数据异常");