feat(sis): 支持黑名单人员管理

- 新增人员标签类型字段,用于区分红名单、白名单和黑名单
- 修改授权逻辑,黑名单人员不进行授权记录和E8平台同步
- 优化定时任务,对不同名单类型的人员进行差异化处理
- 增加黑名单人员入内的告警功能
This commit is contained in:
2025-08-07 22:34:06 +08:00
parent 1c23320f5a
commit e3867b7a12
19 changed files with 207 additions and 78 deletions

View File

@@ -34,4 +34,6 @@ public class RemoteResidentPersonVo implements Serializable {
private Date authBegDate;
private Date authEndDate;
private Integer rosterType;
}

View File

@@ -38,12 +38,12 @@ public interface RemoteSisAuthService {
Boolean queryPersonAuth(Long authGroupId, Long personId);
/**
* 通过MD5查询图片id
* 通过MD5查询华为盒子id
*
* @param imgMd5 图片MD5
* @return Long
*/
Long queryImgIdByImgMd5(String imgMd5);
Long queryHuaweiBoxIdByImgMd5(String imgMd5);
/**
* 图片写入华为盒子

View File

@@ -43,4 +43,6 @@ public class RemotePersonAuth implements Serializable {
private Date authEndDate;
private Integer rosterType;
}

View File

@@ -108,6 +108,12 @@ public class ResidentPerson extends TenantEntity {
* e8平台id
*/
private Long eEightId;
/**
* 人员标签类型
*/
private Integer rosterType;
/**
* 创建人id
*/

View File

@@ -121,5 +121,10 @@ public class ResidentPersonBo extends BaseEntity {
*/
private String remark;
/**
* 人员标签类型
*/
private Integer rosterType = 2;
}

View File

@@ -138,5 +138,10 @@ public class ResidentPersonVo implements Serializable {
*/
private String idCard;
/**
* 人员标签类型
*/
private Integer rosterType;
}

View File

@@ -35,6 +35,7 @@ public class RemoteResidentPersonServiceImpl implements RemoteResidentPersonServ
remoteResidentPersonVo.setName(vo.getUserName());
remoteResidentPersonVo.setIdCard(vo.getIdCard());
remoteResidentPersonVo.setGender(vo.getGender());
remoteResidentPersonVo.setRosterType(vo.getRosterType());
remoteResidentPersonVo.setAuthGroupId(vo.getAuthGroupId());
remoteResidentPersonVo.setAuthBegDate(vo.getAuthBegDate());
remoteResidentPersonVo.setAuthEndDate(vo.getAuthEndDate());

View File

@@ -140,31 +140,26 @@ public class ResidentPersonServiceImpl implements IResidentPersonService {
ResidentPerson update = MapstructUtils.convert(bo, ResidentPerson.class);
assert update != null;
boolean flag;
// 人脸照片存在时,才同步修改授权
if (update.getAuthGroupId() != null && update.getAuthEndDate() != null && update.getImg() != null) {
ResidentPersonVo vo = queryById(update.getId());
Long e8Id = vo.getEEightId();
baseMapper.updateById(update);
// 显式移除e8id
LambdaUpdateWrapper<ResidentPerson> lqw = new LambdaUpdateWrapper<>();
lqw.eq(ResidentPerson::getId, update.getId())
.set(ResidentPerson::getEEightId, null);
flag = baseMapper.update(lqw) > 0;
boolean check = baseMapper.update(lqw) > 0;
if (flag && e8Id != null) {
if (check && e8Id != null) {
log.info("开始修改授权记录, {}", bo.getUserName());
// 先删除,定时任务增加
Boolean auth = remoteSisAuthService.deletePersonAuth(List.of(update.getId()), List.of(e8Id));
Assert.isTrue(auth, "修改授权记录失败!");
}
} else {
flag = baseMapper.updateById(update) > 0;
}
boolean flag = baseMapper.updateById(update) > 0;
Assert.isTrue(flag, "修改入驻员工失败!");
return flag;
}

View File

@@ -83,4 +83,9 @@ public class SisPersonLibImg extends TenantEntity {
*/
private String imgMd5Value;
/**
* 人员标签
*/
private Integer rosterType;
}

View File

@@ -91,4 +91,9 @@ public class SisPersonLibImgBo extends BaseEntity {
*/
private String imgMd5Value;
/**
* 人员标签
*/
private Integer rosterType;
}

View File

@@ -0,0 +1,32 @@
package org.dromara.sis.domain.enums;
import lombok.Getter;
/**
* @author lsm
* @apiNote RosterTypeEnum
* @since 2025/8/7
*/
@Getter
public enum RosterTypeEnum {
/**
* 红名单
*/
RED_LIST(1),
/**
* 白名单
*/
WHITE_LIST(2),
/**
* 黑名单名单
*/
BLACK_LIST(3);
private final Integer code;
RosterTypeEnum(Integer code) {
this.code = code;
}
}

View File

@@ -62,5 +62,9 @@ public class SisAuthRecordVo implements Serializable {
@ExcelProperty(value = "结束时间")
private Date endDate;
/**
* 人员标签
*/
private Integer rosterType;
}

View File

@@ -102,4 +102,10 @@ public class SisPersonLibImgVo implements Serializable {
*/
@ExcelProperty(value = "图片MD5")
private String imgMd5Value;
/**
* 人员标签
*/
@ExcelProperty(value = "人员标签")
private Integer rosterType;
}

View File

@@ -85,15 +85,15 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
}
/**
* 通过MD5查询图片id
* 通过MD5查询华为盒子id
*
* @param imgMd5 图片MD5
* @return Long
*/
@Override
public Long queryImgIdByImgMd5(String imgMd5) {
public Long queryHuaweiBoxIdByImgMd5(String imgMd5) {
SisPersonLibImgVo vo = sisPersonLibImgService.queryByImgMd5(imgMd5);
return vo != null ? vo.getId() : null;
return vo != null ? vo.getRemoteImgId() : null;
}
/**
@@ -118,6 +118,7 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
pId = huaWeiBoxApi.addPerson(List.of(req));
} catch (Exception e) {
log.error("同步华为盒子失败:{}----{}", person.getName(), person.getId());
return null;
}
return pId;
@@ -152,7 +153,7 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
try {
log.info("e8平台上传照片");
String e8ImgUrl = e8PlatformApi.uploadFace(imgByte);
Assert.notNull(e8ImgUrl, "图片上传E8平台失败");
Assert.notNull(e8ImgUrl, "图片上传E8平台失败" + person.getName() + "----" + person.getId());
log.info("e8平台上传照片完成");
count++; // 图片上传完成步进器+1
@@ -161,7 +162,7 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
req.setName(person.getName());
req.setGender(person.getSex() != 1 ? 0 : 1);
e8Id = e8PlatformApi.addCustomer(req).getId();
Assert.notNull(e8Id, "e8同步新建人员失败");
Assert.notNull(e8Id, "e8同步新建人员失败" + person.getName() + "----" + person.getId());
log.info("e8同步新建人员完成");
count++; // 新增人员完成步进器+1
@@ -172,7 +173,7 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
voucherReq.setTxtData(e8ImgUrl);
voucherReq.setCardType(34);
Long voucherId = e8PlatformApi.issueVoucher(voucherReq);
Assert.notNull(voucherId, "e8平台发行凭证失败");
Assert.notNull(voucherId, "e8平台发行凭证失败" + person.getName() + "----" + person.getId());
log.info("e8平台发行凭证成功");
count++; // 发行凭证完成步进器+1
@@ -199,11 +200,12 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
log.info("e8平台开始授权");
Boolean flag = e8PlatformApi.addCustomerAuth(authReq);
Assert.isTrue(flag, "E8平台授权失败");
Assert.isTrue(flag, "E8平台授权失败" + person.getName() + "----" + person.getId());
log.info("E8平台授权完成!");
count++; // 授权完成步进器+1
}
} catch (Exception e) {
log.info(e.getMessage());
return null;
}

View File

@@ -18,6 +18,7 @@ import org.dromara.sis.api.domain.RemotePersonAuth;
import org.dromara.sis.domain.bo.SisAccessControlBo;
import org.dromara.sis.domain.bo.SisElevatorInfoBo;
import org.dromara.sis.domain.bo.SisPersonLibImgBo;
import org.dromara.sis.domain.enums.RosterTypeEnum;
import org.dromara.sis.domain.vo.SisAccessControlVo;
import org.dromara.sis.domain.vo.SisElevatorInfoVo;
import org.dromara.sis.domain.vo.SisPersonLibImgVo;
@@ -115,6 +116,8 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByPerson(RemotePersonAuth bo) {
// 黑名单不加授权记录
if (!Objects.equals(bo.getRosterType(), RosterTypeEnum.BLACK_LIST.getCode())) {
SisAuthRecord add = new SisAuthRecord();
add.setTargetType(1L);
add.setTargetId(bo.getId());
@@ -124,21 +127,23 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
add.setTenantId("000000");
boolean flag = baseMapper.insert(add) > 0;
Assert.isTrue(flag, "新增授权记录失败");
}
try {
// 记录图片md5值
byte[] imgByte = remoteFileService.downloadToByteArray(Long.parseLong(bo.getOssId()));
String md5 = calculateMD5(imgByte);
// 写入安防人像信息
this.syncPersonImg(bo, md5);
Boolean sync = this.syncPersonImg(bo, md5);
Assert.isTrue(sync, "写入安防人像信息失败");
} catch (Exception e) {
log.info("下载图片失败");
log.info(e.getMessage());
}
return flag;
return true;
}
private void syncPersonImg(RemotePersonAuth bo, String md5) {
private Boolean syncPersonImg(RemotePersonAuth bo, String md5) {
log.info("开始写入安防人像信息");
SisPersonLibImgBo personLibImg = new SisPersonLibImgBo();
personLibImg.setImgOssId(Long.parseLong(bo.getOssId()));
@@ -149,8 +154,10 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
personLibImg.setCertificateNo(bo.getIdCardNumber());
personLibImg.setResidentPersonId(bo.getId());
personLibImg.setImgMd5Value(md5);
sisPersonLibImgService.insertByBo(personLibImg);
log.info("写入安防人像信息完成");
personLibImg.setRosterType(bo.getRosterType());
Boolean flag = sisPersonLibImgService.insertByBo(personLibImg);
if (flag) log.info("写入安防人像信息完成");
return flag;
}
/**
@@ -352,10 +359,8 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
public Boolean deleteByPersonIds(Collection<Long> ids, Collection<Long> e8Ids) {
LambdaQueryWrapper<SisAuthRecord> lqw = new LambdaQueryWrapper<>();
lqw.in(SisAuthRecord::getTargetId, ids);
boolean flag = baseMapper.delete(lqw) > 0;
Assert.isTrue(flag, "删除授权记录失败");
baseMapper.delete(lqw);
if (flag) {
List<SisPersonLibImgVo> list = new ArrayList<>();
ids.forEach(id -> {
SisPersonLibImgVo imgVo = sisPersonLibImgService.queryByPersonId(id);
@@ -364,16 +369,16 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
}
});
Collection<Long> imgIds = list.stream().map(SisPersonLibImgVo::getId).toList();
if (CollUtil.isNotEmpty(imgIds)){
flag = sisPersonLibImgService.deleteWithValidByIds(imgIds, false);
if (CollUtil.isNotEmpty(imgIds)) {
Boolean flag = sisPersonLibImgService.deleteWithValidByIds(imgIds, false);
Assert.isTrue(flag, "删除人像库图片失败");
}
if (CollUtil.isNotEmpty(e8Ids)){
if (CollUtil.isNotEmpty(e8Ids)) {
e8Ids.forEach(e8PlatformApi::deleteCustomer);
}
}
return flag;
return true;
}
/**
@@ -382,7 +387,7 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
* @param groupIds 权限组IDs
*/
@Override
public Boolean queryByGroupIds(Collection<Long> groupIds){
public Boolean queryByGroupIds(Collection<Long> groupIds) {
LambdaQueryWrapper<SisAuthRecord> lqw = Wrappers.lambdaQuery();
lqw.in(SisAuthRecord::getGroupId, groupIds);
List<SisAuthRecordVo> authVoList = baseMapper.selectVoList(lqw);

View File

@@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.property.api.RemoteFloorService;
import org.dromara.sis.domain.enums.RosterTypeEnum;
import org.dromara.sis.domain.vo.*;
import org.dromara.sis.producer.CleanLiftAuthRocketProducer;
import org.dromara.sis.sdk.e8.E8PlatformApi;
@@ -70,6 +71,12 @@ public class ZeroSensationPassageServiceImpl implements IZeroSensationPassageSer
// 不是内部人员 产生紧急的告警信息
alarmEventsService.createAlarmRecord(deviceIp, 1, 1, "陌生人员入内", smallImg, bigImg);
return;
}else {
if (Objects.equals(authRecord.getRosterType(), RosterTypeEnum.BLACK_LIST.getCode())) {
log.info("人员[{}]在黑名单中,暂不处理。", person);
alarmEventsService.createAlarmRecord(deviceIp, 3, 1, "黑名单人员入内", smallImg, bigImg);
return;
}
}
Date now = new Date();

View File

@@ -5,7 +5,7 @@ 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 c.target_id, c.group_id, c.beg_date, c.end_date
SELECT c.target_id, c.group_id, c.beg_date, c.end_date, a.roster_type
FROM sis_person_lib_img a
LEFT JOIN resident_person b ON a.resident_person_id = b.id and b.state = 1
LEFT JOIN sis_auth_record c

View File

@@ -0,0 +1,32 @@
package org.dromara.job.entity.enums;
import lombok.Getter;
/**
* @author lsm
* @apiNote RosterTypeEnum
* @since 2025/8/7
*/
@Getter
public enum RosterTypeEnum {
/**
* 红名单
*/
RED_LIST(1),
/**
* 白名单
*/
WHITE_LIST(2),
/**
* 黑名单名单
*/
BLACK_LIST(3);
private final Integer code;
RosterTypeEnum(Integer code) {
this.code = code;
}
}

View File

@@ -8,6 +8,7 @@ import com.aizuda.snailjob.client.job.core.dto.JobArgs;
import com.aizuda.snailjob.client.model.ExecuteResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.job.entity.enums.RosterTypeEnum;
import org.dromara.property.api.RemoteResidentPersonService;
import org.dromara.property.api.domain.vo.RemoteResidentPersonVo;
import org.dromara.resource.api.RemoteFileService;
@@ -18,6 +19,7 @@ import org.springframework.stereotype.Component;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
/**
@@ -53,20 +55,9 @@ public class SyncGrantAuthTask {
try {
if (CollUtil.isNotEmpty(unAuthPerson)) {
for (RemoteResidentPersonVo person : unAuthPerson) {
log.info("开始定时授权:{}----{}", person.getName(), person.getId());
// 判断是否存在授权
Boolean auth = remoteSisAuthService.queryPersonAuth(person.getAuthGroupId(), person.getId());
if (!auth) {
log.info("无授权记录:{}----{}", person.getName(), person.getId());
// 补录授权记录、人像信息
Boolean flag = syncAuthRecord(person);
if (!flag) {
log.info("补录授权记录、人像信息失败:{}----{}", person.getName(), person.getId());
continue;
}
// 下载人像
byte[] imgByte;
try {
@@ -78,10 +69,30 @@ public class SyncGrantAuthTask {
continue;
}
// 当前人员是黑名单
if (Objects.equals(person.getRosterType(), RosterTypeEnum.BLACK_LIST.getCode())) {
// 计算图片MD5
String nowMd5 = calculateMD5(imgByte);
// 通过MD5、入驻员工id查询相同图片
Long remoteId = remoteSisAuthService.queryHuaweiBoxIdByImgMd5(nowMd5);
// 人像信息已上传,跳过
if (remoteId != null) continue;
}
log.info("开始定时授权:{}----{}", person.getName(), person.getId());
// 补录授权记录、人像信息
Boolean flag = syncAuthRecord(person);
if (!flag) {
log.info("录入授权记录、人像信息失败:{}----{}", person.getName(), person.getId());
remoteSisAuthService.deletePersonAuth(List.of(person.getId()), new ArrayList<>());
continue;
}
// // 计算图片MD5
// String nowMd5 = calculateMD5(imgByte);
// // 通过MD5查询相同图片
// Long remoteId = remoteSisAuthService.queryImgIdByImgMd5(nowMd5);
// Long remoteId = remoteSisAuthService.queryHuaweiBoxIdByImgMd5(nowMd5);
//
// Long huaweiId;
// if (remoteId == null) {
@@ -102,6 +113,7 @@ public class SyncGrantAuthTask {
// update = remoteSisAuthService.updateImgByPersonId(person.getId(), huaweiId, nowMd5);
// } catch (Exception e) {
// remoteSisAuthService.deletePersonAuth(List.of(person.getId()), new ArrayList<>());
// continue;
// }
//
// if (!update) {
@@ -110,6 +122,8 @@ public class SyncGrantAuthTask {
// continue;
// }
// 黑名单不授权到E8
if (!Objects.equals(person.getRosterType(), RosterTypeEnum.BLACK_LIST.getCode())) {
// 同步人像到E8平台
Long e8Id = syncE8Plat(person, imgByte);
if (e8Id == null) {
@@ -117,11 +131,11 @@ public class SyncGrantAuthTask {
remoteSisAuthService.deletePersonAuth(List.of(person.getId()), new ArrayList<>());
continue;
}
// 更新入驻员工E8平台id
remoteResidentPersonService.updateE8Id(person.getId(), e8Id);
}
} else {
// 存在授权记录,为了避免重复授权,删除授权记录
// 存在授权记录,为了避免重复授权,删除授权记录,等待下次定时任务
remoteSisAuthService.deletePersonAuth(List.of(person.getId()), new ArrayList<>());
}
}
@@ -144,14 +158,14 @@ public class SyncGrantAuthTask {
* @param person bean
*/
private Boolean syncAuthRecord(RemoteResidentPersonVo person) {
log.info("开始录授权记录、人像信息:{}----{}", person.getName(), person.getId());
log.info("开始录授权记录、人像信息:{}----{}", person.getName(), person.getId());
RemotePersonAuth personAuth = getRemotePersonAuth(person);
Boolean flag;
try {
flag = remoteSisAuthService.personAuth(personAuth);
if (flag) {
log.info("录授权记录、人像信息完成:{}----{}", person.getName(), person.getId());
log.info("授权记录、人像信息完成:{}----{}", person.getName(), person.getId());
}
} catch (Exception e) {
return false;
@@ -168,11 +182,12 @@ public class SyncGrantAuthTask {
personAuth.setOssId(person.getOssId());
personAuth.setName(person.getName());
personAuth.setPhone(person.getPhone());
personAuth.setSex(person.getGender().intValue());
personAuth.setIdCardNumber(person.getIdCard());
personAuth.setSex(person.getGender().intValue());
personAuth.setAuthGroupId(person.getAuthGroupId());
personAuth.setAuthBegDate(person.getAuthBegDate());
personAuth.setAuthEndDate(person.getAuthEndDate());
personAuth.setRosterType(person.getRosterType());
return personAuth;
}