//package me.zhengjie.modules.dm.order.rest;
//
//import com.alibaba.fastjson.JSONArray;
//import com.rabbitmq.client.*;
//import lombok.SneakyThrows;
//import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
//import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
//import me.zhengjie.modules.dm.order.domain.DmOrderItem;
//import me.zhengjie.modules.dm.order.domain.DmOrderRecord;
//import me.zhengjie.modules.dm.order.service.DmOrderItemService;
//import me.zhengjie.modules.dm.order.service.DmOrderRecordService;
//import me.zhengjie.modules.dm.order.service.dto.DmExpenseCalendar;
//import me.zhengjie.modules.dm.order.service.dto.DmOrderItemDto;
//import me.zhengjie.utils.ConnectionUtil;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.io.ByteArrayInputStream;
//import java.io.IOException;
//import java.io.ObjectInputStream;
//import java.sql.Timestamp;
//import java.util.List;
//
//@Component
//public class OrderReceiveMsg {
//    @Autowired
//    private DmOrderRecordService dmOrderRecordService;
//    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 = "dish_trade_produce",containerFactory = "brianThreadPool")
//    public void receive(byte[] body){
////        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(body);
//                    if (str!=null){
//                        System.out.println("receiveOrder:"+str);
//                    }else {
//                        System.out.println("receiveOrder(null):"+ str);
//                    }
//                    try {
//                        List<DmExpenseCalendar> dmOrderItem = JSONArray.parseArray(str, DmExpenseCalendar.class);
//                        for (DmExpenseCalendar dmExpenseCalendar : dmOrderItem) {
//                            dmOrderRecordService.createOrderItem(dmExpenseCalendar);
//                            dmOrderRecordService.createOrderRecord(dmExpenseCalendar);
//                        }
//                    }catch (Exception ex){
//
//                    }
////                }
////            }
////            channel.basicConsume("dish_trade_produce",true,consumer);
////        } catch (IOException e) {
////            e.printStackTrace();
////        }
//    }
//
////    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();
////    }
//}
