package cn.superdesk.uniorder.mq.consumer.superdeskmall;

import cn.superdesk.uniorder.dubbo.consumer.organisation.SysEnterpriseDubboConsumerService;
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: 特指商城过来的企业信息 目前只有侨城汇是这样用
 * @Author: linjinyu
 * @CreateDate: 7/7/20 3:11 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 7/7/20 3:11 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Component
public class ReceiveVirtualarchitectureConsumerHandler {

	@Autowired
	private SysEnterpriseDubboConsumerService sysEnterpriseDubboConsumerService;

	/**
	 * 特指商城过来的企业信息 目前只有侨城汇是这样用
	 *
	 * @param record
	 */
	@KafkaListener(topics = "${superdesk.mall.kafka.topic.organisation.virtualarchitecture}")
	public void listenVirtualarchitecture(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))) {

				// 侨城汇 福利商城
//				topic superdesk-mall-receive_virtualarchitecture - superdesk.mall.kafka.topic.organisation.virtualarchitecture
//				message_key mergeReceiveVirtualarchitecture

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

					sysEnterpriseDubboConsumerService.mergeReceiveVirtualarchitecture4SuperdeskMall(String.valueOf(message));

				} else if ("deleteReceiveVirtualarchitecture".equals(String.valueOf(record.key()))) {
					// 20200707 林智鹏 说是没删除
					sysEnterpriseDubboConsumerService.deleteReceiveVirtualarchitecture4SuperdeskMall(String.valueOf(message));
				}
			}
		}

	}
}
