lrf 9 months ago
parent
commit
720c34b9d7

+ 5 - 0
pom.xml

@@ -35,6 +35,11 @@
       <scope>runtime</scope>
       <scope>runtime</scope>
       <optional>true</optional>
       <optional>true</optional>
     </dependency>
     </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.datatype</groupId>
+      <artifactId>jackson-datatype-jsr310</artifactId>
+      <version>2.13.4</version>
+    </dependency>
     <!-- 安全,防御,加密 -->
     <!-- 安全,防御,加密 -->
     <dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <groupId>org.springframework.boot</groupId>

+ 10 - 5
src/main/java/com/free/controller/TestController.java

@@ -28,22 +28,27 @@ public class TestController {
   @Autowired
   @Autowired
   private TestService testService;
   private TestService testService;
 
 
-
   @Autowired
   @Autowired
   MqService mqService;
   MqService mqService;
-  
+
   @PassToken
   @PassToken
-  @GetMapping("/mq/send") 
+  @GetMapping("/mq/send")
   public Object mqSendTest() throws JsonProcessingException {
   public Object mqSendTest() throws JsonProcessingException {
     String messageId = String.valueOf(UUID.randomUUID());
     String messageId = String.valueOf(UUID.randomUUID());
     String messageData = "message: M A N ";
     String messageData = "message: M A N ";
     String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
     String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
     Map<String, Object> manMap = new HashMap<>();
     Map<String, Object> manMap = new HashMap<>();
-    manMap.put("messageId", messageId);
+    manMap.put("messageId", null);
     manMap.put("messageData", messageData);
     manMap.put("messageData", messageData);
     manMap.put("createTime", createTime);
     manMap.put("createTime", createTime);
+    Map data = new HashMap();
+    data.put("value","tesF");
+    data.put("create_time", LocalDateTime.now());
+    Long l = null;
+    data.put("l", l);
+    manMap.put("data", data);
     mqService.sendMsg(MqListeners.userExName, MqListeners.userQueue + ".1", manMap);
     mqService.sendMsg(MqListeners.userExName, MqListeners.userQueue + ".1", manMap);
-    return ResponseFormat.success();
+    return ResponseFormat.success(data);
   }
   }
 
 
   /**
   /**

+ 6 - 1
src/main/java/com/free/mq/MqService.java

@@ -9,10 +9,12 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
 import com.free.entity.TransferApply;
 import com.free.entity.TransferApply;
-import com.free.service.system.CustomerService;
+import com.free.utils.FormatJavaTimeModule;
 import com.free.utils.Utils;
 import com.free.utils.Utils;
 
 
 @Service
 @Service
@@ -33,6 +35,9 @@ public class MqService {
   public void sendMsg(String ex, String queue, Map msg) throws JsonProcessingException {
   public void sendMsg(String ex, String queue, Map msg) throws JsonProcessingException {
     String strMsg = null;
     String strMsg = null;
     ObjectMapper mapper = new ObjectMapper();
     ObjectMapper mapper = new ObjectMapper();
+    mapper.setSerializationInclusion(Include.NON_NULL);
+    JavaTimeModule jtmf = FormatJavaTimeModule.init();
+    mapper.registerModule(jtmf);
     strMsg = mapper.writeValueAsString(msg);
     strMsg = mapper.writeValueAsString(msg);
     rabbitTemplate.convertAndSend(ex, queue, strMsg);
     rabbitTemplate.convertAndSend(ex, queue, strMsg);
   }
   }

+ 19 - 0
src/main/java/com/free/utils/FormatJavaTimeModule.java

@@ -0,0 +1,19 @@
+package com.free.utils;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
+
+public class FormatJavaTimeModule {
+  public static JavaTimeModule init() {
+    JavaTimeModule javaTimeModule = new JavaTimeModule();
+    javaTimeModule.addSerializer(LocalDateTime.class,
+        new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+    javaTimeModule.addDeserializer(LocalDateTime.class,
+        new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+    return javaTimeModule;
+  }
+}

+ 1 - 0
src/main/resources/application.yml

@@ -39,6 +39,7 @@ spring:
     #设置空如何序列化
     #设置空如何序列化
     default-property-inclusion: non_null
     default-property-inclusion: non_null
     serialization:
     serialization:
+      WRITE_DATES_AS_TIMESTAMPS: false
       #格式化输出
       #格式化输出
       indent_output: true
       indent_output: true
       #忽略无法转换的对象
       #忽略无法转换的对象