//package me.zhengjie.modules.dm.dmPlateTraffic.rest;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.rabbitmq.client.BuiltinExchangeType;
//import com.rabbitmq.client.Channel;
//import com.rabbitmq.client.Connection;
//import me.zhengjie.modules.dm.dmPlateTraffic.service.DmPlateTrafficService;
//import me.zhengjie.modules.dm.dmPlateTraffic.service.dto.DmPlateTrafficDto;
//import me.zhengjie.utils.ConnectionUtil;
//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.ByteArrayOutputStream;
//import java.io.IOException;
//import java.io.ObjectOutputStream;
//import java.io.Serializable;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.TimeoutException;
//
//@Component
//public class SendMsg {
//    @Autowired
//    private DmPlateTrafficService dmPlateTrafficService;
//    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"){
//            send();
//            isEable = "0";
//        }
//    }
//
//    public void send(){
//        //获取连接
//        Connection connection = ConnectionUtil.getConnection();
//        try {
////            List<Map<String,Object>> map = dmVisitorsUserService.selectVisitors();
////            JSONArray jsonArray = new JSONArray();
////            jsonArray.addAll(map);
//            List<DmPlateTrafficDto> dmDayPc = dmPlateTrafficService.queryAll(null);
//            String userString = JSON.toJSONString(dmDayPc);
//            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, userString.getBytes());
//            System.out.println("车牌记录:"+userString);
//
//            channel.close();
//            connection.close();
//        } catch (IOException | TimeoutException e) {
//            e.printStackTrace();
//        }
//    }
//
//    //对象转化为字节码
//    public  byte[] getBytesFromObject(Serializable obj) throws Exception {
//        if (obj == null) {
//            return null;
//        }
//        ByteArrayOutputStream bo = new ByteArrayOutputStream();
//        ObjectOutputStream oo = new ObjectOutputStream(bo);
//        oo.writeObject(obj);
//        return bo.toByteArray();
//    }
//}
