package org.ts.ddcs.RabbitMQ;


import com.alibaba.fastjson.JSONObject;
import org.ts.ddcs.Log.LogHelper;

import org.ts.ddcs.Worker.DataProcessHolder;
import org.ts.ddcs.utils.GBConstants;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class MqMsgListener {

    @Value("${run-config.mq.waitingToProcessDatagram}")
    private String waitingToProcessDatagram;

    @PostConstruct
    public void init() {
        LogHelper.info("************************ rabbit mq listener:" + waitingToProcessDatagram);
    }

   // @RabbitListener(queues = "${rabbit.config.queue.waitingToProcessDatagram}")
    public void process(String body) {
        try {
            if (null != body) {
                LogHelper.info("datagramProcess queue message:" + 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);
                        }
                    }
                }
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }
}
