Blame view

src/main/java/com/objecteye/utils/RabbbitmqConsumer.java 4.5 KB
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  package com.objecteye.utils;
  
  import com.alibaba.fastjson.JSON;
  import com.objecteye.config.RabbitmqConfig;
  import com.objecteye.dao.MongoTemplates;
  import com.objecteye.entity.PersonMsg;
  import com.objecteye.pojo.RabbitMQVehicle;
  import com.objecteye.service.DeployService;
  import com.objecteye.service.IVehicleViolationsService;
  import com.rabbitmq.client.Channel;
  import org.springframework.amqp.core.Message;
  import org.springframework.amqp.rabbit.annotation.RabbitListener;
  import org.springframework.amqp.rabbit.core.RabbitTemplate;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.data.mongodb.core.MongoTemplate;
  import org.springframework.data.redis.core.RedisTemplate;
  import org.springframework.stereotype.Component;
  
  import java.util.List;
  
  @Component
  public class RabbbitmqConsumer {
  
      @Autowired
      private RabbitMQVehicleTools rabbitMQVehicleTools;
      @Autowired
      private MongoTemplate mongoTemplate;
      @Autowired
      private RedisTemplate redisTemplate;
      @Autowired
      private MongoTemplates mongoTemplates;
      @Autowired
      private RabbitTemplate rabbitTemplate;
      @Autowired
      private DeployService deployService;
      @Autowired
      private IVehicleViolationsService vehicleViolationsService;
  
      @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_STORE})
      public void receive_store(String msg, Message message, Channel channel) {
          try {
              List<RabbitMQVehicle> rabbitMQVehicles = rabbitMQVehicleTools.encapsulationRabbitVehicle(msg);
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
43
              if (rabbitMQVehicles != null && rabbitMQVehicles.size() > 0) {
fddd4673   Liu Haoyu   去掉设备相关内容;
44
                  for (RabbitMQVehicle rabbitMQVehicle : rabbitMQVehicles) {
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
45
46
47
48
49
50
51
                      if (rabbitMQVehicle == null) {
                          continue;
                      }
                      double vehicleWinScore = rabbitMQVehicle.getVehicle_win_score();
                      if (vehicleWinScore < 0.7) {
                          continue;
                      }
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
52
53
54
                      RabbitMQVehicle rabbitMQVehicle1 = mongoTemplates.insertData(rabbitMQVehicle);
  
                      String s = JSON.toJSONString(rabbitMQVehicle1);
40c853a1   Liu Haoyu   去掉MySQL相关内容, 去掉my...
55
56
                      redisTemplate.opsForList().leftPush("deviceId", s);
                      // 车辆的特征值归一化距离保存到Redis
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
57
58
59
60
61
62
63
64
                      double dbFea = new CompareDistance().getDistance(rabbitMQVehicle1.getVehicle_fea_feature());
                      redisTemplate.opsForHash().put(GlobalUtil.VEHICLE_FEATURE_DISTANCE, rabbitMQVehicle1.getId(), dbFea);
                      redisTemplate.opsForHash().put(GlobalUtil.VEHICLE_FEATURE, rabbitMQVehicle1.getId(), rabbitMQVehicle1.getVehicle_fea_feature());
                      String vehicle_plate_hphm = rabbitMQVehicle1.getVehicle_plate_hphm();
                      double vehicle_plate_numScore = rabbitMQVehicle1.getVehicle_plate_numScore();
                      if (vehicle_plate_numScore > 0.9) {
                          redisTemplate.opsForHash().put("vehicleFilePlateNumber", vehicle_plate_hphm, s);
                      }
fddd4673   Liu Haoyu   去掉设备相关内容;
65
66
                      rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM, "inform.alarm", s);
                      rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM, "inform.forbidden", s);
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
                  }
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_PERSON})
      public void receive_person(String msg, Message message, Channel channel) {
          try {
              PersonMsg personMsg = JSON.parseObject(msg, PersonMsg.class);
              deployService.rabbitMqMsgListener(personMsg);
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  
      @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_ALARM})
      public void receive_alarm(String msg, Message message, Channel channel) {
          try {
              RabbitMQVehicle rabbitMqVehicle = JSON.parseObject(msg, RabbitMQVehicle.class);
              deployService.rabbitMqMsgListener(rabbitMqVehicle);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_FORBIDDEN_TASK})
      public void receive_forbidden(String msg, Message message, Channel channel) {
          try {
              RabbitMQVehicle rabbitMqVehicle = JSON.parseObject(msg, RabbitMQVehicle.class);
              // 车辆违规监听
              vehicleViolationsService.taskListener(rabbitMqVehicle);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }