Procházet zdrojové kódy

排菜+消费rabbit

he.dujuan před 3 roky
rodič
revize
54af559257

+ 4 - 4
eladmin-common/src/main/java/me/zhengjie/utils/ConnectionUtil.java

@@ -17,16 +17,16 @@ public class ConnectionUtil {
         //定义连接工厂
         ConnectionFactory factory = new ConnectionFactory();
         //设置服务地址
-        factory.setHost("127.0.0.1");
+        factory.setHost("10.208.19.6");//10.21.39.1
         //端口
-        factory.setPort(5672);
+        factory.setPort(11672);//56720
         //设置账号信息
         //vhost(Virtual Host)
 //        factory.setVirtualHost("test");
         //用户名
-        factory.setUsername("admin");
+        factory.setUsername("usemq");//admin
         //密码
-        factory.setPassword("admin");
+        factory.setPassword("User!@#$mq");//123456
         //通过工厂获得与mq的连接对象
         Connection connection = null;
         try {

+ 1 - 1
eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java

@@ -105,7 +105,7 @@ public class SecurityUtils {
     public static void CheckApiAuth(QueryPageParams params) {
         HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
         if (request != null) {
-            String accesstoken = request.getHeader("X_YT_ACCESS_TOKEN");
+            String accesstoken = request.getHeader("XYTACCESSTOKEN");
             String token = "DMERPYT!@#$QWER2021+{:>";
 
             if (params == null || StringUtils.isBlank(params.getTimestamp()) || StringUtils.isBlank(params.getNonce()) || StringUtils.isBlank(accesstoken)) {

+ 9 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/daypc/rest/DmDayPcController.java

@@ -42,6 +42,7 @@ import javax.servlet.http.HttpServletResponse;
 public class DmDayPcController {
 
     private final DmDayPcService dmDayPcService;
+    private final SendMsg sendMsg;
 
     @Log("导出数据")
     @ApiOperation("导出数据")
@@ -59,6 +60,14 @@ public class DmDayPcController {
         return new ResponseEntity<>(dmDayPcService.queryAll(criteria,pageable),HttpStatus.OK);
     }
 
+    @GetMapping(value = "/send")
+    @Log("查询sned")
+    @ApiOperation("查询send")
+    public ResponseEntity<Object> send() {
+        sendMsg.send();
+        return new ResponseEntity<>(HttpStatus.OK);
+    }
+
     @PostMapping
     @Log("新增daypc")
     @ApiOperation("新增daypc")

+ 120 - 111
eladmin-system/src/main/java/me/zhengjie/modules/dm/daypc/rest/ReceiveMsg.java

@@ -1,114 +1,123 @@
-//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.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.rabbit.core.RabbitTemplate;
-//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.*;
-//import java.sql.*;
-//import java.text.*;
-//import java.util.*;
-//
-//@Component
-////@RabbitListener(queues = "schedule_produce")
-//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";
-//        }
-//    }
-//
-//    /**
-//     * 消费者
-//     */
-//    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);
-//                    List<DmDayPc>  list = JSONArray.parseArray(str,DmDayPc.class);
-////                    Map<String,Object> map = null;
-//                    for (DmDayPc dmDayPc : list) {
-////                        map = new HashMap<>();
-////                        map.put("food",dmDayPc.getFood());
-//                        dmDayPc.setPcdate(new Timestamp(System.currentTimeMillis()));
-//                        dmDayPcService.create(dmDayPc);
-//                        System.out.println("新增food==="+dmDayPc.getFood());
-//                        dmFoodService.create(dmDayPc.getFood());
+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.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.rabbit.core.RabbitTemplate;
+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.*;
+import java.sql.*;
+import java.text.*;
+import java.util.*;
+
+@Component
+//@RabbitListener(queues = "schedule_produce")
+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";
+        }
+    }
+
+    /**
+     * 消费者
+     */
+
+    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("erro"+str);
+                        System.out.println("erro"+body);
+                    }else {
+                        System.out.println("sucess"+str);
+                        System.out.println("sucess"+body);
+                    }
+                    List<DmDayPc>  list = JSONArray.parseArray(str,DmDayPc.class);
+//                    Map<String,Object> map = null;
+                    for (DmDayPc dmDayPc : list) {
+//                        map = new HashMap<>();
+//                        map.put("food",dmDayPc.getFood());
+                        dmDayPc.setPcdate(new Timestamp(System.currentTimeMillis()));
+                        dmDayPcService.create(dmDayPc);
+                        System.out.println("新增food==="+dmDayPc.getFood());
+                        dmFoodService.create(dmDayPc.getFood());
+                    }
+//                    Map<String,Object> map = JSONObject.parseObject(str);
+//                    for (Map.Entry<String, Object> entry : map.entrySet()) {
+//                        dmFoodService.create((DmFood) entry);
+//                        System.out.println("key====>" + entry.getKey() + ",value===>" + entry.getValue());
 //                    }
-////                    Map<String,Object> map = JSONObject.parseObject(str);
-////                    for (Map.Entry<String, Object> entry : map.entrySet()) {
-////                        dmFoodService.create((DmFood) entry);
-////                        System.out.println("key====>" + entry.getKey() + ",value===>" + entry.getValue());
-////                    }
-//
-//                }
-//            };
-//            //参数1:接收哪个队列的数据
-//            //参数2:消息确认 是否应答,收到消息是否回复
-//            //参数3:
-//            channel.basicConsume("schedule_produce",true,consumer);
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//        }
+
+                }
+            };
+            //参数1:接收哪个队列的数据
+            //参数2:消息确认 是否应答,收到消息是否回复
+            //参数3:
+            System.out.println();
+            channel.basicConsume("schedule_produce",true,consumer);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+//    public List<DmDayPc> getDmDayPc(){
+//        return JSONObject.parseArray(getDmDayPc(),DmDayPc.class);
 //    }
-//
-////    public List<DmDayPc> getDmDayPc(){
-////        return JSONObject.parseArray(getDmDayPc(),DmDayPc.class);
-////    }
-//
-//    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();
+
+    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();
+    }
+
+//    @RabbitHandler
+//    public void process(DmDayPc dmDayPc) {
+//        dmDayPcService.create(dmDayPc);
 //    }
-//
-////    @RabbitHandler
-////    public void process(DmDayPc dmDayPc) {
-////        dmDayPcService.create(dmDayPc);
-////    }
-//}
+}

