feat(sis): 实现人脸识别后远程开门功能(测试)
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
zcxlsm 2025-07-26 22:32:26 +08:00
parent 47f389c560
commit f4dbcba15f
4 changed files with 64 additions and 18 deletions

View File

@ -2,6 +2,7 @@ package org.dromara.sis.sdk.hik.calback;
import cn.hutool.core.codec.Base64Encoder;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.sun.jna.Pointer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -36,6 +37,7 @@ public class HikAlarmCallBack implements HCNetSDK.FMSGCallBack_V31 {
private final HuaWeiBoxApi huaWeiBoxApi;
private final ISisAuthRecordService authRecordService;
private final ISisAuthGroupRefService authGroupRefService;
private final ISisElevatorInfoService elevatorInfoService;
private final ISisDeviceBindRefService deviceBindRefService;
private final ISisAccessControlService accessControlService;
@ -321,6 +323,44 @@ public class HikAlarmCallBack implements HCNetSDK.FMSGCallBack_V31 {
}
log.info("人脸比对完成,personId={}", person);
// TODO 测试逻辑只针对门禁
// 授权纪录
SisAuthRecordVo authRecord = authRecordService.checkAuth(person);
if (authRecord == null) {
log.info("当前人脸未授权,暂不处理。");
return true;
}
Date now = new Date();
if(DateUtil.compare(now, authRecord.getEndDate()) > 0){
log.info("当前人脸已过期,暂不处理。");
return true;
}
// 授权设备列表
List<SisAuthGroupRefVo> authGroupRefVos = authGroupRefService.queryListByGroupId(authRecord.getGroupId());
// 获取门禁id
Collection<Long> acIds = authGroupRefVos.stream().filter(vo -> vo.getDeviceType() == 1).map(SisAuthGroupRefVo::getDeviceId).toList();
if (CollUtil.isNotEmpty(acIds)) {
acIds.forEach(id -> {
// controlType 1-门禁
Long deviceId = bindRefList.stream().filter(vo -> vo.getBindId().equals(id) && vo.getControlType() == 1).findFirst().map(SisDeviceBindRefVo::getBindId).orElse(null);
SisAccessControlVo ac = accessControlService.queryById(deviceId);
if (ac != null) {
log.info("调用门禁服务远程开门doorName:{}", ac.getAccessName());
RemoteOpenDoorReq req = new RemoteOpenDoorReq();
req.setType(0);
RemoteOpenDoorReq.ControlData data = new RemoteOpenDoorReq.ControlData();
data.setDeviceId(Long.parseLong(ac.getOutCode()));
data.setDoorId(Long.parseLong(ac.getOutCode()));
req.setControlList(List.of(data));
Boolean flag = e8PlatformApi.remoteOpenDoor(req);
log.info("远程开门结果,result={}", flag);
}
});
}
// 授权记录
// List<SisAuthRecordVo> authVoList = authRecordService.checkAuth(person);
// 获取门禁id

View File

@ -86,7 +86,7 @@ public interface ISisAuthRecordService {
/**
* 查询所有可授权设备树
*
* @return List<TreeNode<Long>>
* @return List<TreeNode < Long>>
*/
List<TreeNode<Long>> authDeviceTree();
@ -95,12 +95,12 @@ public interface ISisAuthRecordService {
*
* @param personId 人脸比对ID
*/
// List<SisAuthRecordVo> checkAuth(Long personId);
SisAuthRecordVo checkAuth(Long personId);
/**
* 根据权限组ID人员id返回授权记录
*
* @param groupId 权限组ID
* @param groupId 权限组ID
* @param personId 人员id
* @return SisAuthRecordVo
*/

View File

@ -123,7 +123,7 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
return flag;
}
private void syncPersonImg(RemotePersonAuth bo){
private void syncPersonImg(RemotePersonAuth bo) {
log.info("开始写入安防人像信息");
SisPersonLibImgBo personLibImg = new SisPersonLibImgBo();
personLibImg.setImgOssId(Long.parseLong(bo.getOssId()));
@ -250,17 +250,27 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
return List.of(root);
}
/**
* 根据人脸比对ID返回授权记录
*
* @param personId 人脸比对ID
*/
@Override
public SisAuthRecordVo checkAuth(Long personId) {
return baseMapper.checkAuth(personId).get(0);
}
/**
* 根据权限组ID人员id返回授权记录
*
* @param groupId 权限组ID
* @param groupId 权限组ID
* @param personId 人员id
* @return SisAuthRecordVo
*/
public SisAuthRecordVo queryByGroupIdAndPersonId(Long groupId, Long personId){
public SisAuthRecordVo queryByGroupIdAndPersonId(Long groupId, Long personId) {
LambdaQueryWrapper<SisAuthRecord> lqw = Wrappers.lambdaQuery();
lqw.eq(SisAuthRecord::getGroupId, groupId)
.eq(SisAuthRecord::getTargetId, personId);
.eq(SisAuthRecord::getTargetId, personId);
return baseMapper.selectVoOne(lqw);
}
}

View File

@ -5,16 +5,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace="org.dromara.sis.mapper.SisAuthRecordMapper">
<select id="checkAuth" resultType="org.dromara.sis.domain.vo.SisAuthRecordVo">
SELECT
device_type,
device_id
FROM sis_auth_record sar
WHERE EXISTS (
SELECT 1
FROM sis_person_lib_img a
INNER JOIN sis_lib_img_ref b ON a.id = b.img_id
WHERE a.remote_img_id = #{personId}
AND b.lib_id = sar.lib_id -- 关联主表
)
SELECT c.target_id, c.group_id, c.beg_date, c.end_date
FROM sis_person_lib_img a
LEFT JOIN resident_person b ON a.resident_person_id = b.id
LEFT JOIN sis_auth_record c
ON c.target_id = b.id
AND c.group_id = b.auth_group_id
WHERE a.remote_img_id = #{personId};
</select>
</mapper>