|
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.aiLib;
|
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.genersoft.iot.vmp.conf.SipConfig;
|
|
|
import com.genersoft.iot.vmp.conf.security.saToken.SaAdminCheckRole;
|
|
|
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
|
@@ -144,22 +145,27 @@ public class AiControl {
|
|
|
@PostMapping("/alarm")
|
|
|
@SaIgnore
|
|
|
@ResponseBody
|
|
|
- public WVPResult alarm(BodyAiAlarm bodyAiAlarm){
|
|
|
+ public WVPResult alarm(BodyAiAlarm bodyAiAlarm) {
|
|
|
System.out.println("Received request body: " + bodyAiAlarm);
|
|
|
System.out.println("Received request body: " + bodyAiAlarm.getReco_info());
|
|
|
- logger.info("body{}",bodyAiAlarm);
|
|
|
- logger.info("devId:{}",bodyAiAlarm.getDev_id());
|
|
|
- logger.info("results:{}",bodyAiAlarm.getReco_info());
|
|
|
+ logger.info("body{}", bodyAiAlarm.toString());
|
|
|
+ logger.info("devId:{}", bodyAiAlarm.getDev_id());
|
|
|
+ logger.info("results:{}", bodyAiAlarm.getReco_info());
|
|
|
// ps upload 0-8 为兼容性集成,以防多文件上传
|
|
|
String deviceId = bodyAiAlarm.getDev_id();
|
|
|
String channelId = bodyAiAlarm.getChannelId();
|
|
|
- String arithmetic = bodyAiAlarm.getType();
|
|
|
+ // 解析ai识别结果
|
|
|
+ Ai_parse ai_parse = getAiInfo(bodyAiAlarm);
|
|
|
+ if (ai_parse == null) {
|
|
|
+ logger.error("[ai Parse] 无法解析 ai 信息");
|
|
|
+ return WVPResult.fail(ErrorCode.ERROR400.getCode(), ErrorCode.ERROR400.getMsg());
|
|
|
+ }
|
|
|
// 判断是否存在失败到的数据
|
|
|
- if (bodyAiAlarm.getReco_info().contains("failed")){
|
|
|
+ if (bodyAiAlarm.getReco_info().contains("failed")) {
|
|
|
logger.error("ai upload not reco_info");
|
|
|
- return WVPResult.fail(ErrorCode.ERROR400.getCode(),ErrorCode.ERROR400.getMsg());
|
|
|
+ return WVPResult.fail(ErrorCode.ERROR400.getCode(), ErrorCode.ERROR400.getMsg());
|
|
|
}
|
|
|
- JSONArray results_recoInfos = JSON.parseObject(bodyAiAlarm.getReco_info()).getJSONArray("results");
|
|
|
+
|
|
|
|
|
|
// List<AiAlarm> items = results_recoInfos;
|
|
|
String firmware_version = bodyAiAlarm.getFirmware_version();
|
|
@@ -180,7 +186,7 @@ public class AiControl {
|
|
|
upload7 = bodyAiAlarm.getUpload7();
|
|
|
|
|
|
logger.debug("上报ai识别接口调用 body:{}", bodyAiAlarm);
|
|
|
- logger.debug("上报ai识别接口调用 items:{}", results_recoInfos);
|
|
|
+ logger.debug("上报ai识别接口调用 items:{}", ai_parse.getAi_info());
|
|
|
logger.info("test upload{},upload0{}", upload, upload0);
|
|
|
WVPResult result = new WVPResult<>();
|
|
|
// 处理上传文件参数,合并 不同upload字段下的 file 文件
|
|
@@ -200,8 +206,8 @@ public class AiControl {
|
|
|
result.setMsg("未接收到上传文件.待处理");
|
|
|
}else{
|
|
|
//
|
|
|
- storager.saveAlarm(deviceId,channelId,arithmetic, results_recoInfos,uploads,
|
|
|
- firmware_version,timestamp,battery,signal,temp_env,temp_cpu,ccid);
|
|
|
+ storager.saveAlarm(deviceId, channelId, ai_parse.getArithmetic(), ai_parse.getAi_info(), uploads,
|
|
|
+ firmware_version, timestamp, battery, signal, temp_env, temp_cpu, ccid);
|
|
|
result.setCode(ErrorCode.SUCCESS.getCode());
|
|
|
result.setMsg("ok");
|
|
|
}
|
|
@@ -217,10 +223,76 @@ public class AiControl {
|
|
|
* @param uploads
|
|
|
*/
|
|
|
public void hbUploads(@RequestParam(value = "upload", required = false) MultipartFile upload, @RequestParam(value = "upload0", required = false) MultipartFile upload0, @RequestParam(value = "upload1", required = false) MultipartFile upload1, @RequestParam(value = "upload2", required = false) MultipartFile upload2, List<MultipartFile> uploads) {
|
|
|
- if(upload!=null&&!upload.isEmpty()){ uploads.add(upload); }
|
|
|
- if(upload0!=null&&!upload0.isEmpty()){ uploads.add(upload0); }
|
|
|
- if(upload1!=null&&!upload1.isEmpty()){ uploads.add(upload1); }
|
|
|
- if(upload2!=null&&!upload2.isEmpty()){ uploads.add(upload2); }
|
|
|
+ if (upload != null && !upload.isEmpty()) {
|
|
|
+ uploads.add(upload);
|
|
|
+ }
|
|
|
+ if (upload0 != null && !upload0.isEmpty()) {
|
|
|
+ uploads.add(upload0);
|
|
|
+ }
|
|
|
+ if (upload1 != null && !upload1.isEmpty()) {
|
|
|
+ uploads.add(upload1);
|
|
|
+ }
|
|
|
+ if (upload2 != null && !upload2.isEmpty()) {
|
|
|
+ uploads.add(upload2);
|
|
|
+ }
|
|
|
}
|
|
|
//
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取算法类型和识别后的json数据
|
|
|
+ *
|
|
|
+ * @param bodyAiAlarm
|
|
|
+ * @return Ai_parse | null
|
|
|
+ */
|
|
|
+ public Ai_parse getAiInfo(BodyAiAlarm bodyAiAlarm) {
|
|
|
+// 人脸 1, 识别从 6开始, 中间预留部分给其它可能的算法, 车牌 2
|
|
|
+ String arithmetic = "";
|
|
|
+ JSONObject reco_info = JSON.parseObject(bodyAiAlarm.getReco_info());
|
|
|
+ if (reco_info == null) {
|
|
|
+ logger.error("ai upload not reco_info");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ JSONArray ai_info = reco_info.getJSONArray("results");
|
|
|
+ if (ai_info == null) {
|
|
|
+ // 判断是否是车牌识别
|
|
|
+ ai_info = JSON.parseObject(bodyAiAlarm.getReco_info()).getJSONArray("plates");
|
|
|
+ arithmetic = "2";
|
|
|
+
|
|
|
+ }
|
|
|
+ // 判断是否为空数组
|
|
|
+ if (ai_info == null || 0 == ai_info.size()) {
|
|
|
+ logger.error("ai upload not reco_info");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 获取
|
|
|
+ // 判断是人脸还是识别算法, 人脸识别的 识别对象中包含 msgid 识别则是 id
|
|
|
+ if (arithmetic.equals("") && ai_info.getJSONObject(0).containsKey("msgid")) {
|
|
|
+ arithmetic = "1";
|
|
|
+ }
|
|
|
+ // 判断具体是哪一项识别项
|
|
|
+ if (arithmetic.equals("")) {
|
|
|
+ // 根据id 文本判断是什么识别
|
|
|
+ // "DiaoChe","TaDiao","fire","ShiGongJiXie","DaoXianYiWu","smoke"
|
|
|
+ String id = ai_info.getJSONObject(0).getString("id");
|
|
|
+ if (id.equals("DiaoChe")) {
|
|
|
+ arithmetic = "6";
|
|
|
+ } else if (id.equals("TaDiao")) {
|
|
|
+ arithmetic = "7";
|
|
|
+ } else if (id.equals("fire")) {
|
|
|
+ arithmetic = "8";
|
|
|
+ } else if (id.equals("ShiGongJiXie")) {
|
|
|
+ arithmetic = "9";
|
|
|
+ } else if (id.equals("DaoXianYiWu")) {
|
|
|
+ arithmetic = "10";
|
|
|
+ } else if (id.equals("smoke")) {
|
|
|
+ arithmetic = "11";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Ai_parse ai_parse = new Ai_parse();
|
|
|
+ ai_parse.setArithmetic(arithmetic);
|
|
|
+ ai_parse.setAi_info(ai_info);
|
|
|
+ // 同时返回算法类型和识别后的json数据
|
|
|
+
|
|
|
+ return ai_parse;
|
|
|
+ }
|
|
|
}
|