+ 91 - 91
eladmin-system/src/main/java/me/zhengjie/modules/dm/daypc/rest/SendMsg.java

@@ -1,92 +1,92 @@
-//package me.zhengjie.modules.dm.daypc.rest;
-//
-//import com.alibaba.fastjson.JSON;
-//import com.rabbitmq.client.BuiltinExchangeType;
-//import com.rabbitmq.client.Channel;
-//import com.rabbitmq.client.Connection;
-//import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
-//import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
-//import me.zhengjie.modules.dm.daypc.service.dto.DmDayPcDto;
-//import me.zhengjie.utils.ConnectionUtil;
-//import org.springframework.amqp.core.AmqpTemplate;
-//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.HashMap;
-//import java.util.List;
-//import java.util.Map;
-//import java.util.concurrent.TimeoutException;
-//
-//@Component
-//public class SendMsg {
-//    @Autowired
-//    private AmqpTemplate amqpTemplate;
-//    @Autowired
-//    private DmDayPcService dmDayPcService;
-//    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(){
-////        String msg = "Hello,rabbit";
-//        //获取连接
-//        Connection connection = ConnectionUtil.getConnection();
-//        try {
-//            List<DmDayPc> dmDayPc = dmDayPcService.foodRepository();
+package me.zhengjie.modules.dm.daypc.rest;
+
+import com.alibaba.fastjson.JSON;
+import com.rabbitmq.client.BuiltinExchangeType;
+import com.rabbitmq.client.Channel;
+import com.rabbitmq.client.Connection;
+import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
+import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
+import me.zhengjie.modules.dm.daypc.service.dto.DmDayPcDto;
+import me.zhengjie.utils.ConnectionUtil;
+import org.springframework.amqp.core.AmqpTemplate;
+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.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeoutException;
+
+@Component
+public class SendMsg {
+    @Autowired
+    private AmqpTemplate amqpTemplate;
+    @Autowired
+    private DmDayPcService dmDayPcService;
+    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(){
+//        String msg = "Hello,rabbit";
+        //获取连接
+        Connection connection = ConnectionUtil.getConnection();
+        try {
+            List<DmDayPc> dmDayPc = dmDayPcService.foodRepository();
+            String userString = JSON.toJSONString(dmDayPc);
+            Channel channel = connection.createChannel();
+            String exchangeName = "schedule_produce";//交换机
+            channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true,false, null);
+            String queue1Name = "schedule_produce";//队列名称
+            channel.queueDeclare(queue1Name, true, false, false, null);
+            channel.queueBind(queue1Name, exchangeName, "schedule_produce");// 队列绑定hello路由
+            channel.basicPublish(exchangeName, "schedule_produce", null, userString.getBytes());
+            System.out.println("sned排菜:"+dmDayPc);
+            //            Boy boy=new Boy(15,"tom");
+            //对象转化为字节码 把对象转化为字节码后,把字节码传输过去再转化为对象
+//            byte[] bytes=getBytesFromObject(dmDayPc);
+//            amqpTemplate.convertAndSend("exchange","topic.messages",bytes);
+
+//            List<DmDayPcDto> dmDayPc = dmDayPcService.queryAll(null);
 //            String userString = JSON.toJSONString(dmDayPc);
-//            Channel channel = connection.createChannel();
-//            String exchangeName = "schedule_produce";//交换机
-//            channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true,false, null);
-//            String queue1Name = "schedule_produce";//队列名称
-//            channel.queueDeclare(queue1Name, true, false, false, null);
-//            channel.queueBind(queue1Name, exchangeName, "schedule_produce");// 队列绑定hello路由
-//            channel.basicPublish(exchangeName, "schedule_produce", null, userString.getBytes());
-//            System.out.println("sned排菜:"+dmDayPc);
-//            //            Boy boy=new Boy(15,"tom");
-//            //对象转化为字节码 把对象转化为字节码后,把字节码传输过去再转化为对象
-////            byte[] bytes=getBytesFromObject(dmDayPc);
-////            amqpTemplate.convertAndSend("exchange","topic.messages",bytes);
-//
-////            List<DmDayPcDto> dmDayPc = dmDayPcService.queryAll(null);
-////            String userString = JSON.toJSONString(dmDayPc);
-////            amqpTemplate.convertAndSend(exchangeName,queue1Name,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();
-//    }
-//}
+//            amqpTemplate.convertAndSend(exchangeName,queue1Name,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();
+    }
+}

