‘liusuyi’
2024-03-02 06dbac737b78fbd6bdafaa222fdb1327314094eb
src/main/java/com/ard/alarm/tube/service/TubeAlarmService.java
@@ -1,15 +1,19 @@
package com.ard.alarm.tube.service;
import com.alibaba.fastjson2.JSON;
import com.ard.utils.other.DateUtils;
import com.ard.utils.mqtt.MqttConsumer;
import com.ard.utils.udp.NettyUdpServer;
import com.ard.utils.netty.config.NettyUdpConfiguration;
import com.ard.utils.util.DateUtils;
import com.ard.utils.mqtt.MqttProducer;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
@@ -24,25 +28,7 @@
 **/
@Service
@Slf4j(topic = "tube")
@Order(3)
public class TubeAlarmService {
    @Resource
    NettyUdpServer nettyUdpServer;
    @Value("${spring.netty.udp.port}")
    private Integer udpPort;
    @Value("${spring.netty.udp.enabled}")
    private String UdpServerEnable;
    @PostConstruct
    public void init() {
        if (UdpServerEnable.equals("false")) {
            return;
        }
        nettyUdpServer.init(udpPort);
        log.info("管线泄露UDP服务已启动");
    }
    @Async("alarm")
    public void alarmHandler(String message) {
@@ -65,15 +51,15 @@
                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);
                MqttConsumer.publish(2, false, "tube", JSON.toJSONString(map));
                log.debug("开始解析" + start);
                log.debug("主机:" + host);
                log.debug("管线编号:" + tubeId);
                log.debug("报警时间:" + alarmTime);
                log.debug("报警类型:" + type);
                log.debug("位置:" + position);
                log.debug("值班人:" + watcher);
                log.debug("结束解析" + stop);
                MqttProducer.publish(2, false, "tube", JSON.toJSONString(map));
            } else {
                log.error("数据异常");
            }
@@ -81,6 +67,5 @@
            log.error("tube报警数据推送异常:" + ex.getMessage());
        }
    }
}