Browse Source

优化事件管理表-新增接口,增加异步方法处理,解决接口响应超时的问题

james 4 months ago
parent
commit
2c6557289b

+ 31 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/config/SyncPatrolInspectionEvent.java

@@ -0,0 +1,31 @@
+package com.usky.fire.service.config;
+
+import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
+import com.usky.common.security.utils.SecurityUtils;
+import com.usky.system.RemoteDictService;
+import com.usky.system.RemoteMceService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
+
+@Configuration
+public class SyncPatrolInspectionEvent {
+
+    @Autowired
+    private RemoteMceService remoteMceService;
+    @Autowired
+    private RemoteDictService remoteDictService;
+
+    @Async
+    public void sendAsyncMessage(Integer eventId,String eventName,Integer eventType){
+        String eventTypeName = remoteDictService.selectNameById("patrol_event_type",
+                eventType.toString());
+        JsonObject jsonObject = new JsonObject();
+        jsonObject.addProperty("infoTitle", eventName);
+        jsonObject.addProperty("infoContent",eventTypeName);
+        jsonObject.addProperty("infoType",2);
+        jsonObject.addProperty("userName", SecurityUtils.getUsername());
+        jsonObject.addProperty("id",eventId);
+        remoteMceService.addMce(jsonObject.toString());
+    }
+}

+ 4 - 13
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionEventServiceImpl.java

@@ -18,6 +18,7 @@ import com.usky.fire.service.PatrolInspectionEventService;
 import com.usky.common.mybatis.core.AbstractCrudService;
 import com.usky.fire.service.PatrolInspectionPersonnelService;
 import com.usky.fire.service.PatrolInspectionPlanScheduleService;
+import com.usky.fire.service.config.SyncPatrolInspectionEvent;
 import com.usky.fire.service.config.mqtt.MqttOutConfig;
 import com.usky.fire.service.config.rabbitmq.RabbitMQConfig;
 import com.usky.fire.service.vo.PatrolInspectionPlanRequestVO;
@@ -61,10 +62,7 @@ public class PatrolInspectionEventServiceImpl extends AbstractCrudService<Patrol
     @Resource
     private MqttOutConfig.MqttGateway mqttGateway;
     @Autowired
-    private RemoteMceService remoteMceService;
-    @Autowired
-    private RemoteDictService remoteDictService;
-
+    private SyncPatrolInspectionEvent syncPatrolInspectionEvent;
 
     @Override
     public CommonPage<PatrolInspectionEvent> patrolInspectionEventList(PatrolInspectionPlanRequestVO requestVO){
@@ -135,15 +133,8 @@ public class PatrolInspectionEventServiceImpl extends AbstractCrudService<Patrol
 //      rabbitTemplate.convertAndSend(rabbitMQConfig.patrolFEventExchange,"", JSONObject.toJSONString(map));
 
         this.save(patrolInspectionEvent);
-        String eventTypeName = remoteDictService.selectNameById("patrol_event_type",
-                patrolInspectionEvent.getEventType().toString());
-        JsonObject jsonObject = new JsonObject();
-        jsonObject.addProperty("infoTitle", patrolInspectionEvent.getEventName());
-        jsonObject.addProperty("infoContent",eventTypeName);
-        jsonObject.addProperty("infoType",2);
-        jsonObject.addProperty("userName",SecurityUtils.getUsername());
-        jsonObject.addProperty("id",patrolInspectionEvent.getId());
-        remoteMceService.addMce(jsonObject.toString());
+
+        syncPatrolInspectionEvent.sendAsyncMessage(patrolInspectionEvent.getId(),patrolInspectionEvent.getEventName(),patrolInspectionEvent.getEventType());
 
     }