diff --git a/pom.xml b/pom.xml index a916eae..46ef961 100644 --- a/pom.xml +++ b/pom.xml @@ -76,8 +76,15 @@ com.alibaba fastjson - 1.2.62 + 1.2.68 + + + com.google.code.gson + gson + 2.8.6 + + mysql mysql-connector-java diff --git a/src/main/java/io/qyi/e5/controller/TestController.java b/src/main/java/io/qyi/e5/controller/TestController.java index 9dd7839..eb15c77 100644 --- a/src/main/java/io/qyi/e5/controller/TestController.java +++ b/src/main/java/io/qyi/e5/controller/TestController.java @@ -1,5 +1,9 @@ package io.qyi.e5.controller; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.gson.Gson; +import io.qyi.e5.outlook.entity.Outlook; +import io.qyi.e5.outlook.service.IOutlookService; import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.connection.CorrelationData; import org.springframework.amqp.rabbit.core.RabbitTemplate; @@ -22,12 +26,15 @@ public class TestController { @Autowired RabbitTemplate rabbitTemplate; + @Autowired + IOutlookService outlookService; + @GetMapping("/send") public void aaa() { CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); + Outlook Outlook = outlookService.getOne(new QueryWrapper().eq("github_id", 19658189)); - - rabbitTemplate.convertAndSend("delay", "delay", "ttt", message -> { + rabbitTemplate.convertAndSend("delay", "delay", Outlook, message -> { MessageProperties messageProperties = message.getMessageProperties(); // 设置这条消息的过期时间 messageProperties.setExpiration("5000"); diff --git a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java index 5286c7d..25feff2 100644 --- a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java +++ b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java @@ -171,7 +171,6 @@ public class OutlookServiceImpl extends ServiceImpl impl String s = OkHttpRequestUtils.doGet("https://graph.microsoft.com/v1.0/me/messages?$select=sender,subject", head, null); logger.info("请求邮件列表返回数据:" + s); return s; - } diff --git a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java index bb23a65..57a17bc 100644 --- a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java +++ b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java @@ -2,6 +2,7 @@ package io.qyi.e5.outlook_log.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.gson.Gson; import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; import io.qyi.e5.outlook.entity.Outlook; import io.qyi.e5.outlook.service.IOutlookService; @@ -16,6 +17,7 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; import java.util.List; @@ -45,24 +47,16 @@ public class OutlookLogController { private int pageSize; @GetMapping("/findLog") + @ResponseBody public String findLog(Model model){ UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); int github_id = authentication.getGithub_id(); - /*QueryWrapper wrapper = new QueryWrapper(); - wrapper.eq("github_id", github_id); - Page page = new Page<>(8,pageSize); - - IPage> mapIPage = outlookLogMapper.selectMapsPage(page, wrapper); - System.out.println("总页数"+mapIPage.getPages()); - System.out.println("总记录数"+mapIPage.getTotal()); - List> records = mapIPage.getRecords(); - records.forEach(System.out::println);*/ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("github_id", github_id); List list = outlookLogService.list(queryWrapper); - model.addAttribute("list_log", list); - return "/outlookLog/findLog"; + Gson gson = new Gson(); + return gson.toJson(list); } @GetMapping("/exec111111") diff --git a/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java b/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java index 3f6722b..65c744e 100644 --- a/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java +++ b/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java @@ -2,7 +2,9 @@ package io.qyi.e5.service.rabbitMQ.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; import com.rabbitmq.client.Channel; +import io.qyi.e5.outlook.entity.Outlook; import io.qyi.e5.outlook.service.IOutlookService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.IOException; +import java.lang.reflect.Type; /** * @program: msgpush @@ -30,7 +33,15 @@ public class ListenerImpl { @RabbitHandler @RabbitListener(queues = "delay_queue2", containerFactory = "rabbitListenerContainerFactory") public void listen(Message message, Channel channel) throws IOException { - logger.info("消费者1开始处理消息: {},时间戳:{}" ,new String(message.getBody()),System.currentTimeMillis()); + String body = new String(message.getBody()); + logger.info("消费者1开始处理消息: {},时间戳:{}" ,body,System.currentTimeMillis()); + try { + Gson gson = new Gson(); + Outlook outlook = gson.fromJson(body, Outlook.class); + outlookService.getMailList(outlook); + } catch (Exception e) { + e.printStackTrace(); + } channel.basicAck(message.getMessageProperties().getDeliveryTag(), true); } }