海康事件回调

This commit is contained in:
guo 2024-03-07 16:35:20 +08:00
parent 914b1d7594
commit 3234a54483
7 changed files with 212 additions and 48 deletions

View File

@ -1,8 +1,14 @@
package com.zhgd.xmgl.base; package com.zhgd.xmgl.base;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
@Data @Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class HikvisionEventsPictureRq { public class HikvisionEventsPictureRq {
/** /**
* 图片存储服务器唯一标识提供picUri处会提供此字段 * 图片存储服务器唯一标识提供picUri处会提供此字段
@ -19,4 +25,9 @@ public class HikvisionEventsPictureRq {
* 参数不填优先返回https协议 * 参数不填优先返回https协议
*/ */
private String netProtocol; private String netProtocol;
public HikvisionEventsPictureRq(String svrIndex, String vehiclePicUrl) {
this.svrIndexCode = svrIndex;
this.picUri = vehiclePicUrl;
}
} }

View File

@ -11,8 +11,10 @@ import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.xmgl.base.*; import com.zhgd.xmgl.base.*;
import com.zhgd.xmgl.modules.basicdata.entity.HikvisionRequestRetry; import com.zhgd.xmgl.modules.basicdata.entity.HikvisionRequestRetry;
import com.zhgd.xmgl.modules.basicdata.mapper.HikvisionRequestRetryMapper; import com.zhgd.xmgl.modules.basicdata.mapper.HikvisionRequestRetryMapper;
import com.zhgd.xmgl.modules.car.entity.CarCamera;
import com.zhgd.xmgl.modules.car.entity.CarInfo; import com.zhgd.xmgl.modules.car.entity.CarInfo;
import com.zhgd.xmgl.modules.car.entity.CarPassRecord; import com.zhgd.xmgl.modules.car.entity.CarPassRecord;
import com.zhgd.xmgl.modules.car.mapper.CarCameraMapper;
import com.zhgd.xmgl.modules.car.mapper.CarInfoMapper; import com.zhgd.xmgl.modules.car.mapper.CarInfoMapper;
import com.zhgd.xmgl.modules.car.mapper.CarPassRecordMapper; import com.zhgd.xmgl.modules.car.mapper.CarPassRecordMapper;
import com.zhgd.xmgl.modules.car.mapper.CarTypeMapper; import com.zhgd.xmgl.modules.car.mapper.CarTypeMapper;
@ -58,6 +60,9 @@ public class HikvisionCall {
private WorkerInfoMapper workerInfoMapper; private WorkerInfoMapper workerInfoMapper;
@Autowired @Autowired
@Lazy @Lazy
private CarCameraMapper carCameraMapper;
@Autowired
@Lazy
private CarPassRecordMapper carPassRecordMapper; private CarPassRecordMapper carPassRecordMapper;
@Autowired @Autowired
@Lazy @Lazy
@ -85,76 +90,116 @@ public class HikvisionCall {
@ApiOperation(value = "海康事件回调", notes = "海康事件回调", httpMethod = "POST") @ApiOperation(value = "海康事件回调", notes = "海康事件回调", httpMethod = "POST")
@PostMapping(value = "/eventCallback") @PostMapping(value = "/eventCallback")
public Result eventCallback(@ApiIgnore @RequestBody JSONObject jsonObject) { public Result eventCallback(@ApiIgnore @RequestBody JSONObject jsonObject) {
log.info("海康事件回调:{}", JSON.toJSONString(jsonObject));
String method = jsonObject.getString("method"); String method = jsonObject.getString("method");
if (Objects.equals(method, "OnEventNotify")) { if (Objects.equals(method, "OnEventNotify")) {
JSONObject paramsJo = jsonObject.getJSONObject("params"); JSONObject paramsJo = jsonObject.getJSONObject("params");
String ability = paramsJo.getString("ability"); String ability = paramsJo.getString("ability");
//人员通行记录
if (Objects.equals(ability, "event_acs")) { if (Objects.equals(ability, "event_acs")) {
//人员通行记录
JSONArray eventsJa = paramsJo.getJSONArray("events"); JSONArray eventsJa = paramsJo.getJSONArray("events");
if (eventsJa != null) { if (eventsJa != null) {
for (int i = 0; i < eventsJa.size(); i++) { for (int i = 0; i < eventsJa.size(); i++) {
JSONObject jo1 = eventsJa.getJSONObject(i); JSONObject jo1 = eventsJa.getJSONObject(i);
JSONObject dataJo = jo1.getJSONObject("data"); JSONObject dataJo = jo1.getJSONObject("data");
String happenTime = jo1.getString("happenTime");
String srcIndex = jo1.getString("srcIndex");
JSONObject extEventIdentityCardInfoJo = dataJo.getJSONObject("ExtEventIdentityCardInfo"); JSONObject extEventIdentityCardInfoJo = dataJo.getJSONObject("ExtEventIdentityCardInfo");
String idNum = extEventIdentityCardInfoJo.getString("IdNum"); if (extEventIdentityCardInfoJo == null) {
String extEventPictureURL = extEventIdentityCardInfoJo.getString("ExtEventPictureURL"); log.info("extEventIdentityCardInfoJo为null");
String svrIndexCode = extEventIdentityCardInfoJo.getString("svrIndexCode"); return null;
}
String extEventPersonNo = dataJo.getString("ExtEventPersonNo");
String extEventCardNo = dataJo.getString("ExtEventCardNo"); String extEventCardNo = dataJo.getString("ExtEventCardNo");
WorkerInfo workerInfo = workerInfoMapper.selectOne(new LambdaQueryWrapper<WorkerInfo>().eq(WorkerInfo::getIdCard, idNum) WorkerInfo workerInfo = workerInfoMapper.selectById(extEventPersonNo);
.or().eq(WorkerInfo::getIdCard, extEventCardNo).last("limit 1"));
if (workerInfo == null) { if (workerInfo == null) {
log.info("未找到该人员信息idCard:{},extEventCardNo:{}", idNum, extEventCardNo); log.info("未找到该人员信息,extEventPersonNo:{}", extEventPersonNo);
return null; return null;
} }
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, workerInfo.getProjectSn())); Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, workerInfo.getProjectSn()));
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) { if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
log.info("未配置idCard:{},extEventCardNo:{}", idNum, extEventCardNo); log.info("未配置idCard:{},extEventCardNo:{}", workerInfo.getIdCard(), extEventCardNo);
return null; return null;
} }
HikvisionEventsPictureRq rq = new HikvisionEventsPictureRq();
rq.setPicUri(extEventPictureURL);
rq.setSvrIndexCode(svrIndexCode);
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
map.put("passTime", null); map.put("passTime", DateUtil.formatDateTime(DateUtil.parse(happenTime)));
map.put("idCard", idNum); map.put("idCard", workerInfo.getIdCard());
map.put("attendanceNumber", extEventCardNo); map.put("attendanceNumber", workerInfo.getAttendanceNumber());
map.put("direction", getDirection(dataJo)); map.put("direction", getDirection(dataJo));
map.put("passType", 2); map.put("passType", 2);
map.put("projectCode", workerInfo.getProjectSn()); map.put("projectCode", workerInfo.getProjectSn());
map.put("devCode", null); map.put("devCode", srcIndex);
map.put("faceUrl", getHikvisionEventsPicture(rq, project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret())); try {
String extEventPictureURL = extEventIdentityCardInfoJo.getString("ExtEventPictureURL");
String svrIndexCode = extEventIdentityCardInfoJo.getString("svrIndexCode");
HikvisionEventsPictureRq rq = new HikvisionEventsPictureRq();
rq.setPicUri(extEventPictureURL);
rq.setSvrIndexCode(svrIndexCode);
map.put("faceUrl", getHikvisionEventsPicture(rq, project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
} catch (Exception e) {
e.printStackTrace();
}
workerAttendanceService.saveExternalPassRecord(map); workerAttendanceService.saveExternalPassRecord(map);
} }
} }
} else if (Objects.equals(ability, "event_mpc")) { } else if (Objects.equals(ability, "event_pms")) {
//车辆入场压线放行出场压线放行
JSONArray eventsJa = paramsJo.getJSONArray("events"); JSONArray eventsJa = paramsJo.getJSONArray("events");
if (eventsJa != null) { if (eventsJa != null) {
for (int i = 0; i < eventsJa.size(); i++) { for (int i = 0; i < eventsJa.size(); i++) {
JSONObject jo1 = eventsJa.getJSONObject(i); JSONObject jo1 = eventsJa.getJSONObject(i);
JSONObject dataJo = jo1.getJSONObject("data"); JSONObject dataJo = jo1.getJSONObject("data");
CarPassRecord entity = new CarPassRecord(); String srcIndex = jo1.getString("srcIndex");
entity.setCarNumber(dataJo.getString("plateNo")); Long eventType = jo1.getLong("eventType");
String imageIndexCode = dataJo.getString("imageIndexCode"); CarCamera carCamera = carCameraMapper.selectOne(new LambdaQueryWrapper<CarCamera>()
entity.setType(null); .eq(CarCamera::getCameraId, srcIndex));
entity.setPassTime(DateUtil.formatDateTime(DateUtil.parse(dataJo.getString("crossTime")))); if (carCamera == null) {
JSONObject picUrlJo = dataJo.getJSONObject("picUrl"); log.info("海康回调车辆相机设备不存在CameraId:{}", srcIndex);
String vehiclePicUrl = picUrlJo.getString("vehiclePicUrl"); return null;
HikvisionEventsPictureRq rq = new HikvisionEventsPictureRq(); }
rq.setPicUri(vehiclePicUrl); Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, carCamera.getProjectSn()));
rq.setSvrIndexCode(imageIndexCode); if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
//entity.setImageUrl(getHikvisionEventsPicture(rq, project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));//todo log.info("海康事件车辆入场压线的project不存在,cameraId:{}", carCamera.getCameraId());
//entity.setPanoramaUrl(); return null;
//entity.setCarColor(); }
//entity.setLocation();
//entity.setProjectSn(); String plateNo = dataJo.getString("plateNo");
//entity.setCarLogo(); String time = DateUtil.formatDateTime(DateUtil.parse(dataJo.getString("time")));
//entity.setColor(); if (eventType == 771760134 || eventType == 771760131) {
//entity.setCameraId(); //出入场放行
JSONObject personJo = dataJo.getJSONObject("person"); CarPassRecord carPassRecord = carPassRecordMapper.getNewestlineBreakingEvent(plateNo, time);
entity.setDriverData(personJo.getString("personName")); carPassRecord.setIsOpen(1);
entity.setIsOpen(1); carPassRecordMapper.updateById(carPassRecord);
carPassRecordMapper.insert(entity); } else if (eventType == 771760130 || eventType == 771760133) {
//压线事件
CarPassRecord entity = new CarPassRecord();
entity.setCarNumber(plateNo);
entity.setType(getPassType(carCamera.getPassType()));
entity.setPassTime(time);
try {
//车牌
JSONObject picUrlJo = dataJo.getJSONObject("picUrl");
String svrIndex = dataJo.getString("svrIndex");
String vehiclePicUrl = picUrlJo.getString("vehiclePicUrl");
String platePicUrl = picUrlJo.getString("platePicUrl");
entity.setImageUrl(getHikvisionEventsPicture(new HikvisionEventsPictureRq(svrIndex, platePicUrl), project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
entity.setPanoramaUrl(getHikvisionEventsPicture(new HikvisionEventsPictureRq(svrIndex, vehiclePicUrl), project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret()));
} catch (Exception e) {
e.printStackTrace();
}
entity.setCarColor(getCarColor(dataJo.getInteger("plateColor")));
entity.setLocation(carCamera.getCameraName());
entity.setProjectSn(carCamera.getProjectSn());
entity.setColor(getColor(dataJo.getInteger("vehicleColor")));
entity.setCameraId(srcIndex);
JSONObject personJo = dataJo.getJSONObject("person");
entity.setDriverData(personJo.getString("personName"));
entity.setIsOpen(0);
carPassRecordMapper.insert(entity);
}
} }
} }
} }
@ -162,14 +207,103 @@ public class HikvisionCall {
return Result.ok(); return Result.ok();
} }
/**
* 获取车辆颜色
*
* @param plateColor
* @return
*/
private String getColor(Integer plateColor) {
if (plateColor == null) {
return null;
}
switch (plateColor) {
case 0:
return "其他颜色";
case 1:
return "白色";
case 2:
return "银色";
case 3:
return "灰色";
case 4:
return "黑色";
case 5:
return "红色";
case 6:
return "深蓝色";
case 7:
return "蓝色";
case 8:
return "黄色";
case 9:
return "绿色";
case 10:
return "棕色";
case 11:
return "粉色";
case 12:
return "紫色";
case 13:
return "深灰";
case 14:
return "杏色";
case 255:
return "未识别的车辆颜色";
}
return null;
}
/**
* 车牌颜色
*
* @param plateColor
* @return
*/
private String getCarColor(Integer plateColor) {
if (plateColor == null) {
return null;
}
switch (plateColor) {
case 0:
return "蓝色";
case 1:
return "黄色";
case 2:
return "白色";
case 3:
return "黑色";
case 4:
return "绿色";
case 5:
return "民航黑色";
case 255:
return "其他颜色";
}
return null;
}
private Integer getPassType(Integer passType) {
if (passType == null) {
return null;
}
//1进2出
switch (passType) {
case 1:
return 0;
case 2:
return 1;
}
return null;
}
@ApiOperation(value = "按事件类型订阅事件", notes = "按事件类型订阅事件", httpMethod = "POST") @ApiOperation(value = "按事件类型订阅事件", notes = "按事件类型订阅事件", httpMethod = "POST")
@PostMapping(value = "/subscribeEvent") @PostMapping(value = "/subscribeEvent")
public Result subscribeEvent(@ApiIgnore @RequestBody SubscribeEventQo qo) { public Result subscribeEvent(@ApiIgnore @RequestBody SubscribeEventQo qo) {
final String ARTEMIS_PATH = "/artemis"; final String ARTEMIS_PATH = "/artemis";
final String path = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionByEventTypes"; final String path = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionByEventTypes";
String host = "https://" + qo.getArtemisConfigHost(); String host = "https://" + qo.getArtemisConfigHost();
JSONObject jo = new JSONObject(); String rs = HikvisionUtil.doPost(host, path, JSON.toJSONString(qo), null, qo.getArtemisConfigAppKey(), qo.getArtemisConfigAppSecret());
String rs = HikvisionUtil.doPost(host, path, jo.toJSONString(), null, qo.getArtemisConfigAppKey(), qo.getArtemisConfigAppSecret());
return Result.ok(); return Result.ok();
} }
@ -683,8 +817,8 @@ public class HikvisionCall {
String body = JSONObject.toJSONString(rq); String body = JSONObject.toJSONString(rq);
String rs = HikvisionUtil.doPost(host, path, body, null, artemisConfigAppKey, artemisConfigAppSecret); String rs = HikvisionUtil.doPost(host, path, body, null, artemisConfigAppKey, artemisConfigAppSecret);
JSONObject rsJo = JSONObject.parseObject(rs); JSONObject rsJo = JSONObject.parseObject(rs);
Integer code = rsJo.getInteger("code"); String code = rsJo.getString("code");
if (code == 0) { if (Objects.equals(code, "0")) {
return rsJo.getJSONObject("data").getString("picUrl"); return rsJo.getJSONObject("data").getString("picUrl");
} }
return null; return null;

View File

@ -54,10 +54,10 @@ public class CarPassRecord implements Serializable {
@ApiModelProperty(value = "进出场图片(车牌图片)") @ApiModelProperty(value = "进出场图片(车牌图片)")
private java.lang.String imageUrl; private java.lang.String imageUrl;
/** /**
* 颜色 * 颜色
*/ */
@Excel(name = "颜色", width = 15) @Excel(name = "颜色", width = 15)
@ApiModelProperty(value = "颜色") @ApiModelProperty(value = "颜色")
private java.lang.String carColor; private java.lang.String carColor;
/** /**
* 进出位置 * 进出位置

View File

@ -5,7 +5,6 @@ import java.util.Map;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.jeecg.common.mybatis.EntityMap; import com.zhgd.jeecg.common.mybatis.EntityMap;
import com.zhgd.xmgl.modules.car.entity.vo.EntryAndExitRecordsTodayVo;
import com.zhgd.xmgl.modules.car.entity.vo.TodayOutInNumber; import com.zhgd.xmgl.modules.car.entity.vo.TodayOutInNumber;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -43,4 +42,13 @@ public interface CarPassRecordMapper extends BaseMapper<CarPassRecord> {
EntityMap getTodayOutInNumber(String projectSn); EntityMap getTodayOutInNumber(String projectSn);
CarPassRecord queryNewestCarPassRecord(Map<String, Object> map); CarPassRecord queryNewestCarPassRecord(Map<String, Object> map);
/**
* 查询海康压线事件后新增的记录因为压线时间没有是否通行的结果
*
* @param plateNo
* @param time
* @return
*/
CarPassRecord getNewestlineBreakingEvent(@Param("plateNo") String plateNo, @Param("time") String time);
} }

