refactor(property): 优化人员导入和人脸上传功能
This commit is contained in:
parent
f0beb7be5e
commit
79f98b5387
@ -37,7 +37,7 @@ public class ResidentPersonBo extends BaseEntity {
|
|||||||
/**
|
/**
|
||||||
* 联系电话
|
* 联系电话
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "联系电话不能为空", groups = {AddGroup.class, EditGroup.class})
|
// @NotBlank(message = "联系电话不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
private String phone;
|
private String phone;
|
||||||
/**
|
/**
|
||||||
* 人员类型
|
* 人员类型
|
||||||
@ -53,7 +53,7 @@ public class ResidentPersonBo extends BaseEntity {
|
|||||||
/**
|
/**
|
||||||
* 证件号
|
* 证件号
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "证件号不能为空", groups = {AddGroup.class, EditGroup.class})
|
// @NotBlank(message = "证件号不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
private String idCard;
|
private String idCard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,33 +57,31 @@ public class ResidentPersonImportListener extends AnalysisEventListener<Resident
|
|||||||
@Override
|
@Override
|
||||||
public void invoke(ResidentPersonImportVo personVo, AnalysisContext context) {
|
public void invoke(ResidentPersonImportVo personVo, AnalysisContext context) {
|
||||||
ResidentUnitVo unitVo = residentUnitService.queryById(unitId);
|
ResidentUnitVo unitVo = residentUnitService.queryById(unitId);
|
||||||
List<ResidentPersonVo> list = new ArrayList<>();
|
ResidentPersonVo person = new ResidentPersonVo();
|
||||||
// 判断证件号是否为空
|
// 判断证件号是否为空
|
||||||
if (StringUtils.isEmpty(personVo.getIdCard())) {
|
if (StringUtils.isEmpty(personVo.getIdCard())) {
|
||||||
failureNum++;
|
failureNum++;
|
||||||
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(personVo.getUserName()).append(" 证件号不能为空!");
|
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(personVo.getUserName()).append(" 证件号不能为空!");
|
||||||
} else {
|
} else {
|
||||||
ResidentPersonBo personBo = new ResidentPersonBo();
|
person = residentPersonService.queryByUnitIdAndName(unitId, person.getUserName());
|
||||||
personBo.setUnitId(unitId);
|
|
||||||
personBo.setIdCard(personVo.getIdCard());
|
|
||||||
list = residentPersonService.queryList(personBo);
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (list.isEmpty()) { // 判断当前单位是否已存在该用户
|
if (person == null) { // 判断当前单位是否已存在该用户
|
||||||
ResidentPersonBo bo = BeanUtil.toBean(personVo, ResidentPersonBo.class);
|
ResidentPersonBo bo = BeanUtil.toBean(personVo, ResidentPersonBo.class);
|
||||||
ValidatorUtils.validate(bo);
|
ValidatorUtils.validate(bo);
|
||||||
bo.setState(1L);
|
bo.setState(1L);
|
||||||
bo.setUnitId(unitId);
|
bo.setUnitId(unitId);
|
||||||
bo.setTime(new Date());
|
bo.setTime(new Date());
|
||||||
bo.setUnitName(unitVo.getName());
|
bo.setUnitName(unitVo.getName().trim());
|
||||||
bo.setAuthGroupId(unitVo.getAuthGroupId());
|
bo.setAuthGroupId(unitVo.getAuthGroupId());
|
||||||
bo.setAuthBegDate(unitVo.getAuthBegDate());
|
bo.setAuthBegDate(unitVo.getAuthBegDate());
|
||||||
bo.setAuthEndDate(unitVo.getAuthEndDate());
|
bo.setAuthEndDate(unitVo.getAuthEndDate());
|
||||||
|
bo.setUserName(personVo.getUserName().replaceAll("[\\s\u3000]", ""));
|
||||||
residentPersonService.insertByBo(bo);
|
residentPersonService.insertByBo(bo);
|
||||||
successNum++;
|
successNum++;
|
||||||
successMsg.append("<br/>").append(successNum).append("、账号 ").append(bo.getUserName()).append(" 导入成功");
|
successMsg.append("<br/>").append(successNum).append("、账号 ").append(bo.getUserName()).append(" 导入成功");
|
||||||
} else if (isUpdateSupport) {
|
} else if (isUpdateSupport) {
|
||||||
Long id = list.get(0).getUserId();
|
Long id = person.getUserId();
|
||||||
ResidentPersonBo bo = BeanUtil.toBean(personVo, ResidentPersonBo.class);
|
ResidentPersonBo bo = BeanUtil.toBean(personVo, ResidentPersonBo.class);
|
||||||
bo.setId(id);
|
bo.setId(id);
|
||||||
ValidatorUtils.validate(bo);
|
ValidatorUtils.validate(bo);
|
||||||
@ -93,7 +91,7 @@ public class ResidentPersonImportListener extends AnalysisEventListener<Resident
|
|||||||
successMsg.append("<br/>").append(successNum).append("、账号 ").append(bo.getUserName()).append(" 更新成功");
|
successMsg.append("<br/>").append(successNum).append("、账号 ").append(bo.getUserName()).append(" 更新成功");
|
||||||
} else {
|
} else {
|
||||||
failureNum++;
|
failureNum++;
|
||||||
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(list.get(0).getUserName()).append(" 已存在");
|
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(personVo.getUserName()).append(" 已存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -69,7 +69,7 @@ public interface IResidentPersonService {
|
|||||||
/**
|
/**
|
||||||
* 获取单位人员数量
|
* 获取单位人员数量
|
||||||
*
|
*
|
||||||
* @param unitId 单元id
|
* @param unitId 单位id
|
||||||
* @return Long
|
* @return Long
|
||||||
*/
|
*/
|
||||||
Long queryPersonCount(Long unitId);
|
Long queryPersonCount(Long unitId);
|
||||||
@ -80,4 +80,12 @@ public interface IResidentPersonService {
|
|||||||
* @return List<ResidentPersonVo>
|
* @return List<ResidentPersonVo>
|
||||||
*/
|
*/
|
||||||
List<ResidentPersonVo> queryUnAuthPerson();
|
List<ResidentPersonVo> queryUnAuthPerson();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过单位和姓名,查询人员信息
|
||||||
|
*
|
||||||
|
* @param unitId 单位id
|
||||||
|
* @param name 姓名
|
||||||
|
*/
|
||||||
|
ResidentPersonVo queryByUnitIdAndName(Long unitId, String name);
|
||||||
}
|
}
|
||||||
|
@ -169,16 +169,16 @@ public class ResidentPersonServiceImpl implements IResidentPersonService {
|
|||||||
if (update.getAuthGroupId() != null && update.getAuthEndDate() != null && update.getImg() != null) {
|
if (update.getAuthGroupId() != null && update.getAuthEndDate() != null && update.getImg() != null) {
|
||||||
ResidentPersonVo vo = queryById(update.getId());
|
ResidentPersonVo vo = queryById(update.getId());
|
||||||
Long e8Id = vo.getEEightId();
|
Long e8Id = vo.getEEightId();
|
||||||
flag = baseMapper.updateById(update) > 0;
|
baseMapper.updateById(update);
|
||||||
|
|
||||||
// 显式移除e8id
|
// 显式移除e8id
|
||||||
LambdaUpdateWrapper<ResidentPerson> lqw = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<ResidentPerson> lqw = new LambdaUpdateWrapper<>();
|
||||||
lqw.eq(ResidentPerson::getId, update.getId())
|
lqw.eq(ResidentPerson::getId, update.getId())
|
||||||
.set(ResidentPerson::getEEightId, null);
|
.set(ResidentPerson::getEEightId, null);
|
||||||
baseMapper.update(lqw);
|
flag = baseMapper.update(lqw) > 0;
|
||||||
|
|
||||||
|
|
||||||
if (flag) {
|
if (flag && e8Id != null) {
|
||||||
log.info("开始修改授权记录, {}", bo.getUserName());
|
log.info("开始修改授权记录, {}", bo.getUserName());
|
||||||
RemotePersonAuth personAuth = new RemotePersonAuth();
|
RemotePersonAuth personAuth = new RemotePersonAuth();
|
||||||
personAuth.setId(update.getId());
|
personAuth.setId(update.getId());
|
||||||
@ -224,7 +224,7 @@ public class ResidentPersonServiceImpl implements IResidentPersonService {
|
|||||||
private void validEntityBeforeSave(ResidentPerson entity) {
|
private void validEntityBeforeSave(ResidentPerson entity) {
|
||||||
//TODO 做一些数据校验,如唯一约束
|
//TODO 做一些数据校验,如唯一约束
|
||||||
LambdaQueryWrapper<ResidentPerson> lqw = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<ResidentPerson> lqw = Wrappers.lambdaQuery();
|
||||||
lqw.eq(ResidentPerson::getIdCard, entity.getIdCard())
|
lqw.eq(ResidentPerson::getIdCard, entity.getUserName())
|
||||||
.eq(ResidentPerson::getUnitId, entity.getUnitId());
|
.eq(ResidentPerson::getUnitId, entity.getUnitId());
|
||||||
boolean exists = baseMapper.exists(lqw);
|
boolean exists = baseMapper.exists(lqw);
|
||||||
Assert.isTrue(!exists, "当前单位,{}已入驻!", entity.getUserName());
|
Assert.isTrue(!exists, "当前单位,{}已入驻!", entity.getUserName());
|
||||||
@ -252,9 +252,12 @@ public class ResidentPersonServiceImpl implements IResidentPersonService {
|
|||||||
.map(ResidentPersonVo::getEEightId)
|
.map(ResidentPersonVo::getEEightId)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.toList();
|
.toList();
|
||||||
|
if (!e8Ids.isEmpty()) {
|
||||||
boolean auth = remoteSisAuth.deletePersonAuth(ids, e8Ids);
|
boolean auth = remoteSisAuth.deletePersonAuth(ids, e8Ids);
|
||||||
Assert.isTrue(auth, "删除授权记录失败!");
|
Assert.isTrue(auth, "删除授权记录失败!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return baseMapper.deleteByIds(ids) > 0;
|
return baseMapper.deleteByIds(ids) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,4 +287,19 @@ public class ResidentPersonServiceImpl implements IResidentPersonService {
|
|||||||
.isNull(ResidentPerson::getEEightId);
|
.isNull(ResidentPerson::getEEightId);
|
||||||
return baseMapper.selectVoList(lqw);
|
return baseMapper.selectVoList(lqw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过单位和姓名,查询人员信息
|
||||||
|
*
|
||||||
|
* @param unitId 单位id
|
||||||
|
* @param name 姓名
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ResidentPersonVo queryByUnitIdAndName(Long unitId, String name) {
|
||||||
|
LambdaQueryWrapper<ResidentPerson> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.eq(ResidentPerson::getUnitId, unitId)
|
||||||
|
.eq(ResidentPerson::getUserName, name);
|
||||||
|
List<ResidentPersonVo> list = baseMapper.selectVoList(lqw);
|
||||||
|
return list.isEmpty() ? null : list.get(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
@ -39,7 +38,7 @@ public class UploadFaceUtil {
|
|||||||
// 安全配置参数(实际项目中可以从配置文件读取)
|
// 安全配置参数(实际项目中可以从配置文件读取)
|
||||||
private static final int MAX_TOTAL_SIZE = 50 * 1024 * 1024; // 50MB 最大解压总大小
|
private static final int MAX_TOTAL_SIZE = 50 * 1024 * 1024; // 50MB 最大解压总大小
|
||||||
private static final int MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB 最大单个文件大小
|
private static final int MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB 最大单个文件大小
|
||||||
private static final int MAX_FILE_COUNT = 30; // 最大文件数量
|
private static final int MAX_FILE_COUNT = 50; // 最大文件数量
|
||||||
|
|
||||||
private static final Map<String, String> CONTENT_TYPE_MAP = new HashMap<>();
|
private static final Map<String, String> CONTENT_TYPE_MAP = new HashMap<>();
|
||||||
static {
|
static {
|
||||||
@ -59,7 +58,7 @@ public class UploadFaceUtil {
|
|||||||
// 重置统计信息
|
// 重置统计信息
|
||||||
resetStats();
|
resetStats();
|
||||||
|
|
||||||
try (ZipInputStream zis = new ZipInputStream(zipFile.getInputStream())) {
|
try (ZipInputStream zis = new ZipInputStream(zipFile.getInputStream(), StandardCharsets.UTF_8)) {
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
byte[] buffer = new byte[8192]; // 8KB缓冲区
|
byte[] buffer = new byte[8192]; // 8KB缓冲区
|
||||||
long totalExtractedSize = 0;
|
long totalExtractedSize = 0;
|
||||||
@ -126,19 +125,16 @@ public class UploadFaceUtil {
|
|||||||
bao.write(buffer, 0, len);
|
bao.write(buffer, 0, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResidentPersonBo bo = new ResidentPersonBo();
|
ResidentPersonVo personVo = residentPersonService.queryByUnitIdAndName(unitId, name);
|
||||||
bo.setUnitId(unitId);
|
|
||||||
bo.setUserName(name);
|
|
||||||
List<ResidentPersonVo> personVos = residentPersonService.queryList(bo);
|
|
||||||
// 判断当前姓名是否存在入驻单位
|
// 判断当前姓名是否存在入驻单位
|
||||||
if (personVos.isEmpty()) continue;
|
if (personVo == null) continue;
|
||||||
|
|
||||||
byte[] imageData = bao.toByteArray();
|
byte[] imageData = bao.toByteArray();
|
||||||
|
|
||||||
RemoteFile remoteFile = remoteFileService.upload(name, name, contentType, imageData);
|
RemoteFile remoteFile = remoteFileService.upload(name, entry.getName(), contentType, imageData);
|
||||||
|
|
||||||
personVos.get(0).setImg(remoteFile.getOssId().toString());
|
personVo.setImg(remoteFile.getOssId().toString());
|
||||||
ResidentPersonBo updateBo = BeanUtil.toBean(personVos.get(0), ResidentPersonBo.class);
|
ResidentPersonBo updateBo = BeanUtil.toBean(personVo, ResidentPersonBo.class);
|
||||||
residentPersonService.updateByBo(updateBo);
|
residentPersonService.updateByBo(updateBo);
|
||||||
|
|
||||||
totalFiles++;
|
totalFiles++;
|
||||||
|
@ -61,7 +61,7 @@ public class AuthSyncTask {
|
|||||||
/**
|
/**
|
||||||
* 每两分钟执行一次
|
* 每两分钟执行一次
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "0 */2 * * * ?")
|
@Scheduled(cron = "0 */5 * * * ?")
|
||||||
public void autoAuth() {
|
public void autoAuth() {
|
||||||
AtomicReference<List<RemoteResidentPersonVo>> unAuthPersonRef = new AtomicReference<>(new ArrayList<>());
|
AtomicReference<List<RemoteResidentPersonVo>> unAuthPersonRef = new AtomicReference<>(new ArrayList<>());
|
||||||
AtomicReference<byte[]> imgByteRef = new AtomicReference<>(new byte[0]);
|
AtomicReference<byte[]> imgByteRef = new AtomicReference<>(new byte[0]);
|
||||||
@ -81,35 +81,34 @@ public class AuthSyncTask {
|
|||||||
// 判断是否已存在授权
|
// 判断是否已存在授权
|
||||||
SisAuthRecordVo authRecord = sisAuthRecordService.queryByGroupIdAndPersonId(person.getAuthGroupId(), person.getId());
|
SisAuthRecordVo authRecord = sisAuthRecordService.queryByGroupIdAndPersonId(person.getAuthGroupId(), person.getId());
|
||||||
if (ObjectUtil.isEmpty(authRecord)) {
|
if (ObjectUtil.isEmpty(authRecord)) {
|
||||||
// 无授权记录时,补录
|
log.info("无授权记录:{}", person.getId());
|
||||||
this.syncAuthRecord(person);
|
this.syncAuthRecord(person);
|
||||||
}
|
|
||||||
|
|
||||||
imgByteRef.set(remoteFileService.downloadToByteArray(Long.parseLong(person.getOssId())));
|
imgByteRef.set(remoteFileService.downloadToByteArray(Long.parseLong(person.getOssId())));
|
||||||
// 读取人像
|
// 读取人像
|
||||||
byte[] imgByte = imgByteRef.get();
|
byte[] imgByte = imgByteRef.get();
|
||||||
if (imgByte == null) continue;
|
if (imgByte == null) continue;
|
||||||
|
|
||||||
String nowMd5 = this.calculateMD5(imgByte);
|
// String nowMd5 = this.calculateMD5(imgByte);
|
||||||
SisPersonLibImgVo imgVo = sisPersonLibImgService.queryByImgMd5(nowMd5);
|
// SisPersonLibImgVo imgVo = sisPersonLibImgService.queryByImgMd5(nowMd5);
|
||||||
|
//
|
||||||
Long huaweiId;
|
// Long huaweiId;
|
||||||
Boolean update;
|
// Boolean update;
|
||||||
if (ObjectUtil.isEmpty(imgVo)) {
|
// if (ObjectUtil.isEmpty(imgVo)) {
|
||||||
// 写入华为盒子
|
// // 写入华为盒子
|
||||||
huaweiId = syncHuaweiBox(person, imgByte);
|
// huaweiId = syncHuaweiBox(person, imgByte);
|
||||||
} else {
|
// } else {
|
||||||
if (imgVo.getRemoteImgId() == null) {
|
// if (imgVo.getRemoteImgId() == null) {
|
||||||
huaweiId = syncHuaweiBox(person, imgByte);
|
// huaweiId = syncHuaweiBox(person, imgByte);
|
||||||
} else {
|
// } else {
|
||||||
huaweiId = imgVo.getRemoteImgId();
|
// huaweiId = imgVo.getRemoteImgId();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (huaweiId == null) continue;
|
// if (huaweiId == null) continue;
|
||||||
|
//
|
||||||
// 更新人像信息huaweiBoxId
|
// // 更新人像信息huaweiBoxId
|
||||||
update = sisPersonLibImgService.updateByPersonId(person.getId(), huaweiId, nowMd5);
|
// update = sisPersonLibImgService.updateByPersonId(person.getId(), huaweiId, nowMd5);
|
||||||
if (!update) continue;
|
// if (!update) continue;
|
||||||
|
|
||||||
// 同步E8平台
|
// 同步E8平台
|
||||||
Long e8Id = syncE8Plat(person, imgByte);
|
Long e8Id = syncE8Plat(person, imgByte);
|
||||||
@ -117,7 +116,9 @@ public class AuthSyncTask {
|
|||||||
|
|
||||||
// 更新入驻员工E8平台id
|
// 更新入驻员工E8平台id
|
||||||
remoteResidentPersonService.updateE8Id(person.getId(), e8Id);
|
remoteResidentPersonService.updateE8Id(person.getId(), e8Id);
|
||||||
|
}else{
|
||||||
|
log.info("已存在授权记录:{}", person.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("无待授权人员");
|
log.info("无待授权人员");
|
||||||
|
Loading…
Reference in New Issue
Block a user