فهرست منبع

Merge branch 'usky-zyj' of uskycloud/usky-modules into server-165

James 11 ماه پیش
والد
کامیت
fc94fb0c0e

+ 4 - 1
service-fire/service-fire-biz/pom.xml

@@ -111,7 +111,10 @@
             <artifactId>commons-collections4</artifactId>
             <version>4.4</version>
         </dependency>
-
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
 
     </dependencies>
 

+ 2 - 1
service-fire/service-fire-biz/src/main/java/com/usky/fire/RuoYiSystemApplication.java

@@ -2,6 +2,7 @@ package com.usky.fire;
 
 
 import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.amqp.rabbit.annotation.EnableRabbit;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.openfeign.EnableFeignClients;
@@ -13,7 +14,7 @@ import org.springframework.context.annotation.ComponentScan;
  * @author ruoyi
  */
 
-
+@EnableRabbit
 @EnableFeignClients(basePackages = "com.usky")
 @MapperScan(value = "com.usky.fire.mapper")
 @ComponentScan("com.usky")

+ 61 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/config/rabbitmq/RabbitMQConfig.java

@@ -0,0 +1,61 @@
+package com.usky.fire.service.config.rabbitmq;
+
+import com.rabbitmq.client.AMQP;
+import org.springframework.amqp.core.*;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RabbitMQConfig {
+    //队列
+    public String patrolEventQueue = "Patrol_QEvent";
+    //交换机
+    public String patrolEventExchange = "Patrol_EEvent";
+    //路由
+    public String patrolEventRoute = "Patrol_REvent";
+
+    //注册一个队列
+    @Bean
+    public Queue patrolQueue(){
+        return QueueBuilder.durable(patrolEventQueue).maxLength(100).build();    //启动的时候,它会根据这个名称先去查找有没有这个队列,如果有什么都不做,如果没有就创建一个新的
+    }
+
+    //注册交换机
+    @Bean
+    public DirectExchange patrolExchange(){
+        return ExchangeBuilder.directExchange(patrolEventExchange).build();
+    }
+
+    //绑定交换机与队列关系
+    @Bean
+    public Binding bindingPatrolExchangeMessage(){
+        return BindingBuilder.bind(patrolQueue()).to(patrolExchange()).with(patrolEventRoute);
+    }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 25 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionEventServiceImpl.java

@@ -15,12 +15,16 @@ 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.rabbitmq.RabbitMQConfig;
 import com.usky.fire.service.vo.PatrolInspectionPlanRequestVO;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -36,6 +40,10 @@ public class PatrolInspectionEventServiceImpl extends AbstractCrudService<Patrol
     private PatrolInspectionPlanScheduleService patrolInspectionPlanScheduleService;
     @Autowired
     private PatrolInspectionPersonnelService patrolInspectionPersonnelService;
+    @Autowired
+    private RabbitTemplate rabbitTemplate;
+    @Autowired
+    private RabbitMQConfig rabbitMQConfig;
 
     @Override
     public CommonPage<PatrolInspectionEvent> patrolInspectionEventList(PatrolInspectionPlanRequestVO requestVO){
@@ -76,6 +84,23 @@ public class PatrolInspectionEventServiceImpl extends AbstractCrudService<Patrol
         patrolInspectionEvent.setCreateBy(SecurityUtils.getUsername());
         patrolInspectionEvent.setCreateTime(LocalDateTime.now());
 
+        Map<String,Object> map = new HashMap<>();
+        map.put("deviceId",patrolInspectionEvent.getDeviceId());
+        map.put("personnelId",patrolInspectionEvent.getPersonnelId());
+        map.put("personnelName",patrolInspectionEvent.getPersonnelName());
+        map.put("eventName",patrolInspectionEvent.getEventName());
+        map.put("eventType",patrolInspectionEvent.getEventType());
+        map.put("eventCategory",patrolInspectionEvent.getEventCategory());
+        map.put("eventImage",patrolInspectionEvent.getEventImage());
+        map.put("handleStatus",patrolInspectionEvent.getHandleStatus());
+        map.put("handleName",patrolInspectionEvent.getHandleName());
+        map.put("handleTime",patrolInspectionEvent.getHandleTime());
+        map.put("remark",patrolInspectionEvent.getRemark());
+        map.put("createBy",patrolInspectionEvent.getCreateBy());
+        map.put("createTime",patrolInspectionEvent.getCreateTime());
+
+        rabbitTemplate.convertAndSend(rabbitMQConfig.patrolEventExchange,rabbitMQConfig.patrolEventRoute,map);
+
         this.save(patrolInspectionEvent);
     }
 

+ 20 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/listener/RabbitMQListener.java

@@ -0,0 +1,20 @@
+package com.usky.fire.service.listener;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+@Slf4j
+@Component
+public class RabbitMQListener {
+
+    @RabbitHandler
+    @RabbitListener(queues = "Patrol_QEvent")  //监听名称为Patrol_QEvent队列消息
+    public void process(Map testMessage){
+        System.out.println("DirectReceiver消费者收到消息: " + testMessage.toString());
+    }
+}