|
@@ -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
|
|
|
+
|
|
|
+public class ReceiveMsg {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DmDayPcService dmDayPcService;
|
|
|
+ @Autowired
|
|
|
+ private DmFoodService dmFoodService;
|
|
|
+ @Autowired
|
|
|
+ RabbitTemplate rabbitTemplate;
|
|
|
+ private static String isEable = "0";
|
|
|
+
|
|
|
+
|
|
|
+ @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 = new DefaultConsumer(channel){
|
|
|
+ @SneakyThrows
|
|
|
+ @Override
|
|
|
+ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ for (DmDayPc dmDayPc : list) {
|
|
|
+
|
|
|
+
|
|
|
+ dmDayPc.setPcdate(new Timestamp(System.currentTimeMillis()));
|
|
|
+ dmDayPcService.create(dmDayPc);
|
|
|
+ System.out.println("新增food==="+dmDayPc.getFood());
|
|
|
+ dmFoodService.create(dmDayPc.getFood());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println();
|
|
|
+ channel.basicConsume("schedule_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();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+}
|