//package me.zhengjie.modules.quartz.task;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.rabbitmq.client.*;
//import lombok.RequiredArgsConstructor;
//import lombok.SneakyThrows;
//import lombok.extern.slf4j.Slf4j;
//import me.zhengjie.modules.dm.order.service.DmOrderRecordService;
//import me.zhengjie.modules.dm.order.service.dto.DmExpenseCalendar;
//import me.zhengjie.utils.ConnectionUtil;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.TimeoutException;
//
//@Slf4j
//@RequiredArgsConstructor
//@Component
//public class OrderDataTask {
//    private final DmOrderRecordService dmOrderRecordService;
//    private static String isEable = "0";
//
////    public void runSend1(){
////        isEable = "1";
////    }
////
////    public void runSend2(){
////        if(isEable!=null&&isEable=="1"){
////            send();
////            isEable = "0";
////        }
////    }
//
////    public void runReceive1(){
////        isEable = "1";
////    }
//
//    @Scheduled(cron = "0 */5 * * * ?")
//    @Async("threadPoolTaskExecutor2")
//    public void runReceive2(){
////        if(isEable!=null&&isEable=="1"){
//            receive();
////            isEable = "0";
////        }
//    }
//
//    /**
//     * 生产者
//     */
////    public void send(){
////        //获取连接
////        Connection connection = ConnectionUtil.getConnection();
////        try {
////            List<Map<String,Object>> map = dmOrderRecordService.selectOrderRecord();
////            JSONArray jsonArray = new JSONArray();
////            jsonArray.addAll(map);
////            List<DmExpenseCalendar> list = jsonArray.toJavaList(DmExpenseCalendar.class);
////            String userString2 = JSON.toJSONString(list);
////            Channel channel = connection.createChannel();
////            String exchangeName = "dish_trade_produce";//交换机
////            channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true,false, null);
////            String queue1Name = "dish_trade_produce";//队列名称
////            channel.queueDeclare(queue1Name, true, false, false, null);
////            channel.queueBind(queue1Name, exchangeName, "dish_trade_produce");// 队列绑定hello路由
////            channel.basicPublish(exchangeName, "dish_trade_produce", null, userString2.getBytes());
////            System.out.println("消费记录:"+userString2);
////
////            channel.close();
////            connection.close();
////        } catch (IOException | TimeoutException e) {
////            e.printStackTrace();
////        }
////    }
//
//    /**
//     * 消费者
//     */
//    public void receive(){
//        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("erroOrder"+str);
//                        System.out.println("erroOrder"+body);
//                    }else {
//                        System.out.println("sucessOrder"+str);
//                        System.out.println("sucessOreder"+body);
//                    }
//                    System.out.println("dingshiorder"+str);
////                    List<>
//                    List<DmExpenseCalendar> dmOrderItem = JSONArray.parseArray(str,DmExpenseCalendar.class);
//                    for (DmExpenseCalendar dmExpenseCalendar : dmOrderItem) {
//                        dmOrderRecordService.createOrderItem(dmExpenseCalendar);
//                        dmOrderRecordService.createOrderRecord(dmExpenseCalendar);
//                    }
//                }
//            };
//            channel.basicConsume("dish_trade_produce",true,consumer);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//}
