//package me.zhengjie.modules.dm.daypc.rest;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.fasterxml.jackson.databind.ObjectMapper;
////import com.rabbitmq.client.*;
//import com.rabbitmq.client.Connection;
//import lombok.SneakyThrows;
//import me.zhengjie.config.thread.ThreadPoolConfig;
//import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
//import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
//import me.zhengjie.modules.dm.food.domain.DmFood;
//import me.zhengjie.modules.dm.food.service.DmFoodService;
//import me.zhengjie.utils.ConnectionUtil;
//import org.springframework.amqp.core.AcknowledgeMode;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//import org.springframework.stereotype.Component;
//
//import java.io.*;
//import java.sql.*;
//import java.text.*;
//import java.util.*;
//import java.util.concurrent.ExecutionException;
//import java.util.concurrent.Future;
//
//@Component
//public class ReceiveMsg {
////    private final static String SCHEDULE_PRODUCE = "schedule_produce";
//    @Autowired
//    private DmDayPcService dmDayPcService;
//    @Autowired
//    private DmFoodService dmFoodService;
////    @Autowired
////    RabbitTemplate rabbitTemplate;
//    private static String isEable = "0";
//
////    //每天10点执行
////    @Scheduled(cron = "0 0 10 * * ?")
////    //异步执行,指定线程池(配置类里配置)
////    @Async("threadPoolTaskExecutor1")
////    public void timer(){
////        isEable = "1";
////    }
////
////    //每五分钟执行一次
////    @Scheduled(cron = "0 */5 * * * ?")
////    @Async("threadPoolTaskExecutor2")
////    public void timer2(){
////        if(isEable!=null&&isEable=="1"){
////            receive();
////            isEable = "0";
////        }
////    }
//
//    /**
//     * 消费者
//     */
////    @RabbitListener(queues = "schedule_produce",containerFactory = "brianThreadPool")
//    public void receive(byte[] msg){
////        Connection connection = ConnectionUtil.getConnection();
////        try {
////            Channel channel = connection.createChannel();
////            //通过consumer来处理数据
////            Consumer consumer = new DefaultConsumer(channel){
////                @SneakyThrows
////                @Override
////                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
////                    //body就是从队列中获取的数据
//                    String str = new String(msg);
//
//                    if (str!=null){
//                        System.out.println("receive:"+str);
//                    }else {
//                        System.out.println("receive(null):"+ str);
//                    }
//                    try {
//                        List<DmDayPc> list = JSONArray.parseArray(str, DmDayPc.class);
//                        for (DmDayPc dmDayPc : list) {
//                            dmDayPc.setPcdate(new Timestamp(System.currentTimeMillis()));
//                            dmDayPcService.create(dmDayPc);
//                            System.out.println("新增food===" + dmDayPc.getFood());
//                            dmFoodService.create(dmDayPc.getFood());
//                        }
//                    }catch (Exception ex){
//
//                    }
////                }
////            };
////            //参数1：接收哪个队列的数据
////            //参数2：消息确认 是否应答，收到消息是否回复
////            //参数3：
////            System.out.println();
////            channel.basicConsume("schedule_produce",true,consumer);
////        } catch (IOException e) {
////            e.printStackTrace();
////        }
//    }
//
////    public SimpleRabbitListenerContainerFactory firstListenerFactory(
////            SimpleRabbitListenerContainerFactoryConfigurer configurer,
////            @Qualifier("firstConnectionFactory") ConnectionFactory connectionFactory) {
////        SimpleRabbitListenerContainerFactory listenerContainerFactory = new SimpleRabbitListenerContainerFactory();
////        //设置手动ack
////        listenerContainerFactory.setAcknowledgeMode(AcknowledgeMode.MANUAL);
////        configurer.configure(listenerContainerFactory, connectionFactory);
////        return listenerContainerFactory;
////    }
//
////    public  Object getObjectFromBytes(byte[] objBytes) throws Exception {
////        if (objBytes == null || objBytes.length == 0) {
////            return null;
////        }
////        ByteArrayInputStream bi = new ByteArrayInputStream(objBytes);
////        ObjectInputStream oi = new ObjectInputStream(bi);
////        return oi.readObject();
////    }
//}
