bug修复

This commit is contained in:
guo 2024-02-28 16:28:36 +08:00
parent 294db15d20
commit 212e3aba4a
2 changed files with 153 additions and 52 deletions

View File

@ -0,0 +1,22 @@
package com.zhgd.xmgl.base;
import lombok.Data;
@Data
public class HikvisionEventsPictureRq {
/**
* 图片存储服务器唯一标识提供picUri处会提供此字段
*/
private String svrIndexCode;
/**
* 图片的相对地址
*/
private String picUri;
/**
* 网络协议
* http:HTTP协议
* https:HTTPS协议
* 参数不填优先返回https协议
*/
private String netProtocol;
}

View File

@ -1,82 +1,56 @@
package com.zhgd.xmgl.call;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.xmgl.base.HikvisionCarInfo;
import com.zhgd.xmgl.base.HikvisionEventsPictureRq;
import com.zhgd.xmgl.modules.car.entity.CarInfo;
import com.zhgd.xmgl.modules.car.entity.CarPassRecord;
import com.zhgd.xmgl.modules.car.mapper.CarPassRecordMapper;
import com.zhgd.xmgl.modules.project.entity.Project;
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
import com.zhgd.xmgl.modules.worker.mapper.WorkerInfoMapper;
import com.zhgd.xmgl.modules.worker.service.IWorkerAttendanceService;
import com.zhgd.xmgl.util.Base64Util;
import com.zhgd.xmgl.util.HikvisionUtil;
import com.zhgd.xmgl.util.PathUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Objects;
@Slf4j
@Component
@RestController
@RequestMapping("/xmgl/hikvision")
public class HikvisionCall {
@Value("${upload.image.url.prefix:}")
private String imageUrlPrefix;
@Autowired
private ProjectMapper projectMapper;
public static String GetCameraPreviewURL() {
/**
* STEP1设置平台参数根据实际情况,设置host appkey appsecret 三个参数.
*/
ArtemisConfig.host = "127.0.0.1:443"; // 平台的ip端口
ArtemisConfig.appKey = "29180881"; // 密钥appkey
ArtemisConfig.appSecret = "XO0wCAYGi4KV70ybjznx";// 密钥appSecret
/**
* STEP2设置OpenAPI接口的上下文
*/
final String ARTEMIS_PATH = "/artemis";
/**
* STEP3设置接口的URI地址
*/
final String previewURLsApi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs";
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
}
};
/**
* STEP4设置参数提交方式
*/
String contentType = "application/json";
/**
* STEP5组装请求参数
*/
JSONObject jsonBody = new JSONObject();
jsonBody.put("cameraIndexCode", "748d84750e3a4a5bbad3cd4af9ed5101");
jsonBody.put("streamType", 0);
jsonBody.put("protocol", "rtsp");
jsonBody.put("transmode", 1);
jsonBody.put("expand", "streamform=ps");
String body = jsonBody.toJSONString();
/**
* STEP6调用接口
*/
String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
return result;
}
@Autowired
private IWorkerAttendanceService workerAttendanceService;
@Autowired
private WorkerInfoMapper workerInfoMapper;
@Autowired
private CarPassRecordMapper carPassRecordMapper;
public void addWorkerForHikvision(WorkerInfo workerInfo) {
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, workerInfo.getProjectSn()));
@ -239,4 +213,109 @@ public class HikvisionCall {
jo.put("vehicleIds", array);
HikvisionUtil.doPost(host, path, body, null, project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret());
}
@ApiOperation(value = "海康事件回调", notes = "海康事件回调", httpMethod = "POST")
@PostMapping(value = "/eventCallback")
public Result eventCallback(@ApiIgnore @RequestBody JSONObject jsonObject) {
String method = jsonObject.getString("method");
if (Objects.equals(method, "OnEventNotify")) {
JSONObject paramsJo = jsonObject.getJSONObject("params");
String ability = paramsJo.getString("ability");
//人员通行记录
if (Objects.equals(ability, "event_acs")) {
JSONArray eventsJa = paramsJo.getJSONArray("events");
if (eventsJa != null) {
for (int i = 0; i < eventsJa.size(); i++) {
JSONObject jo1 = eventsJa.getJSONObject(i);
JSONObject dataJo = jo1.getJSONObject("data");
JSONObject extEventIdentityCardInfoJo = dataJo.getJSONObject("ExtEventIdentityCardInfo");
String idNum = extEventIdentityCardInfoJo.getString("IdNum");
String extEventPictureURL = extEventIdentityCardInfoJo.getString("ExtEventPictureURL");
String svrIndexCode = extEventIdentityCardInfoJo.getString("svrIndexCode");
String extEventCardNo = dataJo.getString("ExtEventCardNo");
WorkerInfo workerInfo = workerInfoMapper.selectOne(new LambdaQueryWrapper<WorkerInfo>().eq(WorkerInfo::getIdCard, idNum)
.or().eq(WorkerInfo::getIdCard, extEventCardNo).last("limit 1"));
if (workerInfo == null) {
log.info("未找到该人员信息idCard:{},extEventCardNo:{}", idNum, extEventCardNo);
return null;
}
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, workerInfo.getProjectSn()));
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
log.info("未配置idCard:{},extEventCardNo:{}", idNum, extEventCardNo);
return null;
}
HikvisionEventsPictureRq rq = new HikvisionEventsPictureRq();
rq.setPicUri(extEventPictureURL);
rq.setSvrIndexCode(svrIndexCode);
HashMap<String, Object> map = new HashMap<>();
map.put("passTime", null);
map.put("idCard", idNum);
map.put("attendanceNumber", extEventCardNo);
map.put("direction", getDirection(dataJo));
map.put("passType", 2);
map.put("projectCode", workerInfo.getProjectSn());
map.put("devCode", null);
map.put("faceUrl", getHikvisionEventsPicture(rq, project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
workerAttendanceService.saveExternalPassRecord(map);
}
}
} else if (Objects.equals(ability, "event_mpc")) {
JSONArray eventsJa = paramsJo.getJSONArray("events");
if (eventsJa != null) {
for (int i = 0; i < eventsJa.size(); i++) {
JSONObject jo1 = eventsJa.getJSONObject(i);
JSONObject dataJo = jo1.getJSONObject("data");
CarPassRecord entity = new CarPassRecord();
entity.setCarNumber(dataJo.getString("plateNo"));
String imageIndexCode = dataJo.getString("imageIndexCode");
entity.setType(null);
entity.setPassTime(DateUtil.formatDateTime(DateUtil.parse(dataJo.getString("crossTime"))));
JSONObject picUrlJo = dataJo.getJSONObject("picUrl");
String vehiclePicUrl = picUrlJo.getString("vehiclePicUrl");
HikvisionEventsPictureRq rq = new HikvisionEventsPictureRq();
rq.setPicUri(vehiclePicUrl);
rq.setSvrIndexCode(imageIndexCode);
//entity.setImageUrl(getHikvisionEventsPicture(rq, project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));//todo
//entity.setPanoramaUrl();
//entity.setCarColor();
//entity.setLocation();
//entity.setProjectSn();
//entity.setCarLogo();
//entity.setColor();
//entity.setCameraId();
JSONObject personJo = dataJo.getJSONObject("person");
entity.setDriverData(personJo.getString("personName"));
entity.setIsOpen(1);
carPassRecordMapper.insert(entity);
}
}
}
}
return Result.ok();
}
private Integer getDirection(JSONObject dataJo) {
Integer extEventInOut = dataJo.getInteger("ExtEventInOut");
if (Objects.equals(extEventInOut, 0)) {
return 2;
} else if (Objects.equals(extEventInOut, 1)) {
return 1;
} else {
return null;
}
}
public static String getHikvisionEventsPicture(HikvisionEventsPictureRq rq, String artemisConfigHost, String artemisConfigAppKey, String artemisConfigAppSecret) {//获取视频事件的图片
final String ARTEMIS_PATH = "/artemis";
final String path = ARTEMIS_PATH + "/api/video/v1/events/picture";
String host = "https://" + artemisConfigHost;
String body = JSONObject.toJSONString(rq);
String rs = HikvisionUtil.doPost(host, path, body, null, artemisConfigAppKey, artemisConfigAppSecret);
JSONObject rsJo = JSONObject.parseObject(rs);
Integer code = rsJo.getInteger("code");
if (code == 0) {
return rsJo.getJSONObject("data").getString("picUrl");
}
return null;
}
}