RabbbitmqConsumer.java
4.5 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
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);
if (rabbitMQVehicles != null && rabbitMQVehicles.size() > 0) {
for (RabbitMQVehicle rabbitMQVehicle : rabbitMQVehicles) {
if (rabbitMQVehicle == null) {
continue;
}
double vehicleWinScore = rabbitMQVehicle.getVehicle_win_score();
if (vehicleWinScore < 0.7) {
continue;
}
RabbitMQVehicle rabbitMQVehicle1 = mongoTemplates.insertData(rabbitMQVehicle);
String s = JSON.toJSONString(rabbitMQVehicle1);
redisTemplate.opsForList().leftPush("deviceId", s);
// 车辆的特征值归一化距离保存到Redis
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);
}
rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM, "inform.alarm", s);
rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM, "inform.forbidden", s);
}
}
} 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();
}
}
}