nishiwei
5 days ago 3f43e40ed1a1e9f66b3ad2862da9dbc4b710c712
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
/*
 * 【机场1】航线准备异常通知消费者(flight_setup_exception_notify)。
 * Dock1/M30 在 flighttask_prepare 失败时会发送该事件;共享层原枚举未注册此方法,
 * 消息会被路由到 default 通道后丢弃。这里新增独立通道与 dock1 消费者,
 * 仅处理 Dock1 设备,机场2/3 收到同名事件时保持原行为(只记录日志)。
 */
package com.ard.sample.dock1.manage.service.impl;
 
import com.ard.sample.component.mqtt.model.ChannelName;
import com.ard.sample.component.mqtt.model.CommonTopicReceiver;
import com.ard.sample.component.websocket.enums.MessageType;
import com.ard.sample.component.websocket.handler.DockWebSocketHandler;
import com.ard.sample.manage.model.dto.DeviceDTO;
import com.ard.sample.manage.service.IDeviceService;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.MessageHeaders;
import org.springframework.stereotype.Service;
 
import java.util.Objects;
import java.util.Optional;
 
/**
 * 机场1航线准备异常通知处理器。
 *
 * @author ard
 */
@Slf4j
@Service
public class Dock1FlightSetupExceptionHandler {
 
    /**
     * 机场1:Dock1 设备类型。
     */
    private static final int DOCK1_DEVICE_TYPE = 1;
 
    @Autowired
    private IDeviceService deviceService;
 
    @Autowired
    private DockWebSocketHandler dockWebSocketHandler;
 
    @Autowired
    private ObjectMapper mapper;
 
    @ServiceActivator(inputChannel = ChannelName.INBOUND_EVENTS_FLIGHT_SETUP_EXCEPTION_NOTIFY)
    public void handleFlightSetupException(CommonTopicReceiver receiver, MessageHeaders headers) {
        String dockSn = receiver.getGateway();
        Optional<DeviceDTO> deviceOpt = deviceService.getDeviceBySn(dockSn);
        if (deviceOpt.isEmpty() || !Objects.equals(DOCK1_DEVICE_TYPE, deviceOpt.get().getType())) {
            // 机场2/3 的事件仍按原逻辑只记录日志,不改变其行为。
            log.info("非机场1设备的航线准备异常通知,忽略。sn={}, method={}, data={}",
                    dockSn, receiver.getMethod(), receiver.getData());
            return;
        }
 
        log.warn("机场1航线准备异常:sn={}, bid={}, data={}", dockSn, receiver.getBid(), receiver.getData());
        try {
            // 原样推送给前端,便于机场1页面展示准备失败原因。
            dockWebSocketHandler.sendMessageToSubscribers(dockSn, MessageType.STATUS.getType(),
                    mapper.writeValueAsString(receiver), "");
        } catch (Exception e) {
            log.error("机场1航线准备异常通知推送失败:sn={}", dockSn, e);
        }
    }
}