c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
1
2
3
4
5
6
|
package com.objecteye.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
7
|
import com.objecteye.entity.*;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
8
9
10
|
import com.objecteye.pojo.RabbitMQInfo;
import com.objecteye.pojo.RabbitMQVehicle;
import com.objecteye.pojo.ResponseParamPerson;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
11
12
|
import com.objecteye.service.DeployService;
import com.objecteye.service.PersonnelService;
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
13
14
|
import com.objecteye.utils.*;
import lombok.extern.slf4j.Slf4j;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
15
16
17
18
19
20
21
|
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
|
68a67f36
Liu Haoyu
接口问题处理;
|
22
|
import org.springframework.data.mongodb.core.query.Update;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
23
24
|
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
|
68a67f36
Liu Haoyu
接口问题处理;
|
25
|
import org.springframework.stereotype.Component;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
26
27
28
29
30
31
32
33
34
35
36
37
|
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* 服务实现层
*
* @author Administrator
*/
|
68a67f36
Liu Haoyu
接口问题处理;
|
38
|
@Component
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
39
|
@Slf4j
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
40
|
public class DeployServiceImpl implements DeployService {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
41
42
43
|
@Autowired
private RedisTemplate redisTemplate;
@Autowired
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
44
45
46
47
48
49
50
|
private MongoTemplate mongoTemplate;
@Autowired
private PersonnelService personnelService;
@Autowired
private CompareDistance compareDistance;
@Autowired
private VehicleEngine vehicleEngine;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
51
52
53
54
55
56
|
/**
* 查询全部
*/
@Override
public List<SyDeploy> findAll() {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
57
|
return mongoTemplate.find(Query.query(Criteria.where("isDelete").is(0)), SyDeploy.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
58
59
60
61
|
}
@Override
public Integer cancelOrReNewDeployTask(int deployId) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
62
|
SyDeploy syDeploy = mongoTemplate.findOne(Query.query(Criteria.where("id").is(deployId)), SyDeploy.class);
|
68a67f36
Liu Haoyu
接口问题处理;
|
63
64
65
|
if (syDeploy == null) {
throw new RuntimeException("未找到对应布控任务");
}
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
66
67
68
|
Integer status = syDeploy.getStatus();
if (status == 0) {
syDeploy.setStatus(1);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
69
70
71
|
mongoTemplate.save(syDeploy);
redisTemplate.opsForHash().delete(GlobalUtil.DEPLOYID_STATRTIME, deployId);
redisTemplate.opsForHash().delete(GlobalUtil.DEPLOYIDANDENDTIME, deployId);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
72
73
74
75
76
77
78
79
80
81
|
changeAllTaskDetailStatus(syDeploy, 1);
} else if (status == 1) {
String endTime = syDeploy.getEndTime();
DateTime parse = DateUtil.parse(endTime);
long time = parse.getTime();
long nowTime = System.currentTimeMillis();
if (nowTime > time) {
throw new RuntimeException("布控结束时间过期");
}
syDeploy.setStatus(0);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
82
|
mongoTemplate.save(syDeploy);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
83
|
changeAllTaskDetailStatus(syDeploy, 0);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
84
85
|
redisTemplate.opsForHash().put(GlobalUtil.DEPLOYIDANDENDTIME, deployId, syDeploy.getEndTime());
redisTemplate.opsForHash().put(GlobalUtil.DEPLOYID_STATRTIME, deployId, syDeploy.getStartTime());
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
}
return syDeploy.getStatus();
}
/**
* 修改任务下所有布控项明细的状态值
*
* @param syDeploy 布控任务
* @param status 修改之后的状态
*/
private void changeAllTaskDetailStatus(SyDeploy syDeploy, int status) {
String deployId = String.valueOf(syDeploy.getId());
for (String deployLid : syDeploy.getDeployLib().split(",")) {
String hashKey;
if (syDeploy.getDeployType() == 0) {
hashKey = deployId + "|" + GlobalUtil.DEPLOY_PLATE_NUM;
} else {
hashKey = deployId + "|" + deployLid;
}
if (syDeploy.getDeployType() == 2) {
Set<Integer> detailIntIds = redisTemplate.opsForHash().keys(hashKey);
for (Integer detailId : detailIntIds) {
redisTemplate.opsForHash().put(hashKey, detailId, status);
}
} else {
Set<String> detailIds = redisTemplate.opsForHash().keys(hashKey);
for (String detailId : detailIds) {
redisTemplate.opsForHash().put(hashKey, detailId, status);
}
}
}
}
@Override
public Integer cancelOrReNewTaskByPersonId(int deployId, int featureId, int personId) {
String key = deployId + "|" + featureId;
Object o = redisTemplate.opsForHash().get(key, personId);
if (o != null) {
String s = o.toString();
int status = Integer.parseInt(s);
if (status == 1) {
redisTemplate.opsForHash().put(key, personId, 0);
} else {
redisTemplate.opsForHash().put(key, personId, 1);
}
} else {
redisTemplate.opsForHash().put(key, personId, 1);
}
return (Integer) redisTemplate.opsForHash().get(key, personId);
}
@Override
public Integer cancelOrReNewTaskByVehicleId(int deployId, int featureId, String id) {
String key = deployId + "|" + featureId;
Object o = redisTemplate.opsForHash().get(key, id);
if (o != null) {
String s = o.toString();
int status = Integer.parseInt(s);
if (status == 1) {
redisTemplate.opsForHash().put(key, id, 0);
} else {
redisTemplate.opsForHash().put(key, id, 1);
}
} else {
redisTemplate.opsForHash().put(key, id, 1);
}
return (Integer) redisTemplate.opsForHash().get(key, id);
}
@Override
public Integer cancelOrReNewTaskByPlate(int deployId, String plate) {
String key = deployId + "|" + GlobalUtil.DEPLOY_PLATE_NUM;
Object o = redisTemplate.opsForHash().get(key, plate);
if (o != null) {
String s = o.toString();
int status = Integer.parseInt(s);
if (status == 1) {
redisTemplate.opsForHash().put(key, plate, 0);
} else {
redisTemplate.opsForHash().put(key, plate, 1);
}
} else {
redisTemplate.opsForHash().put(key, plate, 1);
}
return (Integer) redisTemplate.opsForHash().get(key, plate);
}
/**
* 按分页查询
*/
@Override
public PageResult findPage(int pageNum, int pageSize) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
180
181
182
183
|
List<SyDeploy> result = mongoTemplate
.find(Query.query(Criteria.where("isDelete").is(0)).limit(pageSize).skip((pageNum - 1) * pageSize), SyDeploy.class);
long count = mongoTemplate
.count(Query.query(Criteria.where("isDelete").is(0)), SyDeploy.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
184
|
List<DeployResultMsg> deployResultMsgs = new ArrayList<>();
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
185
|
if (result.size() > 0) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
186
187
188
189
190
191
192
193
|
for (SyDeploy deploy : result) {
DeployResultMsg deployResultMsg = new DeployResultMsg();
deployResultMsg.setDeployName(deploy.getName());
deployResultMsg.setDeployId(deploy.getId());
deployResultMsg.setStatus(deploy.getStatus());
deployResultMsgs.add(deployResultMsg);
}
}
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
194
|
return new PageResult<>(count, deployResultMsgs);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
195
196
197
198
|
}
/**
* 增加
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
199
200
|
*
* @param syDeploy
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
201
|
*/
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
202
|
@Override
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
203
|
public void add(SyDeploy syDeploy) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
204
|
// 处理前端传递的时间戳
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
205
|
makeTimeLongToTimeStr(syDeploy);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
206
|
String now = DateUtil.now();
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
207
208
209
|
if (DateUtil.parse(syDeploy.getStartTime()).getTime() <= System.currentTimeMillis()) {
syDeploy.setStartTime(now);
syDeploy.setStatus(0);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
210
|
} else {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
211
|
syDeploy.setStatus(1);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
212
|
}
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
213
214
215
216
217
|
String endTimeStr = syDeploy.getEndTime();
syDeploy.setIsDelete(0);
syDeploy.setCreateDate(now);
syDeploy.setSinglemonitor(0);
int deployType = syDeploy.getDeployType();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
218
|
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
219
220
|
syDeploy.setDeployType(deployType);
String featureIds = syDeploy.getDeployLib();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
221
222
|
String[] split = featureIds.split(",");
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
223
|
syDeploy.setDeployLib(featureIds);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
224
|
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
225
226
|
mongoTemplate.insert(syDeploy);
String deployId = syDeploy.getId();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
227
228
229
|
// 布控库中每一条数据都放到redis中
makeLibRedisDetail(split, deployId, deployType);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
230
231
232
|
redisTemplate.opsForHash().put(GlobalUtil.DEPLOYID_STATRTIME, deployId, syDeploy.getStartTime());
if (syDeploy.getThresld() != null) {
redisTemplate.opsForHash().put(GlobalUtil.DEPLOYTHRESLD, deployId, syDeploy.getThresld());
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
}
redisTemplate.opsForHash().put(GlobalUtil.DEPLOY_LIB, deployId, featureIds);
redisTemplate.opsForHash().put(GlobalUtil.DEPLOY_TYPE, deployId, deployType);
redisTemplate.opsForHash().put(GlobalUtil.DEPLOYIDANDENDTIME, deployId, endTimeStr);
}
/**
* 重置时间参数
*
* @param syDeploy 原始数据
*/
private void makeTimeLongToTimeStr(SyDeploy syDeploy) {
syDeploy.setStartTime(DateUtil.format(new Date(Long.parseLong(syDeploy.getStartTime())), "yyyy-MM-dd HH:mm:ss"));
syDeploy.setEndTime(DateUtil.format(new Date(Long.parseLong(syDeploy.getEndTime())), "yyyy-MM-dd HH:mm:ss"));
}
/**
* 布控库中每一条数据都放到redis中
*
* @param split 所有的布控库id
* @param deployId 布控任务id
* @param deployType 布控任务类型
*/
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
256
|
private void makeLibRedisDetail(String[] split, String deployId, int deployType) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
257
258
259
260
261
|
for (String s : split) {
s = s.trim();
if (deployType == 0) {
redisTemplate.opsForHash().put(deployId + "|" + GlobalUtil.DEPLOY_PLATE_NUM, s, 0);
} else if (deployType == 1) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
262
263
|
List<UploadVehicleDbResult> vehicleId = mongoTemplate.find(Query.query(new Criteria("vehicleId").is(s)), UploadVehicleDbResult.class);
String key = deployId + "|" + s;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
264
265
266
267
268
|
for (UploadVehicleDbResult uploadVehicleDbResult : vehicleId) {
String id = uploadVehicleDbResult.getId();
redisTemplate.opsForHash().put(key, id, 0);
}
} else if (deployType == 2) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
269
270
|
List<SyPersonnel> personIdByFid = personnelService.findPersonIdByFid(s);
String key = deployId + "|" + s;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
271
|
for (SyPersonnel syPersonnel : personIdByFid) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
272
|
redisTemplate.opsForHash().put(key, syPersonnel.getId(), 0);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
273
274
275
276
277
278
|
}
}
}
}
@Override
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
279
280
281
282
283
284
|
public void update(SyDeploy deploy) {
// 处理前端传递的时间戳
makeTimeLongToTimeStr(deploy);
long l = System.currentTimeMillis();
String endTime = deploy.getEndTime();
long time = DateUtil.parse(endTime).getTime();
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
285
|
String deployId = deploy.getId();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
286
287
288
289
290
291
292
293
294
|
if (l > time) {
deploy.setStatus(1);
redisTemplate.opsForHash().delete(GlobalUtil.DEPLOYID_STATRTIME, deployId);
} else if (l < DateUtil.parse(deploy.getStartTime()).getTime()) {
deploy.setStatus(1);
redisTemplate.opsForHash().put(GlobalUtil.DEPLOYID_STATRTIME, deployId, deploy.getStartTime());
}
String deployLib = deploy.getDeployLib();
Integer deployType = deploy.getDeployType();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
295
296
297
298
299
300
301
302
|
// 删除历史
deleteRedisWhenUpdateDeploy(deployId);
// 布控库中每一条数据都放到redis中
if (deployLib != null && !"".equals(deployLib)) {
makeLibRedisDetail(deployLib.split(","), deployId, deployType);
}
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
303
304
305
306
|
redisTemplate.opsForHash().put(GlobalUtil.DEPLOY_LIB, deployId, deployLib);
redisTemplate.opsForHash().put(GlobalUtil.DEPLOY_TYPE, deployId, deployType);
redisTemplate.opsForHash().put(GlobalUtil.DEPLOYIDANDENDTIME, deployId, endTime);
|
68a67f36
Liu Haoyu
接口问题处理;
|
307
|
mongoTemplate.save(deploy);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
308
309
310
311
312
313
314
|
}
/**
* 删除历史的所有对应布控任务布控库redis数据
*
* @param deployId 布控任务id
*/
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
315
316
|
private void deleteRedisWhenUpdateDeploy(String deployId) {
SyDeploy oldSyDeploy = mongoTemplate.findOne(Query.query(Criteria.where("id").is(deployId)), SyDeploy.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
if (oldSyDeploy.getDeployType() == 0) {
redisTemplate.delete(deployId + "|" + GlobalUtil.DEPLOY_PLATE_NUM);
} else {
String oldDeployLib = oldSyDeploy.getDeployLib();
// 删除历史
List<String> deleteIds = new ArrayList<>();
for (String libId : oldDeployLib.split(",")) {
deleteIds.add(deployId + "|" + libId);
}
redisTemplate.delete(deleteIds);
}
}
/**
* 根据ID获取实体
*
* @param id
* @return
*/
@Override
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
337
338
|
public SyDeploy findOne(String id) {
SyDeploy syDeploy = mongoTemplate.findOne(Query.query(Criteria.where("id").is(id)), SyDeploy.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
339
340
341
|
if (syDeploy != null) {
syDeploy.setStartTime(String.valueOf(DateUtil.parse(syDeploy.getStartTime()).getTime()));
syDeploy.setEndTime(String.valueOf(DateUtil.parse(syDeploy.getEndTime()).getTime()));
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
342
343
344
345
346
347
348
|
}
return syDeploy;
}
/**
* 批量删除
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
349
350
|
*
* @param ids
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
351
352
|
*/
@Override
|
68a67f36
Liu Haoyu
接口问题处理;
|
353
|
public void delete(List<String> ids) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
354
|
for (String id : ids) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
355
|
deleteRedisWhenUpdateDeploy(id);
|
68a67f36
Liu Haoyu
接口问题处理;
|
356
|
mongoTemplate.updateMulti(Query.query(Criteria.where("id").is(id)), Update.update("isDelete", 1), SyDeploy.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
357
358
359
360
361
|
redisTemplate.opsForHash().delete(GlobalUtil.DEPLOY_LIB, id);
redisTemplate.opsForHash().delete(GlobalUtil.DEPLOY_TYPE, id);
redisTemplate.opsForHash().delete(GlobalUtil.DEPLOYIDANDENDTIME, id);
redisTemplate.opsForHash().delete(GlobalUtil.DEPLOYID_STATRTIME, id);
redisTemplate.opsForHash().delete(GlobalUtil.DEPLOYTHRESLD, id);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
}
}
/**
* 布控任务查询列表- 分页
*
* @param pageNum 当前页 码
* @param pageSize 每页记录数
* @param deploy 布控任务类型
* @return 结果集
*/
@Override
public PageResult findPage(SyDeploy deploy, int pageNum, int pageSize) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
376
|
Integer deployType = deploy.getDeployType();
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
377
378
379
380
381
|
List<SyDeploy> tempDeployList = mongoTemplate
.find(Query.query(Criteria.where("deployType").is(deployType).and("isDelete").is(0))
.limit(pageSize).skip((pageNum - 1) * pageSize), SyDeploy.class);
long count = mongoTemplate
.count(Query.query(Criteria.where("deployType").is(deployType).and("isDelete").is(0)), SyDeploy.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
382
383
384
|
List<MonitorTaskResultInfo> resultInfos = new ArrayList<>();
// 查询出指定任务类型的所有任务报警次数
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
385
|
Map<String, Long> deployIdWarningNumberMap = getDeployIdWarningNumberMap(deployType);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
386
387
388
389
390
391
392
393
394
395
396
|
for (SyDeploy syDeploy : tempDeployList) {
long warningNumber = deployIdWarningNumberMap.getOrDefault(syDeploy.getId(), 0L);
MonitorTaskResultInfo monitorTaskResultInfo = new MonitorTaskResultInfo();
monitorTaskResultInfo.setId(syDeploy.getId());
monitorTaskResultInfo.setStatus(syDeploy.getStatus());
monitorTaskResultInfo.setName(syDeploy.getName());
monitorTaskResultInfo.setCreateDate(syDeploy.getCreateDate());
monitorTaskResultInfo.setWarningNumber(warningNumber);
resultInfos.add(monitorTaskResultInfo);
}
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
397
|
return new PageResult<>((long) Math.ceil((double) count / pageSize), resultInfos);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
398
399
400
401
402
403
404
405
|
}
/**
* 获取指定任务类型id报警数量
*
* @param deployType 报警类型
* @return 结果集
*/
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
406
|
private Map<String, Long> getDeployIdWarningNumberMap(Integer deployType) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
407
408
409
410
411
412
|
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("alarmType").is(deployType)),
Aggregation.group("deployId").count().as("count"),
Aggregation.project("deployId", "count")
);
AggregationResults<JSONObject> aggregationResults = mongoTemplate.aggregate(aggregation, "plateAlarmMsg", JSONObject.class);
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
413
|
List<JSONObject> deployIdsWarningNumberList = aggregationResults.getMappedResults();
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
414
|
Map<String, Long> resultMap = new HashMap<>(16);
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
415
|
for (JSONObject jsonObject : deployIdsWarningNumberList) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
416
417
418
|
if (jsonObject == null) {
continue;
}
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
419
|
resultMap.put(jsonObject.getString("_id"), jsonObject.getLongValue("count"));
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
}
return resultMap;
}
/**
* 布控任务-任务内容 查询列表
*
* @param deployId 任务id
* @param currentpage 页码
* @param pagevolume 页码容量
* @return 结果集
*/
@Override
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
434
435
|
public PageResult findMonitorTaskDetail(String deployId, int currentpage, int pagevolume) {
SyDeploy syDeploy = mongoTemplate.findOne(Query.query(Criteria.where("id").is(deployId)), SyDeploy.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
|
Integer deployType = syDeploy.getDeployType();
List<MonitorTaskContentResultInfo> resultInfos = new ArrayList<>();
if (null != deployType) {
if (0 == deployType) {
Set<String> plateNumberSet = redisTemplate.opsForHash().keys(deployId + "|" + GlobalUtil.DEPLOY_PLATE_NUM);
for (String plateNumber : plateNumberSet) {
MonitorTaskContentResultInfo monitorTaskContentResultInfo = new MonitorTaskContentResultInfo();
monitorTaskContentResultInfo.setPlateNumber(plateNumber);
monitorTaskContentResultInfo.setCreateDate(syDeploy.getCreateDate());
monitorTaskContentResultInfo.setDeployTime(syDeploy.getStartTime() + "-" + syDeploy.getEndTime());
monitorTaskContentResultInfo.setDeployId(String.valueOf(deployId));
Integer status = (Integer) redisTemplate.opsForHash().get(deployId + "|" + GlobalUtil.DEPLOY_PLATE_NUM, plateNumber);
monitorTaskContentResultInfo.setStatus(String.valueOf(status));
resultInfos.add(monitorTaskContentResultInfo);
}
} else {
String[] deployLibArr = syDeploy.getDeployLib().split(",");
for (String deployLib : deployLibArr) {
Map<String, Integer> oneLibPicUrlStatusMap = redisTemplate.opsForHash().entries(deployId + "|" + deployLib);
for (Map.Entry<String, Integer> entry : oneLibPicUrlStatusMap.entrySet()) {
MonitorTaskContentResultInfo monitorTaskContentResultInfo = new MonitorTaskContentResultInfo();
monitorTaskContentResultInfo.setDeployTime(syDeploy.getStartTime() + "-" + syDeploy.getEndTime());
monitorTaskContentResultInfo.setCreateDate(syDeploy.getCreateDate());
monitorTaskContentResultInfo.setId(String.valueOf(entry.getKey()));
monitorTaskContentResultInfo.setFeatureId(deployLib);
monitorTaskContentResultInfo.setDeployId(String.valueOf(deployId));
String urlKey = "";
if (1 == deployType) {
urlKey = "vehicleUrl";
} else if (2 == deployType) {
urlKey = "personUrl";
}
monitorTaskContentResultInfo.setUrl((String) redisTemplate.opsForHash().get(urlKey, entry.getKey()));
Integer status = entry.getValue();
monitorTaskContentResultInfo.setStatus(String.valueOf(status));
resultInfos.add(monitorTaskContentResultInfo);
}
}
}
}
return makePageResultByBaseList(resultInfos, currentpage, pagevolume);
}
/**
* 统一手动分页
*
* @param baseList 原始数据集合
* @param currentpage 页码
* @param pagevolume 页面容量
* @return 结果集
*/
private PageResult makePageResultByBaseList(List baseList, Integer currentpage, Integer pagevolume) {
// 总页数
int pageTotal = (baseList.size() / pagevolume) + ((baseList.size() % pagevolume > 0) ? 1 : 0);
int fromIndex = (currentpage - 1) * pagevolume;
int toIndex;
if (currentpage == pageTotal) {
toIndex = baseList.size();
} else if (pageTotal == 0) {
return new PageResult<>(pageTotal, new ArrayList<>());
} else {
toIndex = currentpage * pagevolume;
if (toIndex > baseList.size()) {
toIndex = baseList.size();
}
if (fromIndex >= toIndex) {
return new PageResult<>(pageTotal, new ArrayList<>());
}
}
return new PageResult<>(pageTotal, baseList.subList(fromIndex, toIndex));
}
/**
* 每隔一分钟秒执行一次
*/
@Scheduled(fixedRate = 60 * 1000)
public void monitorDeployState() {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
517
518
519
|
Map<String, String> map = redisTemplate.opsForHash().entries(GlobalUtil.DEPLOYID_STATRTIME);
Set<String> integers = map.keySet();
for (String integer : integers) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
520
521
522
523
524
525
|
String endTime = (String) redisTemplate.opsForHash().get(GlobalUtil.DEPLOYIDANDENDTIME, integer);
long currentTimeStamp = System.currentTimeMillis();
long deployEndTimeStamp = Objects.requireNonNull(DateUtil.parse(endTime)).getTime();
long deployStartTimeStamp = DateUtil.parse(map.get(integer)).getTime();
// 没有到开始时间的不做处理
if (currentTimeStamp >= deployStartTimeStamp && currentTimeStamp <= deployEndTimeStamp) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
526
|
SyDeploy syDeploy = mongoTemplate.findOne(Query.query(Criteria.where("id").is(integer)), SyDeploy.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
527
528
529
530
531
|
if (syDeploy == null) {
return;
}
if (1 == syDeploy.getStatus()) {
syDeploy.setStatus(0);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
532
|
mongoTemplate.save(syDeploy);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
533
534
|
}
} else if (currentTimeStamp > deployEndTimeStamp) {
|
68a67f36
Liu Haoyu
接口问题处理;
|
535
|
mongoTemplate.updateMulti(Query.query(Criteria.where("id").is(integer)), Update.update("status", 1), SyDeploy.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
536
537
538
539
540
541
|
redisTemplate.opsForHash().delete(GlobalUtil.DEPLOYID_STATRTIME, integer);
}
}
}
/**
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
* 布控任务- 主列表查询
*
* @param monitorMainTableQueryInfo 请求参数
* @return 分页结果集
*/
@Override
public PageResult monitorMainTableByPage(MonitorMainTableQueryInfo monitorMainTableQueryInfo) {
Integer currentpage = monitorMainTableQueryInfo.getCurrentpage();
Integer pagevolume = monitorMainTableQueryInfo.getPagevolume();
Integer deployType = monitorMainTableQueryInfo.getDeployType();
Long startTime = monitorMainTableQueryInfo.getStartTime();
Long endTime = monitorMainTableQueryInfo.getEndTime();
Criteria criteria = new Criteria();
if (null != startTime && null != endTime) {
criteria.and("picTime").gte(startTime).lte(endTime);
} else if (null != startTime) {
criteria.and("picTime").gte(startTime);
} else if (null != endTime) {
criteria.and("picTime").lte(endTime);
}
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
|
if (monitorMainTableQueryInfo.getPlateNumber() != null) {
String plateNumber = monitorMainTableQueryInfo.getPlateNumber().replaceAll("\\?", "\\\\S").replaceAll("\\*", ".*");
Pattern pattern = Pattern.compile(plateNumber, Pattern.CASE_INSENSITIVE);
criteria.and("plateNum").regex(pattern);
}
criteria.and("alarmType").is(deployType);
Query query = Query.query(criteria);
query.fields().include("baseId");
query.fields().include("alarmTime");
query.fields().include("plateNum");
query.fields().include("snapshotUrl");
query.fields().include("equipmentName");
if (0 != deployType) {
query.fields().include("similarity");
query.fields().include("libUrl");
query.fields().include("libId");
}
List<PlateAlarmMsg> plateAlarmMsgs = mongoTemplate.find(query.skip((currentpage - 1) * pagevolume).limit(pagevolume)
.with(Sort.by(Sort.Order.desc("picTime"))), PlateAlarmMsg.class);
long total = mongoTemplate.count(query, PlateAlarmMsg.class);
List<MonitorMainTableResultInfo> resultInfos = new ArrayList<>();
Map<String, String> personIdRabbitMqVehicleIdMap = new HashMap<>();
if (2 == deployType) {
List<String> personIdList = plateAlarmMsgs.stream().map(PlateAlarmMsg::getBaseId).collect(Collectors.toList());
Query findIdByPersonIdsQuery = new Query(Criteria.where("personid").in(personIdList));
findIdByPersonIdsQuery.fields().include("id");
findIdByPersonIdsQuery.fields().include("personid");
List<RabbitMQVehicle> rabbitMqVehicles = mongoTemplate.find(findIdByPersonIdsQuery, RabbitMQVehicle.class);
personIdRabbitMqVehicleIdMap = rabbitMqVehicles.stream().collect(Collectors.toMap(RabbitMQVehicle::getPersonid, RabbitMQVehicle::getId));
}
for (PlateAlarmMsg plateAlarmMsg : plateAlarmMsgs) {
MonitorMainTableResultInfo monitorMainTableResultInfo = new MonitorMainTableResultInfo();
if (null != plateAlarmMsg) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
monitorMainTableResultInfo.setPlateNumber(plateAlarmMsg.getPlateNum());
monitorMainTableResultInfo.setSnapshotUrl(plateAlarmMsg.getSnapshotUrl());
monitorMainTableResultInfo.setPicTime(plateAlarmMsg.getAlarmTime());
String id;
if (2 == deployType) {
id = personIdRabbitMqVehicleIdMap.get(plateAlarmMsg.getBaseId());
} else {
id = plateAlarmMsg.getBaseId();
}
monitorMainTableResultInfo.setId(id);
if (0 != deployType) {
monitorMainTableResultInfo.setLibId(plateAlarmMsg.getLibId());
monitorMainTableResultInfo.setLibUrl(plateAlarmMsg.getLibUrl());
monitorMainTableResultInfo.setThreshold(plateAlarmMsg.getSimilarity());
}
}
resultInfos.add(monitorMainTableResultInfo);
}
// 总页数
long pageTotal = (total / pagevolume) + ((total % pagevolume > 0) ? 1 : 0);
return new PageResult<>(pageTotal, resultInfos);
}
/**
* 布控监听器
*
* @param rabbitMqVehicle 消息体
*/
@Override
public void rabbitMqMsgListener(RabbitMQVehicle rabbitMqVehicle) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
631
|
// 设备id - 布控任务
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
632
633
634
|
List<String> deployIds = getAllDeployTaskStatusEqualsTo0();
if (null != deployIds) {
for (String deployId : deployIds) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
|
// 获取布控类型
Integer deployType = (Integer) redisTemplate.opsForHash().get(GlobalUtil.DEPLOY_TYPE, deployId);
if (null != deployType) {
// 车牌布控
if (deployType == 0) {
rabbitMqMsgPlateNumberHandler(rabbitMqVehicle, deployId);
} else if (deployType == 1) {
// 车辆布控
rabbitMqMsgVehicleHandler(rabbitMqVehicle, deployId);
}
}
}
}
}
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
650
651
652
653
654
655
656
657
658
659
|
/**
* 获取所有未删除并且处于激活状态的任务主键
*
* @return 结果集
*/
List<String> getAllDeployTaskStatusEqualsTo0() {
return mongoTemplate.find(Query.query(Criteria.where("status").is(0).and("isDelete").is(0)), SyDeploy.class)
.stream().map(SyDeploy::getId).collect(Collectors.toList());
}
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
660
661
|
@Override
public void rabbitMqMsgListener(PersonMsg personMsg) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
662
|
// 设备id - 布控任务
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
663
|
List<String> integers = getAllDeployTaskStatusEqualsTo0();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
664
|
if (null != integers) {
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
665
|
for (String deployId : integers) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
|
// 获取布控类型
Integer deployType = (Integer) redisTemplate.opsForHash().get(GlobalUtil.DEPLOY_TYPE, deployId);
if (null != deployType) {
if (deployType == 2) {
// 人像布控
rabbitMqPersonHandler(personMsg, deployId);
}
}
}
}
}
/**
* 根据布控库和布控类型查找所有布控id
*
* @param libId 布控库id
* @param deployType 布控类型
* @return 对应布控id
*/
@Override
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
686
687
688
|
public List<String> getDeployListByLibAndDeployType(String libId, int deployType) {
List<SyDeploy> deployList = mongoTemplate.find(Query.query(Criteria.where("deployType").is(deployType).and("isDelete").is(0)), SyDeploy.class);
List<String> list = new ArrayList<>();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
689
|
if (deployList != null) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
690
|
list = deployList.stream().filter(syDeploy -> Arrays.asList(syDeploy.getDeployLib().split(",")).contains(libId))
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
691
692
693
694
695
696
697
698
699
700
701
|
.map(SyDeploy::getId).collect(Collectors.toList());
}
return list;
}
/**
* 车牌布控处理
*
* @param rabbitMqVehicle 消息体
* @param deployId 布控任务id
*/
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
702
|
private void rabbitMqMsgPlateNumberHandler(RabbitMQVehicle rabbitMqVehicle, String deployId) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
703
704
705
706
707
708
709
710
711
712
713
714
715
716
|
String latitude = rabbitMqVehicle.getLatitude();
String longitude = rabbitMqVehicle.getLongitude();
String snapshotUrl = rabbitMqVehicle.getSnapshoturl();
Long pictime = rabbitMqVehicle.getPictime();
String vehiclePlateHphm = rabbitMqVehicle.getVehicle_plate_hphm();
PlateAlarmMsg plateAlarmMsg = null;
String deployLib = (String) redisTemplate.opsForHash().get(GlobalUtil.DEPLOY_LIB, deployId);
if (null != vehiclePlateHphm) {
if (null != deployLib) {
if (deployLib.contains(vehiclePlateHphm)) {
Integer status = (Integer) redisTemplate.opsForHash().get(deployId + "|" + GlobalUtil.DEPLOY_PLATE_NUM, vehiclePlateHphm);
if (status != null && 0 == status) {
plateAlarmMsg = PlateAlarmMsg.builder().id(null).baseId(rabbitMqVehicle.getId()).deployId(deployId)
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
717
|
.longitude(longitude).latitude(latitude)
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
|
.picTime(pictime).alarmTime(DateUtil.now()).snapshotUrl(snapshotUrl)
.plateNum(vehiclePlateHphm).alarmType(0).build();
}
}
}
}
plateAlarmMsgProducer(plateAlarmMsg);
}
/**
* PlateAlarmMsg 消息发生器
*
* @param plateAlarmMsg 消息体
*/
private void plateAlarmMsgProducer(PlateAlarmMsg plateAlarmMsg) {
if (plateAlarmMsg != null) {
|
68a67f36
Liu Haoyu
接口问题处理;
|
734
|
PlateAlarmMsg save = mongoTemplate.insert(plateAlarmMsg);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
735
736
737
738
739
740
741
742
743
744
745
|
String s = JSON.toJSONString(save);
redisTemplate.opsForList().leftPush("ALARM", s);
}
}
/**
* 车辆布控处理
*
* @param rabbitMqVehicle 消息体
* @param deployId 布控任务id
*/
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
746
|
private void rabbitMqMsgVehicleHandler(RabbitMQVehicle rabbitMqVehicle, String deployId) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
|
String latitude = rabbitMqVehicle.getLatitude();
String longitude = rabbitMqVehicle.getLongitude();
String snapshotUrl = rabbitMqVehicle.getSnapshoturl();
Long pictime = rabbitMqVehicle.getPictime();
double[] vehicleFeaFeature = rabbitMqVehicle.getVehicle_fea_feature();
double distance1 = compareDistance.getDistance(vehicleFeaFeature);
String vehiclePlateHphm = rabbitMqVehicle.getVehicle_plate_hphm();
String deployLib = (String) redisTemplate.opsForHash().get(GlobalUtil.DEPLOY_LIB, deployId);
PlateAlarmMsg plateAlarmMsg = null;
if (null != vehiclePlateHphm) {
String vehicleIdStr = (String) redisTemplate.opsForHash().get("vehiclePlate", vehiclePlateHphm);
if (vehicleIdStr != null) {
Integer status = (Integer) redisTemplate.opsForHash().get(deployId + "|" + deployLib, vehicleIdStr);
if (status == null || 0 == status) {
float[] vehicleIds = (float[]) redisTemplate.opsForHash().get("vehicleId", vehicleIdStr);
if (vehicleIds != null) {
double[] features = floatArrToDoubleArr(vehicleIds);
double distance = compareDistance.getDistance(features);
double v = compareDistance.simDistance(vehicleFeaFeature, distance1, features, distance);
v = v > 1 ? 1.00 : v;
String vehicleUrl = (String) redisTemplate.opsForHash().get("vehicleUrl", vehicleIdStr);
//将数据储存到mongo中
plateAlarmMsg = PlateAlarmMsg.builder().id(null).baseId(rabbitMqVehicle.getId()).deployId(deployId)
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
771
|
.longitude(longitude).latitude(latitude)
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
|
.libUrl(vehicleUrl).picTime(pictime).alarmTime(DateUtil.now()).snapshotUrl(snapshotUrl)
.plateNum(vehiclePlateHphm).alarmType(1).similarity(v).libId(vehicleIdStr).build();
}
}
}
}
if (plateAlarmMsg == null) {
double max = 0;
String key = "";
// 获取工作中的所有车辆信息
Set<String> openVehicleIds = new HashSet<>();
if (deployLib != null) {
for (String detailDeployLib : deployLib.split(",")) {
Map<String, Integer> vehicleIdStatusMap = redisTemplate.opsForHash().entries(deployId + "|" + detailDeployLib);
openVehicleIds.addAll(vehicleIdStatusMap.entrySet().stream().filter(entry -> 0 == entry.getValue())
.map(Map.Entry::getKey).collect(Collectors.toList()));
}
}
// 判断是否需要报警
for (String openVehicleId : openVehicleIds) {
float[] floats = (float[]) redisTemplate.opsForHash().get("vehicleId", openVehicleId);
if (floats == null) {
continue;
}
double[] featureArr = floatArrToDoubleArr(floats);
double distance = compareDistance.getDistance(featureArr);
double similar = compareDistance.simDistance(vehicleFeaFeature, distance1, featureArr, distance);
if (max < similar) {
max = similar;
key = openVehicleId;
if (max >= 1) {
max = 1.00;
break;
}
}
}
if (max >= (float) redisTemplate.opsForHash().get(GlobalUtil.DEPLOYTHRESLD, deployId)) {
String vehicleUrl = (String) redisTemplate.opsForHash().get("vehicleUrl", key);
plateAlarmMsg = PlateAlarmMsg.builder().id(null).baseId(rabbitMqVehicle.getId()).deployId(deployId)
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
812
|
.longitude(longitude).latitude(latitude)
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
|
.libUrl(vehicleUrl).picTime(pictime).alarmTime(DateUtil.now()).snapshotUrl(snapshotUrl)
.alarmType(1).similarity(max).build();
}
}
plateAlarmMsgProducer(plateAlarmMsg);
}
/**
* float数组转 double数组
*
* @param floats float数组
* @return double数组
*/
private double[] floatArrToDoubleArr(float[] floats) {
double[] result = new double[floats.length];
for (int i = 0; i < floats.length; i++) {
result[i] = floats[i];
}
return result;
}
/**
* 人像布控处理
*
* @param personMsg 消息体
* @param deployId 任务id
*/
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
840
|
public void rabbitMqPersonHandler(PersonMsg personMsg, String deployId) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
841
|
float[] fea = personMsg.getFea();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
842
843
844
845
846
847
848
849
850
851
852
853
|
String longitude = personMsg.getLongitude();
String latitude = personMsg.getLatitude();
String url = personMsg.getUrl();
long captureTime = personMsg.getCaptureTime();
String snapshotUrl = personMsg.getImageUrl();
HashMap<String, Object> map = new HashMap<>(16);
map.put("topN", 3);
map.put("threshold", 0);
map.put("threadNum", 2);
map.put("feature", fea);
String s = vehicleEngine.searchDataFromDeployDb(map);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
854
|
log.debug("searchDataFromDeployDb: " + s);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
855
856
857
858
|
ResponseParamPerson responseParamPerson = JSON.parseObject(s, ResponseParamPerson.class);
String code = responseParamPerson.getCode();
if ("0".equals(code)) {
List<PersonIdAndScore> result = responseParamPerson.getResult();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
859
|
if (result != null && result.size() > 0) {
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
860
861
|
for (PersonIdAndScore personIdAndScore : result) {
String retrieveKey = personIdAndScore.getRetrieveKey();
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
862
|
log.debug("retrieveKey: " + retrieveKey);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
863
864
865
866
867
868
|
String[] split = retrieveKey.split("&");
String key = deployId + "|" + split[1];
String deployLib = (String) redisTemplate.opsForHash().get(GlobalUtil.DEPLOY_LIB, deployId);
if (deployLib.contains(split[1])) {
Object staus = redisTemplate.opsForHash().get(key, Integer.parseInt(split[0]));
if (staus != null && Integer.parseInt(staus.toString()) == 0) {
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
869
|
float score = Float.parseFloat(personIdAndScore.getScore());
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
870
|
PlateAlarmMsg plateAlarmMsg = PlateAlarmMsg.builder().id(null).baseId(personMsg.getPersonId())
|
fddd4673
Liu Haoyu
去掉设备相关内容;
|
871
|
.deployId(deployId).longitude(longitude).latitude(latitude).libId(split[0])
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
872
873
|
.libUrl(split[2]).picTime(captureTime).alarmTime(DateUtil.now()).snapshotUrl(url)
.plateNum(null).alarmType(2).similarity(score).build();
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
874
|
log.debug("plateAlarmMsg: " + plateAlarmMsg.toString());
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
875
876
|
plateAlarmMsgProducer(plateAlarmMsg);
break;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
|
}
}
}
}
}
}
/**
* 获取底库的相关信息
*
* @param id 底库数据id
* @return 底库数据
*/
@Override
public JSONObject getLibMsgById(String id) {
JSONObject jsonObject = new JSONObject();
try {
List<UploadVehicleDbResult> uploadVehicleDbResults = mongoTemplate.find(Query.query(Criteria.where("id").is(id)), UploadVehicleDbResult.class);
RabbitMQInfo rabbitMQInfo = null;
if (uploadVehicleDbResults.size() > 0) {
UploadVehicleDbResult uploadVehicleDbResult = uploadVehicleDbResults.get(0);
rabbitMQInfo = uploadVehicleDbResultToRabbitInfo(uploadVehicleDbResult);
}
if (rabbitMQInfo != null) {
jsonObject.put("code", 200);
jsonObject.put("message", "success");
jsonObject.put("data", rabbitMQInfo);
} else {
jsonObject.put("code", 201);
jsonObject.put("message", "没有符合要求的数据");
jsonObject.put("data", rabbitMQInfo);
}
} catch (Exception e) {
jsonObject.put("code", 202);
jsonObject.put("message", "请检查数据准确性");
jsonObject.put("data", "");
e.printStackTrace();
}
return jsonObject;
}
private RabbitMQInfo uploadVehicleDbResultToRabbitInfo(UploadVehicleDbResult uploadVehicleDbResult) {
final String nullStatus = " ";
RabbitMQInfo rabbitMQInfo = new RabbitMQInfo();
VehicleInfoParam vehicleInfoParam = uploadVehicleDbResult.getVehicleInfoParam();
//封装数据信息
//增加车头的检测坐标值
SyRectParam syRectParam = vehicleInfoParam.getVehicle_detect_res().getSyRectParam();
if (syRectParam != null && null != uploadVehicleDbResult.getImageUrl()) {
//获取抓拍图
String snapshotBase64 = VehicleDetailsUtils.picToSnapshot(uploadVehicleDbResult.getImageUrl(),
syRectParam.getLeft(), syRectParam.getTop(), syRectParam.getWidth(), syRectParam.getHeight());
rabbitMQInfo.setSnapshot(snapshotBase64);
}
// id; //车辆id
rabbitMQInfo.setId(uploadVehicleDbResult.getId());
// picurl; //图片的路径
rabbitMQInfo.setPicurl(uploadVehicleDbResult.getImageUrl());
// vehicleplatetype; //车牌类型
int vehicleplatetype = vehicleInfoParam.getVehicle_plate_det_recg_res().getType();
String vehiclePlateTypeName = RelationMappingUtil.getVehiclePlateType(vehicleplatetype);
rabbitMQInfo.setVehicleplatetype(vehiclePlateTypeName);
// vehicle_plate_numScore; //号牌可信度
double vehicle_plate_numScore = vehicleInfoParam.getVehicle_plate_det_recg_res().getNumScore();
BigDecimal bg = new BigDecimal(vehicle_plate_numScore).setScale(2, RoundingMode.UP);
float vehiclePlateNumScore = (float) bg.doubleValue();
rabbitMQInfo.setVehicle_plate_numScore(vehiclePlateNumScore);
// vehicle_color_index; //车辆颜色;
int vehicle_color_index = vehicleInfoParam.getVehicle_color_res().getIndex();
String vehicleColor = RelationMappingUtil.getVehicleColor(vehicle_color_index);
rabbitMQInfo.setVehicle_color_index(vehicleColor);
// vehicle_special_type; //特殊品类车类型
int vehicle_special_type = vehicleInfoParam.getVehicle_special_res().getType();
String vehicleSpecialType = RelationMappingUtil.getVehicleSpecialType(vehicle_special_type);
rabbitMQInfo.setVehicle_special_type(vehicleSpecialType);
// vehicleIllegalDriverPersonStatus;
int vehicleIllegalDriverPersonStatus = vehicleInfoParam.getVehicle_illegal_det_res().getDriver().getPerson().getStatus();
String vehicleIllegalStatus3;
if (vehicleIllegalDriverPersonStatus == 1003) {
vehicleIllegalStatus3 = "无人";
} else if (vehicleIllegalDriverPersonStatus == 1004) {
vehicleIllegalStatus3 = "有人";
} else {
vehicleIllegalStatus3 = "不确定有无人";
}
rabbitMQInfo.setVehicle_illegal_driver_person_status(vehicleIllegalStatus3);
if ("有人".equals(vehicleIllegalStatus3)) {
// vehicle_illegal_driver_smoke_status;
int vehicle_illegal_driver_smoke_status = vehicleInfoParam.getVehicle_illegal_det_res().getDriver().getSmoke().getStatus();
String vehicleIllegalStatus;
if (vehicle_illegal_driver_smoke_status == 1000) {
vehicleIllegalStatus = "吸烟";
} else if (vehicle_illegal_driver_smoke_status == 1001) {
vehicleIllegalStatus = "未吸烟";
} else {
vehicleIllegalStatus = "不确定吸烟";
}
rabbitMQInfo.setVehicle_illegal_driver_smoke_status(vehicleIllegalStatus);
// vehicle_illegal_driver_belt_status;
int vehicle_illegal_driver_belt_status = vehicleInfoParam.getVehicle_illegal_det_res().getDriver().getBelt().getStatus();
String vehicleIllegalStatus1;
if (vehicle_illegal_driver_belt_status == 1000) {
vehicleIllegalStatus1 = "未系安全带";
} else if (vehicle_illegal_driver_belt_status == 1001) {
vehicleIllegalStatus1 = "系安全带";
} else {
vehicleIllegalStatus1 = "不确定系安全带";
}
rabbitMQInfo.setVehicle_illegal_driver_belt_status(vehicleIllegalStatus1);
// vehicle_illegal_driver_phone_status;
int vehicle_illegal_driver_phone_status = vehicleInfoParam.getVehicle_illegal_det_res().getDriver().getPhone().getStatus();
String vehicleIllegalStatus2;
if (vehicle_illegal_driver_phone_status == 1000) {
vehicleIllegalStatus2 = "打电话";
} else if (vehicle_illegal_driver_phone_status == 1001) {
vehicleIllegalStatus2 = "未打电话";
} else {
vehicleIllegalStatus2 = "不确定打电话";
}
rabbitMQInfo.setVehicle_illegal_driver_phone_status(vehicleIllegalStatus2);
} else {
rabbitMQInfo.setVehicle_illegal_driver_smoke_status(nullStatus);
rabbitMQInfo.setVehicle_illegal_driver_belt_status(nullStatus);
rabbitMQInfo.setVehicle_illegal_driver_phone_status(nullStatus);
}
// vehicle_illegal_copilot_person_status;
int vehicle_illegal_copilot_person_status = vehicleInfoParam.getVehicle_illegal_det_res().getCopilot().getPerson().getStatus();
String vehicleIllegalStatus7;
if (vehicle_illegal_copilot_person_status == 1003) {
vehicleIllegalStatus7 = "无人";
} else if (vehicle_illegal_copilot_person_status == 1004) {
vehicleIllegalStatus7 = "有人";
} else {
vehicleIllegalStatus7 = "不确定有无人";
}
rabbitMQInfo.setVehicle_illegal_copilot_person_status(vehicleIllegalStatus7);
if ("有人".equals(vehicleIllegalStatus7)) {
// vehicle_illegal_copilot_smoke_status;
int vehicle_illegal_copilot_smoke_status = vehicleInfoParam.getVehicle_illegal_det_res().getCopilot().getSmoke().getStatus();
String vehicleIllegalStatus4;
if (vehicle_illegal_copilot_smoke_status == 1000) {
vehicleIllegalStatus4 = "吸烟";
} else if (vehicle_illegal_copilot_smoke_status == 1001) {
vehicleIllegalStatus4 = "未吸烟";
} else {
vehicleIllegalStatus4 = "不确定吸烟";
}
rabbitMQInfo.setVehicle_illegal_copilot_smoke_status(vehicleIllegalStatus4);
// vehicle_illegal_copilot_belt_status;
int vehicle_illegal_copilot_belt_status = vehicleInfoParam.getVehicle_illegal_det_res().getCopilot().getBelt().getStatus();
String vehicleIllegalStatus5;
if (vehicle_illegal_copilot_belt_status == 1000) {
vehicleIllegalStatus5 = "未系安全带";
} else if (vehicle_illegal_copilot_belt_status == 1001) {
vehicleIllegalStatus5 = "系安全带";
} else {
vehicleIllegalStatus5 = "不确定系安全带";
}
rabbitMQInfo.setVehicle_illegal_copilot_belt_status(vehicleIllegalStatus5);
// vehicle_illegal_copilot_phone_status;
int vehicle_illegal_copilot_phone_status = vehicleInfoParam.getVehicle_illegal_det_res().getCopilot().getPhone().getStatus();
String vehicleIllegalStatus6;
if (vehicle_illegal_copilot_phone_status == 1000) {
vehicleIllegalStatus6 = "打电话";
} else if (vehicle_illegal_copilot_phone_status == 1001) {
vehicleIllegalStatus6 = "未打电话";
} else {
vehicleIllegalStatus6 = "不确定打电话";
}
rabbitMQInfo.setVehicle_illegal_copilot_phone_status(vehicleIllegalStatus6);
} else {
rabbitMQInfo.setVehicle_illegal_copilot_smoke_status(nullStatus);
rabbitMQInfo.setVehicle_illegal_copilot_belt_status(nullStatus);
rabbitMQInfo.setVehicle_illegal_copilot_phone_status(nullStatus);
}
// vehicle_recg_type; //车辆类型
rabbitMQInfo.setVehicle_recg_type(vehicleInfoParam.getVehicle_recg_res().getVehicle_type());
// vehicle_recg_freight_ton; //吨数
rabbitMQInfo.setVehicle_recg_freight_ton(vehicleInfoParam.getVehicle_recg_res().getFreight_ton());
// vehicle_recg_name_score; //品牌可信度
double vehicle_recg_name_score = vehicleInfoParam.getVehicle_recg_res().getName_score();
BigDecimal bigDecimal = new BigDecimal(vehicle_recg_name_score).setScale(2, RoundingMode.UP);
float vehicleRecgNameScore = (float) bigDecimal.doubleValue();
rabbitMQInfo.setVehicle_recg_name_score(vehicleRecgNameScore);
// vehicle_plate_hphm; //车辆号牌
rabbitMQInfo.setVehicle_plate_hphm(uploadVehicleDbResult.getPlateNum());
// vehicle_plate_status;
double vehicle_plate_numScore1 = vehicleInfoParam.getVehicle_plate_det_recg_res().getNumScore();
String vehiclePlateStatus;
if (vehicle_plate_numScore1 == 0) {
//无号牌
vehiclePlateStatus = "无号牌";
} else {
VehiclePlateNumParam[] vehicle_plate_plateNumParams = vehicleInfoParam.getVehicle_plate_det_recg_res().getPlateNumParams();
String chara = null;
for (int i = 0; i < 7; i++) {
VehiclePlateNumParam ppnp = vehicle_plate_plateNumParams[i];
double maxprob = ppnp.getMaxprob();
if (maxprob == 0) {
chara = "污损号牌";
}
}
if (chara == null) {
//有号牌
vehiclePlateStatus = "完整号牌";
} else {
//污损号牌
vehiclePlateStatus = "污损号牌";
}
}
rabbitMQInfo.setVehicle_plate_status(vehiclePlateStatus);
// clxh;
StringBuffer sb = new StringBuffer();
String vehicle_recg_brand = vehicleInfoParam.getVehicle_recg_res().getVehicle_brand();
sb.append(vehicle_recg_brand);
String vehicle_recg_subbrand = vehicleInfoParam.getVehicle_recg_res().getVehicle_subbrand();
if (vehicle_recg_subbrand != null) {
sb.append("-").append(vehicle_recg_subbrand);
}
String vehicle_recg_issue_year = vehicleInfoParam.getVehicle_recg_res().getVehicle_issue_year();
if (vehicle_recg_issue_year != null) {
sb.append("-").append(vehicle_recg_issue_year);
}
rabbitMQInfo.setClxh(sb.toString());
return rabbitMQInfo;
}
}
|