package com.mvc.controller.aep;

import com.alibaba.fastjson.JSON;
import com.mvc.iot.IotStoreBlockingQueue;
import com.mvc.iot.aep.AepMqListener;
import com.mvc.model.aep.AepRootModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

public class AepController {
    private static Logger log = LoggerFactory.getLogger(AepController.class);

    @RequestMapping(value = "/receiveAepData", method = RequestMethod.POST)
    @ResponseBody
    public String receiveCTWingData(@RequestBody AepRootModel model) {
        try {

            String json = JSON.toJSONString(model);
            log.info("[AEP]HTTP监听:" + json);
            //防止HTTP与MQ同时接收数据
            if (!AepMqListener.enabledAepMqListener) {
                IotStoreBlockingQueue.aepCacheQueue.put(model);
            }
            return "200";
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
}
