海康事件回调
This commit is contained in:
parent
914b1d7594
commit
3234a54483
@ -1,8 +1,14 @@
|
||||
package com.zhgd.xmgl.base;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class HikvisionEventsPictureRq {
|
||||
/**
|
||||
* 图片存储服务器唯一标识,提供picUri处会提供此字段
|
||||
@ -19,4 +25,9 @@ public class HikvisionEventsPictureRq {
|
||||
* 参数不填,优先返回https协议
|
||||
*/
|
||||
private String netProtocol;
|
||||
|
||||
public HikvisionEventsPictureRq(String svrIndex, String vehiclePicUrl) {
|
||||
this.svrIndexCode = svrIndex;
|
||||
this.picUri = vehiclePicUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,8 +11,10 @@ import com.zhgd.jeecg.common.api.vo.Result;
|
||||
import com.zhgd.xmgl.base.*;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.HikvisionRequestRetry;
|
||||
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.CarPassRecord;
|
||||
import com.zhgd.xmgl.modules.car.mapper.CarCameraMapper;
|
||||
import com.zhgd.xmgl.modules.car.mapper.CarInfoMapper;
|
||||
import com.zhgd.xmgl.modules.car.mapper.CarPassRecordMapper;
|
||||
import com.zhgd.xmgl.modules.car.mapper.CarTypeMapper;
|
||||
@ -58,6 +60,9 @@ public class HikvisionCall {
|
||||
private WorkerInfoMapper workerInfoMapper;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private CarCameraMapper carCameraMapper;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private CarPassRecordMapper carPassRecordMapper;
|
||||
@Autowired
|
||||
@Lazy
|
||||
@ -85,91 +90,220 @@ public class HikvisionCall {
|
||||
@ApiOperation(value = "海康事件回调", notes = "海康事件回调", httpMethod = "POST")
|
||||
@PostMapping(value = "/eventCallback")
|
||||
public Result eventCallback(@ApiIgnore @RequestBody JSONObject jsonObject) {
|
||||
log.info("海康事件回调:{}", JSON.toJSONString(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");
|
||||
String happenTime = jo1.getString("happenTime");
|
||||
String srcIndex = jo1.getString("srcIndex");
|
||||
JSONObject extEventIdentityCardInfoJo = dataJo.getJSONObject("ExtEventIdentityCardInfo");
|
||||
String idNum = extEventIdentityCardInfoJo.getString("IdNum");
|
||||
String extEventPictureURL = extEventIdentityCardInfoJo.getString("ExtEventPictureURL");
|
||||
String svrIndexCode = extEventIdentityCardInfoJo.getString("svrIndexCode");
|
||||
if (extEventIdentityCardInfoJo == null) {
|
||||
log.info("extEventIdentityCardInfoJo为null");
|
||||
return null;
|
||||
}
|
||||
String extEventPersonNo = dataJo.getString("ExtEventPersonNo");
|
||||
String extEventCardNo = dataJo.getString("ExtEventCardNo");
|
||||
WorkerInfo workerInfo = workerInfoMapper.selectOne(new LambdaQueryWrapper<WorkerInfo>().eq(WorkerInfo::getIdCard, idNum)
|
||||
.or().eq(WorkerInfo::getIdCard, extEventCardNo).last("limit 1"));
|
||||
WorkerInfo workerInfo = workerInfoMapper.selectById(extEventPersonNo);
|
||||
if (workerInfo == null) {
|
||||
log.info("未找到该人员信息,idCard:{},extEventCardNo:{}", idNum, extEventCardNo);
|
||||
log.info("未找到该人员信息,extEventPersonNo:{}", extEventPersonNo);
|
||||
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);
|
||||
log.info("未配置,idCard:{},extEventCardNo:{}", workerInfo.getIdCard(), 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("passTime", DateUtil.formatDateTime(DateUtil.parse(happenTime)));
|
||||
map.put("idCard", workerInfo.getIdCard());
|
||||
map.put("attendanceNumber", workerInfo.getAttendanceNumber());
|
||||
map.put("direction", getDirection(dataJo));
|
||||
map.put("passType", 2);
|
||||
map.put("projectCode", workerInfo.getProjectSn());
|
||||
map.put("devCode", null);
|
||||
map.put("devCode", srcIndex);
|
||||
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);
|
||||
}
|
||||
}
|
||||
} else if (Objects.equals(ability, "event_mpc")) {
|
||||
} else if (Objects.equals(ability, "event_pms")) {
|
||||
//车辆入场压线(放行)、出场压线(放行)
|
||||
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");
|
||||
String srcIndex = jo1.getString("srcIndex");
|
||||
Long eventType = jo1.getLong("eventType");
|
||||
CarCamera carCamera = carCameraMapper.selectOne(new LambdaQueryWrapper<CarCamera>()
|
||||
.eq(CarCamera::getCameraId, srcIndex));
|
||||
if (carCamera == null) {
|
||||
log.info("海康回调车辆相机设备不存在:CameraId:{}", srcIndex);
|
||||
return null;
|
||||
}
|
||||
Project project = projectMapper.selectOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, carCamera.getProjectSn()));
|
||||
if (project == null || !Objects.equals(project.getSyncHikvision(), 1)) {
|
||||
log.info("海康事件车辆入场压线的project不存在,cameraId:{}", carCamera.getCameraId());
|
||||
return null;
|
||||
}
|
||||
|
||||
String plateNo = dataJo.getString("plateNo");
|
||||
String time = DateUtil.formatDateTime(DateUtil.parse(dataJo.getString("time")));
|
||||
if (eventType == 771760134 || eventType == 771760131) {
|
||||
//出入场放行
|
||||
CarPassRecord carPassRecord = carPassRecordMapper.getNewestlineBreakingEvent(plateNo, time);
|
||||
carPassRecord.setIsOpen(1);
|
||||
carPassRecordMapper.updateById(carPassRecord);
|
||||
} else if (eventType == 771760130 || eventType == 771760133) {
|
||||
//压线事件
|
||||
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"))));
|
||||
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");
|
||||
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();
|
||||
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(1);
|
||||
entity.setIsOpen(0);
|
||||
carPassRecordMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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")
|
||||
@PostMapping(value = "/subscribeEvent")
|
||||
public Result subscribeEvent(@ApiIgnore @RequestBody SubscribeEventQo qo) {
|
||||
final String ARTEMIS_PATH = "/artemis";
|
||||
final String path = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionByEventTypes";
|
||||
String host = "https://" + qo.getArtemisConfigHost();
|
||||
JSONObject jo = new JSONObject();
|
||||
String rs = HikvisionUtil.doPost(host, path, jo.toJSONString(), null, qo.getArtemisConfigAppKey(), qo.getArtemisConfigAppSecret());
|
||||
String rs = HikvisionUtil.doPost(host, path, JSON.toJSONString(qo), null, qo.getArtemisConfigAppKey(), qo.getArtemisConfigAppSecret());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ -683,8 +817,8 @@ public class HikvisionCall {
|
||||
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) {
|
||||
String code = rsJo.getString("code");
|
||||
if (Objects.equals(code, "0")) {
|
||||
return rsJo.getJSONObject("data").getString("picUrl");
|
||||
}
|
||||
return null;
|
||||
|
||||
@ -54,10 +54,10 @@ public class CarPassRecord implements Serializable {
|
||||
@ApiModelProperty(value = "进出场图片(车牌图片)")
|
||||
private java.lang.String imageUrl;
|
||||
/**
|
||||
* 车辆颜色
|
||||
* 车牌颜色
|
||||
*/
|
||||
@Excel(name = "车辆颜色", width = 15)
|
||||
@ApiModelProperty(value = "车辆颜色")
|
||||
@Excel(name = "车牌颜色", width = 15)
|
||||
@ApiModelProperty(value = "车牌颜色")
|
||||
private java.lang.String carColor;
|
||||
/**
|
||||
* 进出位置
|
||||
|
||||
@ -5,7 +5,6 @@ import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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 org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@ -43,4 +42,13 @@ public interface CarPassRecordMapper extends BaseMapper<CarPassRecord> {
|
||||
EntityMap getTodayOutInNumber(String projectSn);
|
||||
|
||||
CarPassRecord queryNewestCarPassRecord(Map<String, Object> map);
|
||||
|
||||
/**
|
||||
* 查询海康压线事件后新增的记录,因为压线时间没有是否通行的结果
|
||||
*
|
||||
* @param plateNo
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
CarPassRecord getNewestlineBreakingEvent(@Param("plateNo") String plateNo, @Param("time") String time);
|
||||
}
|
||||
|
||||
@ -222,4 +222,13 @@
|
||||
</if>
|
||||
order by a.pass_time desc limit 1
|
||||
</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>
|
||||
|
||||
@ -117,6 +117,8 @@ public class RtRiskInventoryType implements Serializable {
|
||||
private java.lang.String predecessorIds;
|
||||
@ApiModelProperty(value = "备注")
|
||||
private java.lang.String remark;
|
||||
@ApiModelProperty(value = "1:未注销 2:已注销")
|
||||
private Integer accountState;
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
|
||||
@ -142,7 +142,7 @@ public class WorkerInfoController {
|
||||
@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 = "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"),
|
||||
})
|
||||
@PostMapping(value = "/selectWorkerInfoList")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user