@Service public class IMSAlarmHttpMessageService implements IMessageInternalService {

private final Map<MessagePublish.MessageType, Consumer<AlarmNotifyDto>> messageHandlers = new HashMap<>();

@Autowired
private INorthDeviceInternalService northDeviceInternalService;

@Autowired
private PropertyService propertyFeignClient;

public IMSAlarmHttpMessageService() {
    messageHandlers.put(MessagePublish.MessageType.DEVICE_ALARM_REPORT, this::alarmReport);
    messageHandlers.put(MessagePublish.MessageType.DEVICE_ALARM_CLEAN, this::alarmClean);
    messageHandlers.put(MessagePublish.MessageType.DEVICE_ALARM_CONFIRM, this::alarmConfirm);
}

@Override
public <T> void notify(T notify, MessagePublish.MessageType messageType) {
    Consumer<AlarmNotifyDto> handler = messageHandlers.get(messageType);
    if (handler != null && notify instanceof AlarmNotifyDto) {
        handler.accept((AlarmNotifyDto) notify);
    }
}

@Override
public <T> boolean support(T notify, MessagePublish.MessageType messageType) {
    if (notify instanceof AlarmNotifyDto) {
        Property property = propertyFeignClient.getValue("ims_north_message_publish");
        return property != null && Boolean.parseBoolean(property.getValue());
    }
    return false;
}

private void alarmReport(AlarmNotifyDto dto) {
    northDeviceInternalService.addAlarm(dto.getDeviceAlarm(), dto.getDevice());
}

private void alarmClean(AlarmNotifyDto dto) {
    northDeviceInternalService.cleanAlarm(dto.getDeviceAlarm(), dto.getDevice(), dto.getUserName());
}

private void alarmConfirm(AlarmNotifyDto dto) {
    if (dto.getDeviceAlarm().getCleanStatus() == AlarmCleanStatus.CLEAN) {
        northDeviceInternalService.cleanAlarm(dto.getDeviceAlarm(), dto.getDevice(), dto.getUserName());
    }
    northDeviceInternalService.ackAlarm(dto.getDeviceAlarm(), dto.getDevice(), dto.getUserName());
}
Servicepublic class IMSAlarmHttpMessageService implements IMessageInternalService private final MapMessagePublishMessageType ConsumerAlarmNotifyDto messageHandlers = MapsnewHashMap; Autowired

原文地址: http://www.cveoy.top/t/topic/iX7e 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录