+ 10 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/order/rest/DmOrderRecordController.java

@@ -16,6 +16,7 @@
 package me.zhengjie.modules.dm.order.rest;
 
 import me.zhengjie.annotation.Log;
+import me.zhengjie.modules.dm.daypc.rest.SendMsg;
 import me.zhengjie.modules.dm.order.domain.DmOrderRecord;
 import me.zhengjie.modules.dm.order.service.DmOrderRecordService;
 import me.zhengjie.modules.dm.order.service.dto.DmOrderRecordQueryCriteria;
@@ -41,6 +42,7 @@ import javax.servlet.http.HttpServletResponse;
 @RequestMapping("/api/dmOrderRecord")
 public class DmOrderRecordController {
 
+    private final SendMsg sendMsg;
     private final DmOrderRecordService dmOrderRecordService;
 
     @Log("导出数据")
@@ -59,6 +61,14 @@ public class DmOrderRecordController {
         return new ResponseEntity<>(dmOrderRecordService.queryAll(criteria,pageable),HttpStatus.OK);
     }
 
+    @GetMapping(value = "sendOrder")
+    @Log("查询order")
+    @ApiOperation("查询order")
+    public ResponseEntity<Object> send(){
+        sendMsg.send();
+        return new ResponseEntity<>(HttpStatus.OK);
+    }
+
     @GetMapping(value = "/queryDetails")
     @Log("查询order")
     @ApiOperation("查询order")

+ 96 - 89
eladmin-system/src/main/java/me/zhengjie/modules/dm/order/rest/OrderReceiveMsg.java

@@ -1,89 +1,96 @@
-//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.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";
-//        }
-//    }
-//
-//    /**
-//     * 消费者
-//     */
-//    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);
-//                    List<DmExpenseCalendar> dmOrderItem = JSONArray.parseArray(str,DmExpenseCalendar.class);
-////                    DmOrderRecord dmOrderRecord = (DmOrderRecord) getObjectFromBytes(body);
-////                    dmOrderItemService.create(dmOrderItem);
-////                    dmOrderRecordService.create(dmOrderRecord);
-//                    for (DmExpenseCalendar dmExpenseCalendar : dmOrderItem) {
-////                        dmExpenseCalendar.setCreateDate(new Timestamp(System.currentTimeMillis()));
-//                        dmOrderRecordService.createOrderItem(dmExpenseCalendar);
-//                        dmOrderRecordService.createOrderRecord(dmExpenseCalendar);
-//                    }
-//                }
-//            };
-//            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();
-//    }
-//}
+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.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";
+        }
+    }
+
+    /**
+     * 消费者
+     */
+    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);
+                    }
+                    List<DmExpenseCalendar> dmOrderItem = JSONArray.parseArray(str,DmExpenseCalendar.class);
+//                    DmOrderRecord dmOrderRecord = (DmOrderRecord) getObjectFromBytes(body);
+//                    dmOrderItemService.create(dmOrderItem);
+//                    dmOrderRecordService.create(dmOrderRecord);
+                    for (DmExpenseCalendar dmExpenseCalendar : dmOrderItem) {
+//                        dmExpenseCalendar.setCreateDate(new Timestamp(System.currentTimeMillis()));
+                        dmOrderRecordService.createOrderItem(dmExpenseCalendar);
+                        dmOrderRecordService.createOrderRecord(dmExpenseCalendar);
+                    }
+                }
+            };
+            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();
+    }
+}

