|
@ -74,12 +74,6 @@ public class MonitorManageServiceImpl implements MonitorManageService {
|
74
|
74
|
|
75
|
75
|
//监听文件目录,加载文件
|
76
|
76
|
loadFileList();
|
77
|
|
//等到10秒
|
78
|
|
// Thread.sleep(10000);
|
79
|
|
// //保存图片文件并发送kafka
|
80
|
|
// saveImageFile();
|
81
|
|
// //保存视频文件并发送kafka
|
82
|
|
// saveVideoFile();
|
83
|
77
|
|
84
|
78
|
}
|
85
|
79
|
|
|
@ -108,264 +102,4 @@ public class MonitorManageServiceImpl implements MonitorManageService {
|
108
|
102
|
}
|
109
|
103
|
}
|
110
|
104
|
|
111
|
|
private void saveImageFile(){
|
112
|
|
new Timer().schedule(new TimerTask() {
|
113
|
|
@SneakyThrows
|
114
|
|
@Override
|
115
|
|
public void run() {
|
116
|
|
Map<String,List> imgFileMap = FileUtils.imgFileMap;
|
117
|
|
List<String> keyList = mapTransitionList(imgFileMap);
|
118
|
|
String deviceCode = "";
|
119
|
|
String fileType = "";
|
120
|
|
String filePath = "";
|
121
|
|
String fileName = "";
|
122
|
|
String dateTime = "";
|
123
|
|
String[] keyArr;
|
124
|
|
MultipartFile multipartFile = null;
|
125
|
|
Map<String, String> minioFileMap = null;
|
126
|
|
AiIdenLogDto aiIdenLogDto = null;
|
127
|
|
List<String> fileList = null;
|
128
|
|
Iterator<String> imgiterator = null;
|
129
|
|
MonitorVideoLogDto monitorVideoLogDto = null;
|
130
|
|
String time = "";
|
131
|
|
String bucketName = "";
|
132
|
|
String aiResponseData = "";
|
133
|
|
for(String key:keyList){
|
134
|
|
keyArr = key.split("~!@");
|
135
|
|
deviceCode = keyArr[0];
|
136
|
|
fileType = keyArr[1];
|
137
|
|
|
138
|
|
fileList = imgFileMap.get(key);
|
139
|
|
imgiterator = fileList.iterator();
|
140
|
|
|
141
|
|
while (imgiterator.hasNext()) {
|
142
|
|
filePath = imgiterator.next();
|
143
|
|
aiIdenLogDto = new AiIdenLogDto();
|
144
|
|
monitorVideoLogDto = new MonitorVideoLogDto();
|
145
|
|
fileName = filePath.substring(filePath.lastIndexOf(MonitorManageConsts.getSystemSeparator())+1,filePath.length());
|
146
|
|
if(fileType.equals(MonitorManageConsts.FILE_TYPE_IMG)){
|
147
|
|
// bucketName = minioConfig.getBucketAiVideo();
|
148
|
|
// time = fileName.substring(5,19);
|
149
|
|
// dateTime = DateUtils.formatDate(DateUtils.convertDate(time,DateUtils.PURE_DATETIMEHHMM_PATTERN),DateUtils.NORM_DATETIME_HHMM_PATTERN);
|
150
|
|
// monitorVideoLogDto.setBeginTime(dateTime + ":00");
|
151
|
|
// monitorVideoLogDto.setEndTime(dateTime + ":59");
|
152
|
|
//
|
153
|
|
// }else{
|
154
|
|
bucketName = minioConfig.getBucketAiImage();
|
155
|
|
time = fileName.substring(3,17);
|
156
|
|
dateTime = DateUtils.formatDate(DateUtils.convertDate(time,DateUtils.PURE_DATETIMEHHMM_PATTERN),DateUtils.NORM_DATETIME_PATTERN);
|
157
|
|
aiIdenLogDto.setTaskExecuteTime(DateUtils.getSysDateTime());
|
158
|
|
aiIdenLogDto.setIdenPictureSnapDate(dateTime);
|
159
|
|
}
|
160
|
|
//文件上传到 minio文件服务器
|
161
|
|
multipartFile = new CommonsMultipartFile(FileUtils.createFileItem(new File(filePath),fileName));
|
162
|
|
|
163
|
|
log.info("保存图片文件");
|
164
|
|
minioFileMap = fileManageService.uploadFile(multipartFile,bucketName,deviceCode,null);
|
165
|
|
|
166
|
|
|
167
|
|
if(fileType.equals(MonitorManageConsts.FILE_TYPE_IMG)){
|
168
|
|
// monitorVideoLogDto.setTopic(topicAiVideo);//视频历史记录TOPIC
|
169
|
|
// monitorVideoLogDto.setVideoUrl(minioFileMap.get("fileId"));
|
170
|
|
// monitorVideoLogDto.setResourceToolCode(deviceCode);
|
171
|
|
// kafkaProcess.processKafka(monitorVideoLogDto.getTopic(), JSONObject.toJSONString(monitorVideoLogDto));
|
172
|
|
// }else{
|
173
|
|
aiIdenLogDto.setIdenVideoUrl("");
|
174
|
|
aiIdenLogDto.setIdenPictureUrl(minioFileMap.get("fileId"));
|
175
|
|
aiIdenLogDto.setResourceToolCode(deviceCode);
|
176
|
|
//安全帽识别
|
177
|
|
aiIdenLogDto.setTopic(topicAiTask);//AI识别TOPICs
|
178
|
|
|
179
|
|
//人体识别
|
180
|
|
boolean isHuman = aiworkHumanDetect(filePath);
|
181
|
|
//AI头盔检查
|
182
|
|
if(isHuman){
|
183
|
|
aiIdenLogDto = aiHelmetDetect(aiIdenLogDto,filePath);
|
184
|
|
|
185
|
|
// kafkaProcess.processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
|
186
|
|
}
|
187
|
|
}
|
188
|
|
imgiterator.remove();//使用迭代器的删除方法删除
|
189
|
|
}
|
190
|
|
|
191
|
|
}
|
192
|
|
log.info("-------等待任务--------");
|
193
|
|
}
|
194
|
|
}, 0, 5000);
|
195
|
|
}
|
196
|
|
|
197
|
|
private void saveVideoFile(){
|
198
|
|
new Timer().schedule(new TimerTask() {
|
199
|
|
@SneakyThrows
|
200
|
|
@Override
|
201
|
|
public void run() {
|
202
|
|
Map<String,List> videoFileMap = FileUtils.videoFileMap;
|
203
|
|
List<String> keyList = mapTransitionList(videoFileMap);
|
204
|
|
String deviceCode = "";
|
205
|
|
String fileType = "";
|
206
|
|
String filePath = "";
|
207
|
|
String fileName = "";
|
208
|
|
String dateTime = "";
|
209
|
|
String[] keyArr;
|
210
|
|
MultipartFile multipartFile = null;
|
211
|
|
Map<String, String> minioFileMap = null;
|
212
|
|
AiIdenLogDto aiIdenLogDto = null;
|
213
|
|
List<String> fileList = null;
|
214
|
|
Iterator<String> iterator = null;
|
215
|
|
MonitorVideoLogDto monitorVideoLogDto = null;
|
216
|
|
String time = "";
|
217
|
|
String bucketName = "";
|
218
|
|
String aiResponseData = "";
|
219
|
|
for(String key:keyList){
|
220
|
|
keyArr = key.split("~!@");
|
221
|
|
deviceCode = keyArr[0];
|
222
|
|
fileType = keyArr[1];
|
223
|
|
|
224
|
|
fileList = videoFileMap.get(key);
|
225
|
|
iterator = fileList.iterator();
|
226
|
|
|
227
|
|
while (iterator.hasNext()) {
|
228
|
|
filePath = iterator.next();
|
229
|
|
aiIdenLogDto = new AiIdenLogDto();
|
230
|
|
monitorVideoLogDto = new MonitorVideoLogDto();
|
231
|
|
fileName = filePath.substring(filePath.lastIndexOf(MonitorManageConsts.getSystemSeparator())+1,filePath.length());
|
232
|
|
if(fileType.equals(MonitorManageConsts.FILE_TYPE_VIDEO)){
|
233
|
|
bucketName = minioConfig.getBucketAiVideo();
|
234
|
|
time = fileName.substring(5,19);
|
235
|
|
dateTime = DateUtils.formatDate(DateUtils.convertDate(time,DateUtils.PURE_DATETIMEHHMM_PATTERN),DateUtils.NORM_DATETIME_HHMM_PATTERN);
|
236
|
|
monitorVideoLogDto.setBeginTime(dateTime + ":00");
|
237
|
|
monitorVideoLogDto.setEndTime(dateTime + ":59");
|
238
|
|
|
239
|
|
}
|
240
|
|
//文件上传到 minio文件服务器
|
241
|
|
multipartFile = new CommonsMultipartFile(FileUtils.createFileItem(new File(filePath),fileName));
|
242
|
|
|
243
|
|
log.info("保存文件");
|
244
|
|
minioFileMap = fileManageService.uploadFile(multipartFile,bucketName,deviceCode,null);
|
245
|
|
|
246
|
|
if(fileType.equals(MonitorManageConsts.FILE_TYPE_VIDEO)){
|
247
|
|
monitorVideoLogDto.setTopic(topicAiVideo);//视频历史记录TOPIC
|
248
|
|
monitorVideoLogDto.setVideoUrl(minioFileMap.get("fileId"));
|
249
|
|
monitorVideoLogDto.setResourceToolCode(deviceCode);
|
250
|
|
kafkaProcess.processKafka(monitorVideoLogDto.getTopic(), JSONObject.toJSONString(monitorVideoLogDto));
|
251
|
|
}
|
252
|
|
iterator.remove();//使用迭代器的删除方法删除
|
253
|
|
}
|
254
|
|
|
255
|
|
}
|
256
|
|
log.info("-------等待任务--------");
|
257
|
|
}
|
258
|
|
}, 60000, 60000);
|
259
|
|
}
|
260
|
|
|
261
|
|
/**
|
262
|
|
* AI头盔检查
|
263
|
|
* @param aiIdenLogDto
|
264
|
|
* @return
|
265
|
|
*/
|
266
|
|
private AiIdenLogDto aiHelmetDetect(AiIdenLogDto aiIdenLogDto,String aifilePath){
|
267
|
|
try {
|
268
|
|
log.info("开始AI处理...");
|
269
|
|
//安全帽识别
|
270
|
|
String aiResponseData = ebcAiService.helmetDetect(ImageBase64Converter.convertFileToBase64(aifilePath), Strings.EMPTY, Strings.EMPTY);
|
271
|
|
// String aiResponseData = ebcAiService.helmetDetect(ImageBase64Converter.convertInputStreamToBase64(multipartFile.getInputStream()), Strings.EMPTY, Strings.EMPTY);
|
272
|
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);// JSONUtil.formatJsonStr(aiResponseData);
|
273
|
|
System.out.println("AI 识别结果: "+jsonObject);
|
274
|
|
IdenResultDto idenResultDto = null;
|
275
|
|
List<IdenResultDto> idenResultDtoList = null;
|
276
|
|
if(jsonObject.getString("Status").equals("Ok")){
|
277
|
|
idenResultDtoList = new ArrayList<>();
|
278
|
|
JSONArray jsonoArray = JSONArray.parseArray(jsonObject.getString("Result"));
|
279
|
|
if(jsonoArray.size()>0){
|
280
|
|
for(int i=0;i<jsonoArray.size();i++){
|
281
|
|
JSONObject resultObj = JSONObject.parseObject(jsonoArray.get(i).toString());
|
282
|
|
String aiClassName = resultObj.getString("class");
|
283
|
|
// safety_hat表示安全帽;ordinart_hat表示普通帽子;chef_hat表示厨师帽;none表示未戴帽子
|
284
|
|
if(aiClassName.equals("none")){
|
285
|
|
idenResultDto =new IdenResultDto();
|
286
|
|
idenResultDto.setAlarmEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
287
|
|
idenResultDto.setAlarmType(MonitorManageConsts.AI_ALARM_TYPE_WEA);
|
288
|
|
idenResultDto.setAlarmMemo("未戴帽子");
|
289
|
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT_ALARM);
|
290
|
|
idenResultDtoList.add(idenResultDto);
|
291
|
|
aiIdenLogDto.setIdenResult(idenResultDtoList);
|
292
|
|
aiIdenLogDto.setAiIdenModel(MonitorManageConsts.AI_MODEL_CLOTHING_CODE);
|
293
|
|
}else{
|
294
|
|
// if(aiClassName.equals("safety_hat")){
|
295
|
|
idenResultDto =new IdenResultDto();
|
296
|
|
idenResultDto.setAlarmEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
297
|
|
idenResultDto.setAlarmType(aiClassName);
|
298
|
|
idenResultDto.setAlarmMemo(aiClassName);
|
299
|
|
// }else if(aiClassName.equals("ordinart_hat")){
|
300
|
|
// idenResultDto =new IdenResultDto();
|
301
|
|
// idenResultDto.setAlarmEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
302
|
|
// idenResultDto.setAlarmType("ordinart_hat");
|
303
|
|
// idenResultDto.setAlarmType("普通帽子");
|
304
|
|
// }else if(aiClassName.equals("chef_hat")){
|
305
|
|
// idenResultDto =new IdenResultDto();
|
306
|
|
// idenResultDto.setAlarmEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
307
|
|
// idenResultDto.setAlarmType("chef_hat");
|
308
|
|
// idenResultDto.setAlarmType("厨师帽");
|
309
|
|
// }
|
310
|
|
|
311
|
|
idenResultDtoList.add(idenResultDto);
|
312
|
|
aiIdenLogDto.setIdenResult(idenResultDtoList);
|
313
|
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT);
|
314
|
|
aiIdenLogDto.setAiIdenModel(MonitorManageConsts.AI_MODEL_CLOTHING_CODE);
|
315
|
|
}
|
316
|
|
}
|
317
|
|
log.info("识别成功,推送KAFKA消息");
|
318
|
|
kafkaProcess.processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
|
319
|
|
}else{
|
320
|
|
log.info("没有识别到人,不推送KAFKA消息");
|
321
|
|
}
|
322
|
|
}
|
323
|
|
//AI模型
|
324
|
|
// aiIdenLogDto.setAiIdenModel(MonitorManageConsts.AI_MODEL_CLOTHING_CODE);
|
325
|
|
}catch (Exception e){
|
326
|
|
log.error("AI处理异常");
|
327
|
|
}
|
328
|
|
return aiIdenLogDto;
|
329
|
|
}
|
330
|
|
|
331
|
|
/**
|
332
|
|
* AI人体识别
|
333
|
|
* @param aifilePath
|
334
|
|
* @return
|
335
|
|
*/
|
336
|
|
private boolean aiworkHumanDetect(String aifilePath){
|
337
|
|
boolean isHuman = false;
|
338
|
|
try {
|
339
|
|
//安全帽识别
|
340
|
|
String aiResponseData = ebcAiService.workClothesDetect(ImageBase64Converter.convertFileToBase64(aifilePath), true,true,0.9f);
|
341
|
|
|
342
|
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);// JSONUtil.formatJsonStr(aiResponseData);
|
343
|
|
if(jsonObject.getString("Status").equals("Ok")){
|
344
|
|
JSONArray jsonoArray = JSONArray.parseArray(jsonObject.getString("Result"));
|
345
|
|
for(int i=0;i<jsonoArray.size();i++){
|
346
|
|
JSONObject resultObj = JSONObject.parseObject(jsonoArray.get(i).toString());
|
347
|
|
String aiClassName = resultObj.getString("lable");
|
348
|
|
// safety_hat表示安全帽;ordinart_hat表示普通帽子;chef_hat表示厨师帽;none表示未戴帽子
|
349
|
|
if(aiClassName.equals("person")){
|
350
|
|
isHuman = true;
|
351
|
|
}
|
352
|
|
}
|
353
|
|
}
|
354
|
|
}catch (Exception e){
|
355
|
|
log.error("AI处理异常");
|
356
|
|
}
|
357
|
|
return isHuman;
|
358
|
|
}
|
359
|
|
|
360
|
|
public static List<String> mapTransitionList(Map map) {
|
361
|
|
List list = new ArrayList();
|
362
|
|
Iterator iter = map.entrySet().iterator(); // 获得map的Iterator
|
363
|
|
while (iter.hasNext()) {
|
364
|
|
Map.Entry entry = (Map.Entry) iter.next();
|
365
|
|
list.add(entry.getKey());
|
366
|
|
}
|
367
|
|
return list;
|
368
|
|
}
|
369
|
|
|
370
|
|
|
371
|
105
|
}
|