‘liusuyi’
2023-12-05 745d5b90be7d8cdb8873b18d18b286fdc4b6913b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.ard.alarm.tube.service;
 
import com.alibaba.fastjson2.JSON;
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.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;
import java.util.Map;
 
/**
 * @Description: 管线泄漏报警服务
 * @ClassName: TubeAlarmService
 * @Author: 刘苏义
 * @Date: 2023年06月06日8:56
 * @Version: 1.0
 **/
@Service
@Slf4j(topic = "tube")
public class TubeAlarmService {
 
    @Async("alarm")
    public void alarmHandler(String message) {
        try {
            String[] messages = message.split(",");
            if (messages.length == 8) {
                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 position = messages[4];
                String type = messages[5];
                String watcher = messages[6];
                String stop = messages[7];
                Map<String, Object> map = new HashMap<>();
                map.put("host", host);
                map.put("tubeId", tubeId);
                map.put("alarmTime", alarmTime);
                map.put("type", type);
                map.put("alarmType", start);
                map.put("position", position);
                map.put("watcher", watcher);
                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("数据异常");
            }
        } catch (Exception ex) {
            log.error("tube报警数据推送异常:" + ex.getMessage());
        }
    }
 
}