package cn.superdesk.uniorder.mq.consumer.superdeskapp.services.meetingroomreservation;

import cn.superdesk.uniorder.dubbo.consumer.order.receive.ReceiveMeetingRoomReservationOrderDubboConsumerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;


/**
 * @Description: superdesk-app-transfer-receive_hysy_order
 * @Author: linjinyu
 * @CreateDate: 2021/9/27 上午10:28
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/9/27 上午10:28
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Component
public class MeetingRoomReservationConsumerListener {

	@Autowired
	private ReceiveMeetingRoomReservationOrderDubboConsumerService receiveMeetingRoomReservationOrderDubboConsumerService;

	/**
	 * @param record
	 */
	@KafkaListener(topics = "${superdesk.app.services.meetingroomreservation.kafka.topic.order.main}")
	public void listenMeetingRoomReservationOrder(ConsumerRecord<String, String> record) {

		Optional<?> kafkaMessage = Optional.ofNullable(record.value());

		if (kafkaMessage.isPresent()) {

			Object message = kafkaMessage.get();

			if (!StringUtils.isEmpty(String.valueOf(record.key())) && !StringUtils.isEmpty(String.valueOf(message))) {

				if ("mergeReceiveHysyOrder".equals(String.valueOf(record.key()))) {

					receiveMeetingRoomReservationOrderDubboConsumerService.kafkaMeetingRoomReservationOrderMergeReceive(String.valueOf(message));

				} else if ("deleteReceiveHysyOrder".equals(String.valueOf(record.key()))) {

					receiveMeetingRoomReservationOrderDubboConsumerService.kafkaMeetingRoomReservationOrderDeleteReceive(String.valueOf(message));

				}
			}
		}

	}
}