+ 91 - 91
eladmin-system/src/main/java/me/zhengjie/modules/dm/order/rest/OrderSendMsg.java

@@ -1,91 +1,91 @@
-//package me.zhengjie.modules.dm.order.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.order.service.DmOrderRecordService;
-//import me.zhengjie.modules.dm.order.service.dto.DmExpenseCalendar;
-//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 OrderSendMsg {
-//    @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"){
-//            send();
-//            isEable = "0";
-//        }
-//    }
-//
-//    public void send(){
-//        //获取连接
-//        Connection connection = ConnectionUtil.getConnection();
-//        try {
-////            String userString1 = JSON.toJSONString(dmOrderItemService.queryAll(null));
-////            String userString2 = JSON.toJSONString(dmOrderRecordService.selectOrderRecord());
-//            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路由
-//
-////            byte[] bytes = new byte[2];
-////            bytes = userString1.getBytes();
-////            bytes[1] = (Byte)
-////            channel.basicPublish(exchangeName, "dish_trade_produce", null, userString1.getBytes());
-//            channel.basicPublish(exchangeName, "dish_trade_produce", null, userString2.getBytes());
-////            System.out.println("userString1"+userString1);
-//            System.out.println("消费记录:"+userString2);
-//
-//            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();
-//    }
-//}
+package me.zhengjie.modules.dm.order.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.order.service.DmOrderRecordService;
+import me.zhengjie.modules.dm.order.service.dto.DmExpenseCalendar;
+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 OrderSendMsg {
+    @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"){
+            send();
+            isEable = "0";
+        }
+    }
+
+    public void send(){
+        //获取连接
+        Connection connection = ConnectionUtil.getConnection();
+        try {
+//            String userString1 = JSON.toJSONString(dmOrderItemService.queryAll(null));
+//            String userString2 = JSON.toJSONString(dmOrderRecordService.selectOrderRecord());
+            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路由
+
+//            byte[] bytes = new byte[2];
+//            bytes = userString1.getBytes();
+//            bytes[1] = (Byte)
+//            channel.basicPublish(exchangeName, "dish_trade_produce", null, userString1.getBytes());
+            channel.basicPublish(exchangeName, "dish_trade_produce", null, userString2.getBytes());
+//            System.out.println("userString1"+userString1);
+            System.out.println("order消费记录:"+userString2);
+
+            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();
+    }
+}

+ 4 - 4
eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/DayPcDataTask.java

@@ -64,12 +64,12 @@ public class DayPcDataTask {
             List<DmDayPc> dmDayPc = dmDayPcService.foodRepository();
             String userString = JSON.toJSONString(dmDayPc);
             Channel channel = connection.createChannel();
-            String exchangeName = "schedule_produce";//交换机
+            String exchangeName = "schedule_consume";//交换机
             channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true,false, null);
-            String queue1Name = "schedule_produce";//队列名称
+            String queue1Name = "schedule_consume";//队列名称
             channel.queueDeclare(queue1Name, true, false, false, null);
-            channel.queueBind(queue1Name, exchangeName, "schedule_produce");// 队列绑定hello路由
-            channel.basicPublish(exchangeName, "schedule_produce", null, userString.getBytes());
+            channel.queueBind(queue1Name, exchangeName, "schedule_consume");// 队列绑定hello路由
+            channel.basicPublish(exchangeName, "schedule_consume", null, userString.getBytes());
             System.out.println("sned排菜:"+dmDayPc);
             channel.close();
             connection.close();

+ 7 - 4
eladmin-system/src/main/java/me/zhengjie/modules/thirdparty/v1/OpenApiController.java

@@ -81,14 +81,17 @@ public class OpenApiController {
     @AnonymousPostMapping(value = "/pictures")
     @Log("上传图片")
     @ApiOperation("上传图片")
-    public BaseResponse<Object> upload(@RequestBody QueryPageParams<MultipartFile> file){
-        SecurityUtils.CheckApiAuth(file);
+    public BaseResponse<Object> upload(@RequestParam String timestamp, @RequestParam String nonce, @RequestParam String name, @RequestParam("file") MultipartFile file){
+        QueryPageParams params = new QueryPageParams();
+        params.setNonce(nonce);
+        params.setTimestamp(timestamp);
+        SecurityUtils.CheckApiAuth(params);
         // 判断文件是否为图片
-        String suffix = FileUtil.getExtensionName(file.getQuery().getOriginalFilename());
+        String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
         if(!FileUtil.IMAGE.equals(FileUtil.getFileType(suffix))){
             throw new BadRequestException("只能上传图片");
         }
-        LocalStorage localStorage = localStorageService.create(null, file.getQuery());
+        LocalStorage localStorage = localStorageService.create(name, file);
         return new BaseResponse<>(localStorage);
     }