|
@ -36,6 +36,8 @@ import com.alibaba.fastjson.JSONObject;
|
36
|
36
|
|
37
|
37
|
import lombok.extern.slf4j.Slf4j;
|
38
|
38
|
|
|
39
|
import javax.sound.sampled.Line;
|
|
40
|
|
39
|
41
|
@Slf4j
|
40
|
42
|
@Service
|
41
|
43
|
public class KafkaProcessImpl implements KafkaProcess {
|
|
@ -129,7 +131,6 @@ public class KafkaProcessImpl implements KafkaProcess {
|
129
|
131
|
}
|
130
|
132
|
// 文件上传到 minio文件服务器
|
131
|
133
|
multipartFile = new CommonsMultipartFile(FileUtils.createFileItem(new File(filePath), fileName));
|
132
|
|
|
133
|
134
|
log.info("保存图片文件:"+fileName);
|
134
|
135
|
minioFileMap = fileManageService.uploadFile(multipartFile, bucketName, deviceCode, null);
|
135
|
136
|
|
|
@ -291,13 +292,13 @@ public class KafkaProcessImpl implements KafkaProcess {
|
291
|
292
|
*/
|
292
|
293
|
private AiIdenLogDto aiHelmetDetect(AiIdenLogDto aiIdenLogDto, String aifilePath) {
|
293
|
294
|
try {
|
294
|
|
log.info("开始AI处理...");
|
|
295
|
log.info("开始AI帽子识别处理...");
|
295
|
296
|
// 安全帽识别
|
296
|
297
|
String aiResponseData = ebcAiService.helmetDetect(ImageBase64Converter.convertFileToBase64(aifilePath),
|
297
|
298
|
Strings.EMPTY, Strings.EMPTY);
|
298
|
299
|
// String aiResponseData = ebcAiService.helmetDetect(ImageBase64Converter.convertInputStreamToBase64(multipartFile.getInputStream()), Strings.EMPTY, Strings.EMPTY);
|
299
|
300
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);// JSONUtil.formatJsonStr(aiResponseData);
|
300
|
|
System.out.println("AI 识别结果: " + jsonObject);
|
|
301
|
System.out.println("AI帽子识别结果: " + jsonObject);
|
301
|
302
|
IdenResultDto idenResultDto = null;
|
302
|
303
|
List<IdenResultDto> idenResultDtoList = null;
|
303
|
304
|
if (jsonObject.getString("Status").equals("Ok")) {
|
|
@ -342,7 +343,7 @@ public class KafkaProcessImpl implements KafkaProcess {
|
342
|
343
|
// AI模型
|
343
|
344
|
// aiIdenLogDto.setAiIdenModel(MonitorManageConsts.AI_MODEL_CLOTHING_CODE);
|
344
|
345
|
} catch (Exception e) {
|
345
|
|
log.error("AI处理异常");
|
|
346
|
log.error("AI处理异常,帽子识别");
|
346
|
347
|
}
|
347
|
348
|
return aiIdenLogDto;
|
348
|
349
|
}
|
|
@ -375,7 +376,6 @@ public class KafkaProcessImpl implements KafkaProcess {
|
375
|
376
|
log.info("开始AI人数识别处理...");
|
376
|
377
|
String aiResponseData = ebcAiService.headDetect(ImageBase64Converter.convertFileToBase64(aifilePath), true,
|
377
|
378
|
0.9f);
|
378
|
|
|
379
|
379
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);
|
380
|
380
|
JSONArray jsonArray = jsonObject.getJSONArray("Result");
|
381
|
381
|
if (!CollectionUtils.isEmpty(jsonArray)) {
|
|
@ -384,9 +384,8 @@ public class KafkaProcessImpl implements KafkaProcess {
|
384
|
384
|
} else {
|
385
|
385
|
log.info("AI人数识别结果:没有人");
|
386
|
386
|
}
|
387
|
|
|
388
|
387
|
} catch (Exception e) {
|
389
|
|
log.error("AI处理异常");
|
|
388
|
log.error("AI处理异常,人数识别");
|
390
|
389
|
}
|
391
|
390
|
return isHuman;
|
392
|
391
|
}
|
|
@ -412,12 +411,10 @@ public class KafkaProcessImpl implements KafkaProcess {
|
412
|
411
|
if (resultJsonObject.getIntValue("is_match") == 0) {
|
413
|
412
|
aiIdenLogDto.setIdenResult(jsonObject.getString("result"));
|
414
|
413
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT);
|
415
|
|
|
416
|
414
|
} else {
|
417
|
415
|
aiIdenLogDto.setIdenResult(jsonObject.getString("result"));
|
418
|
416
|
aiIdenLogDto.setRelateEmployeeRoleId(resultJsonObject.getString("user_id"));
|
419
|
417
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT_ATTENDANCE);
|
420
|
|
|
421
|
418
|
}
|
422
|
419
|
|
423
|
420
|
log.info("识别成功,推送KAFKA消息");
|
|
@ -427,7 +424,7 @@ public class KafkaProcessImpl implements KafkaProcess {
|
427
|
424
|
return aiIdenLogDto;
|
428
|
425
|
}
|
429
|
426
|
} catch (Exception e) {
|
430
|
|
log.error("AI处理异常");
|
|
427
|
log.error("AI处理异常,人脸识别");
|
431
|
428
|
}
|
432
|
429
|
return aiIdenLogDto;
|
433
|
430
|
}
|
|
@ -468,16 +465,17 @@ public class KafkaProcessImpl implements KafkaProcess {
|
468
|
465
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT);
|
469
|
466
|
}
|
470
|
467
|
}
|
471
|
|
log.info("识别成功,推送KAFKA消息");
|
|
468
|
log.info("吸烟识别成功,推送KAFKA消息");
|
472
|
469
|
processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
|
|
470
|
log.info("消息推送完成");
|
473
|
471
|
}else{
|
474
|
472
|
log.info("没有识别到吸烟者,不推送KAFKA消息");
|
475
|
473
|
}
|
476
|
474
|
}else{
|
477
|
|
log.error("识别异常返回");
|
|
475
|
log.error("吸烟识别识别异常");
|
478
|
476
|
}
|
479
|
477
|
}catch(Exception e){
|
480
|
|
log.error("AI处理异常");
|
|
478
|
log.error("AI处理异常,吸烟识别");
|
481
|
479
|
}
|
482
|
480
|
return aiIdenLogDto;
|
483
|
481
|
}
|
|
@ -491,17 +489,16 @@ private AiIdenLogDto workClothesDetect(AiIdenLogDto aiIdenLogDto, String aifileP
|
491
|
489
|
//工作服识别
|
492
|
490
|
String aiResponseData=ebcAiService.workClothesDetect(ImageBase64Converter.convertFileToBase64(aifilePath),true,true,0.9f);
|
493
|
491
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);
|
494
|
|
System.out.print("AI识别结果:"+aiResponseData);
|
|
492
|
System.out.print("AI工作服识别结果:"+aiResponseData);
|
495
|
493
|
IdenResultDto idenResultDto = null;
|
496
|
494
|
List<IdenResultDto> idenResultDtoList = null;
|
497
|
495
|
if(jsonObject.getString("Status").equals("Ok")){
|
498
|
496
|
idenResultDtoList = new ArrayList<>();
|
499
|
|
JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("Result"));
|
500
|
|
if(jsonArray.size()>0){
|
501
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
502
|
|
JSONObject resultObj = JSONObject.parseObject(jsonArray.get(i).toString());
|
503
|
|
JSONObject jsonArray1 = JSONObject.parseObject(resultObj.getString("clothes"));
|
504
|
|
String aiClassName =jsonArray1.getString("class");
|
|
497
|
List<Map> resultList = JSONArray.parseArray(jsonObject.getString("Result"),Map.class);
|
|
498
|
if(resultList.size()>0){
|
|
499
|
for (int i = 0; i < resultList.size(); i++) {
|
|
500
|
JSONObject resultObject = JSONObject.parseObject(resultList.get(i).get("clothes").toString());
|
|
501
|
String aiClassName =resultObject.getString("class");
|
505
|
502
|
if(aiClassName.equals("qita")){
|
506
|
503
|
idenResultDto = new IdenResultDto();
|
507
|
504
|
idenResultDto.setAlarmEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
|
@ -524,17 +521,18 @@ private AiIdenLogDto workClothesDetect(AiIdenLogDto aiIdenLogDto, String aifileP
|
524
|
521
|
log.info("识别到工作服,工作服类型为:"+aiClassName);
|
525
|
522
|
}
|
526
|
523
|
}
|
527
|
|
log.info("识别成功,推送KAFKA消息");
|
|
524
|
log.info("工作服识别成功,推送KAFKA消息");
|
528
|
525
|
processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
|
|
526
|
log.info("消息推送完成");
|
529
|
527
|
}else {
|
530
|
528
|
log.info("没有识别到人,不推送KAFKA消息");
|
531
|
529
|
}
|
532
|
530
|
}else if(jsonObject.getString("Status").equals("ERROR")){
|
533
|
|
log.error("异常信息为:"+jsonObject.getString("Des"));
|
|
531
|
log.error("工作服识别异常:"+jsonObject.getString("Des"));
|
534
|
532
|
}
|
535
|
533
|
|
536
|
534
|
}catch(Exception e){
|
537
|
|
log.error("AI处理异常");
|
|
535
|
log.error("AI处理异常,工作服识别");
|
538
|
536
|
}
|
539
|
537
|
return aiIdenLogDto;
|
540
|
538
|
}
|
|
@ -548,17 +546,18 @@ private AiIdenLogDto instrumentDetect(AiIdenLogDto aiIdenLogDto, String aifilePa
|
548
|
546
|
//仪表识别
|
549
|
547
|
String aiResponseData=ebcAiService.instrumentDetect(ImageBase64Converter.convertFileToBase64(aifilePath),Strings.EMPTY,Strings.EMPTY,Strings.EMPTY);
|
550
|
548
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);
|
551
|
|
System.out.print("AI识别结果:"+aiResponseData);
|
552
|
|
JSONObject jsonObjectpredictions=JSONObject.parseObject(jsonObject.getString("predictions"));
|
|
549
|
System.out.print("AI仪表识别结果:"+aiResponseData);
|
|
550
|
JSONObject jsonObjectpredictions=jsonObject.getJSONObject("predictions");
|
553
|
551
|
if(jsonObjectpredictions.getString("Errors").isEmpty()){
|
554
|
552
|
if(jsonObjectpredictions.getInteger("Nums")>0){
|
555
|
553
|
log.info("识别到的仪表的数量为:"+jsonObjectpredictions.getInteger("Nums"));
|
556
|
554
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT);
|
557
|
555
|
aiIdenLogDto.setRelateEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
558
|
|
log.info("返回的仪表信息为:"+JSON.toJSONString(jsonObject));
|
559
|
|
aiIdenLogDto.setIdenResult(JSON.toJSONString(jsonObject));
|
560
|
|
log.info("识别成功,推送KAFKA消息");
|
|
556
|
log.info("返回的仪表信息为:"+jsonObjectpredictions.getString("Items"));
|
|
557
|
aiIdenLogDto.setIdenResult(jsonObjectpredictions.getString("Items"));
|
|
558
|
log.info("仪表识别成功,推送KAFKA消息");
|
561
|
559
|
processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
|
|
560
|
log.info("消息推送完成");
|
562
|
561
|
}else{
|
563
|
562
|
log.info("仪表数量为0,不推送消息");
|
564
|
563
|
}
|
|
@ -566,13 +565,10 @@ private AiIdenLogDto instrumentDetect(AiIdenLogDto aiIdenLogDto, String aifilePa
|
566
|
565
|
log.info("异常返回,异常原因为:"+jsonObjectpredictions.getString("Errors"));
|
567
|
566
|
}
|
568
|
567
|
}catch(Exception e){
|
569
|
|
log.error("AI处理异常");
|
|
568
|
log.error("AI处理异常,仪表识别");
|
570
|
569
|
}
|
571
|
570
|
return aiIdenLogDto;
|
572
|
571
|
}
|
573
|
|
|
574
|
|
|
575
|
|
|
576
|
572
|
/**
|
577
|
573
|
* 根据设备code获取监控任务详情
|
578
|
574
|
* @param deviceCode
|
|
@ -580,11 +576,9 @@ private AiIdenLogDto instrumentDetect(AiIdenLogDto aiIdenLogDto, String aifilePa
|
580
|
576
|
*/
|
581
|
577
|
private List<Map> getResourceToolAllInfo(String deviceCode) {
|
582
|
578
|
List<Map> resourceToolInfoList = new ArrayList<Map>();
|
583
|
|
|
584
|
579
|
try {
|
585
|
580
|
String url = protectionResourceUrl + "?resourceToolCode=" + deviceCode;
|
586
|
581
|
log.info("getResourceToolAllInfo method params: resourceToolCode=" + deviceCode + ", url=" + url);
|
587
|
|
|
588
|
582
|
String resultJson = HttpServiceUtil.sendRequest(url);
|
589
|
583
|
JSONObject resultData = JSON.parseObject(resultJson);
|
590
|
584
|
if (StringUtils.isEmpty(resultData.getString("data"))) {
|