View File

@ -222,4 +222,13 @@
</if> </if>
order by a.pass_time desc limit 1 order by a.pass_time desc limit 1
</select> </select>
<select id="getNewestlineBreakingEvent" resultType="com.zhgd.xmgl.modules.car.entity.CarPassRecord">
select *
from car_pass_record
where car_number=#{plateNo}
and pass_time >= date_sub(#{time},interval 5 minute)
order by pass_time desc
limit 1
</select>
</mapper> </mapper>

View File

@ -117,6 +117,8 @@ public class RtRiskInventoryType implements Serializable {
private java.lang.String predecessorIds; private java.lang.String predecessorIds;
@ApiModelProperty(value = "备注") @ApiModelProperty(value = "备注")
private java.lang.String remark; private java.lang.String remark;
@ApiModelProperty(value = "1未注销 2已注销")
private Integer accountState;
@TableField(exist = false) @TableField(exist = false)

View File

@ -142,7 +142,7 @@ public class WorkerInfoController {
@ApiImplicitParam(name = "projectSnList", value = "项目SN列表", paramType = "body", required = false, dataType = "String"), @ApiImplicitParam(name = "projectSnList", value = "项目SN列表", paramType = "body", required = false, dataType = "String"),
@ApiImplicitParam(name = "orderBy", value = "排序1退场时间倒序2进场日期倒序", paramType = "body", required = false, dataType = "Integer"), @ApiImplicitParam(name = "orderBy", value = "排序1退场时间倒序2进场日期倒序", paramType = "body", required = false, dataType = "Integer"),
@ApiImplicitParam(name = "workerInfos", value = "劳务人员id多个分割", paramType = "body", required = false, dataType = "String"), @ApiImplicitParam(name = "workerInfos", value = "劳务人员id多个分割", paramType = "body", required = false, dataType = "String"),
@ApiImplicitParam(name = "presence", value = "1在场", paramType = "body", required = false, dataType = "Integer"), @ApiImplicitParam(name = "presence", value = "1在场2离场", paramType = "body", required = false, dataType = "Integer"),
@ApiImplicitParam(name = "attendance", value = "1今日出勤", paramType = "body", required = false, dataType = "Integer"), @ApiImplicitParam(name = "attendance", value = "1今日出勤", paramType = "body", required = false, dataType = "Integer"),
}) })
@PostMapping(value = "/selectWorkerInfoList") @PostMapping(value = "/selectWorkerInfoList")