package org.ts.ddcs.kafka;

import org.springframework.kafka.annotation.KafkaListener;
import org.ts.ddcs.log.LogHelper;
import org.ts.ddcs.Worker.DataProcessHolder;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class KafkaMessageListener {

   @KafkaListener(topics = "${run-config.mq.waitingToProcessDatagram}", containerFactory = "kafkaListenerContainerFactory")
    public void process(List<ConsumerRecord<String, String>> records) throws Exception {
        try {
            for (ConsumerRecord<String, String> record : records) {
                LogHelper.info("kafka " + record.topic() + " " + record.partition() + " " + record.value());
                //String body = new String(record.value());
                String body = record.value();
                DataProcessHolder.newInstance().dataProcess.SubmitSw2014DataGramTask(body);
//                JSONObject data = JSONObject.parseObject(body);
//                String gram = data.getString(GBConstants.BASE_KEY_DATAGRAM);
//                if (null != gram) {
//                    String version = data.getString(GBConstants.BASE_KEY_AGREEMENT);
//                    if (null != version) {
//                        if (version.equals(GBConstants.AGREEMENT_KIND_SZY)) {
//                            DataProcessHolder.newInstance().dataProcess.SubmitSzy2012DataGramTask(body);
//                        } else if (version.equals(GBConstants.AGREEMENT_KIND_SW)) {
//                            DataProcessHolder.newInstance().dataProcess.SubmitSw2014DataGramTask(body);
//                        } else if (version.equals(GBConstants.AGREEMENT_KIND_DTU)) {
//                            DataProcessHolder.newInstance().dataProcess.SubmitDtu2021DataGramTask(body);
//                        }
//                    }
//                }
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }

}
