From 79f98b538715fa1abb6b42dd155e7e9b3c54dd7c Mon Sep 17 00:00:00 2001 From: zcxlsm Date: Wed, 30 Jul 2025 19:58:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor(property):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BA=BA=E5=91=98=E5=AF=BC=E5=85=A5=E5=92=8C=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../property/domain/bo/ResidentPersonBo.java | 4 +- .../ResidentPersonImportListener.java | 16 ++-- .../service/IResidentPersonService.java | 10 ++- .../impl/ResidentPersonServiceImpl.java | 30 ++++++-- .../property/utils/UploadFaceUtil.java | 20 ++--- .../org/dromara/sis/task/AuthSyncTask.java | 73 ++++++++++--------- 6 files changed, 87 insertions(+), 66 deletions(-) diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/ResidentPersonBo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/ResidentPersonBo.java index efd5adf..0879477 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/ResidentPersonBo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/ResidentPersonBo.java @@ -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; /** * 人员类型 @@ -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; /** diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/listener/ResidentPersonImportListener.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/listener/ResidentPersonImportListener.java index 678fcf4..0231a2c 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/listener/ResidentPersonImportListener.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/listener/ResidentPersonImportListener.java @@ -57,33 +57,31 @@ public class ResidentPersonImportListener extends AnalysisEventListener list = new ArrayList<>(); + ResidentPersonVo person = new ResidentPersonVo(); // 判断证件号是否为空 if (StringUtils.isEmpty(personVo.getIdCard())) { failureNum++; failureMsg.append("
").append(failureNum).append("、账号 ").append(personVo.getUserName()).append(" 证件号不能为空!"); } else { - ResidentPersonBo personBo = new ResidentPersonBo(); - personBo.setUnitId(unitId); - personBo.setIdCard(personVo.getIdCard()); - list = residentPersonService.queryList(personBo); + person = residentPersonService.queryByUnitIdAndName(unitId, person.getUserName()); } try { - if (list.isEmpty()) { // 判断当前单位是否已存在该用户 + if (person == null) { // 判断当前单位是否已存在该用户 ResidentPersonBo bo = BeanUtil.toBean(personVo, ResidentPersonBo.class); ValidatorUtils.validate(bo); bo.setState(1L); bo.setUnitId(unitId); bo.setTime(new Date()); - bo.setUnitName(unitVo.getName()); + bo.setUnitName(unitVo.getName().trim()); bo.setAuthGroupId(unitVo.getAuthGroupId()); bo.setAuthBegDate(unitVo.getAuthBegDate()); bo.setAuthEndDate(unitVo.getAuthEndDate()); + bo.setUserName(personVo.getUserName().replaceAll("[\\s\u3000]", "")); residentPersonService.insertByBo(bo); successNum++; successMsg.append("
").append(successNum).append("、账号 ").append(bo.getUserName()).append(" 导入成功"); } else if (isUpdateSupport) { - Long id = list.get(0).getUserId(); + Long id = person.getUserId(); ResidentPersonBo bo = BeanUtil.toBean(personVo, ResidentPersonBo.class); bo.setId(id); ValidatorUtils.validate(bo); @@ -93,7 +91,7 @@ public class ResidentPersonImportListener extends AnalysisEventListener").append(successNum).append("、账号 ").append(bo.getUserName()).append(" 更新成功"); } else { failureNum++; - failureMsg.append("
").append(failureNum).append("、账号 ").append(list.get(0).getUserName()).append(" 已存在"); + failureMsg.append("
").append(failureNum).append("、账号 ").append(personVo.getUserName()).append(" 已存在"); } } catch (Exception e) { diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IResidentPersonService.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IResidentPersonService.java index fde3919..6b9251b 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IResidentPersonService.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IResidentPersonService.java @@ -69,7 +69,7 @@ public interface IResidentPersonService { /** * 获取单位人员数量 * - * @param unitId 单元id + * @param unitId 单位id * @return Long */ Long queryPersonCount(Long unitId); @@ -80,4 +80,12 @@ public interface IResidentPersonService { * @return List */ List queryUnAuthPerson(); + + /** + * 通过单位和姓名,查询人员信息 + * + * @param unitId 单位id + * @param name 姓名 + */ + ResidentPersonVo queryByUnitIdAndName(Long unitId, String name); } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/ResidentPersonServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/ResidentPersonServiceImpl.java index 7ed604b..87d22c7 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/ResidentPersonServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/ResidentPersonServiceImpl.java @@ -169,16 +169,16 @@ public class ResidentPersonServiceImpl implements IResidentPersonService { if (update.getAuthGroupId() != null && update.getAuthEndDate() != null && update.getImg() != null) { ResidentPersonVo vo = queryById(update.getId()); Long e8Id = vo.getEEightId(); - flag = baseMapper.updateById(update) > 0; + baseMapper.updateById(update); // 显式移除e8id LambdaUpdateWrapper lqw = new LambdaUpdateWrapper<>(); lqw.eq(ResidentPerson::getId, update.getId()) .set(ResidentPerson::getEEightId, null); - baseMapper.update(lqw); + flag = baseMapper.update(lqw) > 0; - if (flag) { + if (flag && e8Id != null) { log.info("开始修改授权记录, {}", bo.getUserName()); RemotePersonAuth personAuth = new RemotePersonAuth(); personAuth.setId(update.getId()); @@ -224,7 +224,7 @@ public class ResidentPersonServiceImpl implements IResidentPersonService { private void validEntityBeforeSave(ResidentPerson entity) { //TODO 做一些数据校验,如唯一约束 LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); - lqw.eq(ResidentPerson::getIdCard, entity.getIdCard()) + lqw.eq(ResidentPerson::getIdCard, entity.getUserName()) .eq(ResidentPerson::getUnitId, entity.getUnitId()); boolean exists = baseMapper.exists(lqw); Assert.isTrue(!exists, "当前单位,{}已入驻!", entity.getUserName()); @@ -252,8 +252,11 @@ public class ResidentPersonServiceImpl implements IResidentPersonService { .map(ResidentPersonVo::getEEightId) .filter(Objects::nonNull) .toList(); - boolean auth = remoteSisAuth.deletePersonAuth(ids, e8Ids); - Assert.isTrue(auth, "删除授权记录失败!"); + if (!e8Ids.isEmpty()) { + boolean auth = remoteSisAuth.deletePersonAuth(ids, e8Ids); + Assert.isTrue(auth, "删除授权记录失败!"); + } + } return baseMapper.deleteByIds(ids) > 0; } @@ -284,4 +287,19 @@ public class ResidentPersonServiceImpl implements IResidentPersonService { .isNull(ResidentPerson::getEEightId); return baseMapper.selectVoList(lqw); } + + /** + * 通过单位和姓名,查询人员信息 + * + * @param unitId 单位id + * @param name 姓名 + */ + @Override + public ResidentPersonVo queryByUnitIdAndName(Long unitId, String name) { + LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); + lqw.eq(ResidentPerson::getUnitId, unitId) + .eq(ResidentPerson::getUserName, name); + List list = baseMapper.selectVoList(lqw); + return list.isEmpty() ? null : list.get(0); + } } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/utils/UploadFaceUtil.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/utils/UploadFaceUtil.java index c98d598..ead227a 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/utils/UploadFaceUtil.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/utils/UploadFaceUtil.java @@ -14,9 +14,8 @@ import org.springframework.web.multipart.MultipartFile; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.zip.ZipEntry; 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_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 CONTENT_TYPE_MAP = new HashMap<>(); static { @@ -59,7 +58,7 @@ public class UploadFaceUtil { // 重置统计信息 resetStats(); - try (ZipInputStream zis = new ZipInputStream(zipFile.getInputStream())) { + try (ZipInputStream zis = new ZipInputStream(zipFile.getInputStream(), StandardCharsets.UTF_8)) { ZipEntry entry; byte[] buffer = new byte[8192]; // 8KB缓冲区 long totalExtractedSize = 0; @@ -126,19 +125,16 @@ public class UploadFaceUtil { bao.write(buffer, 0, len); } - ResidentPersonBo bo = new ResidentPersonBo(); - bo.setUnitId(unitId); - bo.setUserName(name); - List personVos = residentPersonService.queryList(bo); + ResidentPersonVo personVo = residentPersonService.queryByUnitIdAndName(unitId, name); // 判断当前姓名是否存在入驻单位 - if (personVos.isEmpty()) continue; + if (personVo == null) continue; 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()); - ResidentPersonBo updateBo = BeanUtil.toBean(personVos.get(0), ResidentPersonBo.class); + personVo.setImg(remoteFile.getOssId().toString()); + ResidentPersonBo updateBo = BeanUtil.toBean(personVo, ResidentPersonBo.class); residentPersonService.updateByBo(updateBo); totalFiles++; diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/task/AuthSyncTask.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/task/AuthSyncTask.java index 901f54c..fc6acec 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/task/AuthSyncTask.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/task/AuthSyncTask.java @@ -61,7 +61,7 @@ public class AuthSyncTask { /** * 每两分钟执行一次 */ - @Scheduled(cron = "0 */2 * * * ?") + @Scheduled(cron = "0 */5 * * * ?") public void autoAuth() { AtomicReference> unAuthPersonRef = new AtomicReference<>(new ArrayList<>()); AtomicReference imgByteRef = new AtomicReference<>(new byte[0]); @@ -81,43 +81,44 @@ public class AuthSyncTask { // 判断是否已存在授权 SisAuthRecordVo authRecord = sisAuthRecordService.queryByGroupIdAndPersonId(person.getAuthGroupId(), person.getId()); if (ObjectUtil.isEmpty(authRecord)) { - // 无授权记录时,补录 + log.info("无授权记录:{}", person.getId()); this.syncAuthRecord(person); + + imgByteRef.set(remoteFileService.downloadToByteArray(Long.parseLong(person.getOssId()))); + // 读取人像 + byte[] imgByte = imgByteRef.get(); + if (imgByte == null) continue; + +// String nowMd5 = this.calculateMD5(imgByte); +// SisPersonLibImgVo imgVo = sisPersonLibImgService.queryByImgMd5(nowMd5); +// +// Long huaweiId; +// Boolean update; +// if (ObjectUtil.isEmpty(imgVo)) { +// // 写入华为盒子 +// huaweiId = syncHuaweiBox(person, imgByte); +// } else { +// if (imgVo.getRemoteImgId() == null) { +// huaweiId = syncHuaweiBox(person, imgByte); +// } else { +// huaweiId = imgVo.getRemoteImgId(); +// } +// } +// if (huaweiId == null) continue; +// +// // 更新人像信息huaweiBoxId +// update = sisPersonLibImgService.updateByPersonId(person.getId(), huaweiId, nowMd5); +// if (!update) continue; + + // 同步E8平台 + Long e8Id = syncE8Plat(person, imgByte); + if (e8Id == null) continue; + + // 更新入驻员工E8平台id + remoteResidentPersonService.updateE8Id(person.getId(), e8Id); + }else{ + log.info("已存在授权记录:{}", person.getId()); } - - imgByteRef.set(remoteFileService.downloadToByteArray(Long.parseLong(person.getOssId()))); - // 读取人像 - byte[] imgByte = imgByteRef.get(); - if (imgByte == null) continue; - - String nowMd5 = this.calculateMD5(imgByte); - SisPersonLibImgVo imgVo = sisPersonLibImgService.queryByImgMd5(nowMd5); - - Long huaweiId; - Boolean update; - if (ObjectUtil.isEmpty(imgVo)) { - // 写入华为盒子 - huaweiId = syncHuaweiBox(person, imgByte); - } else { - if (imgVo.getRemoteImgId() == null) { - huaweiId = syncHuaweiBox(person, imgByte); - } else { - huaweiId = imgVo.getRemoteImgId(); - } - } - if (huaweiId == null) continue; - - // 更新人像信息huaweiBoxId - update = sisPersonLibImgService.updateByPersonId(person.getId(), huaweiId, nowMd5); - if (!update) continue; - - // 同步E8平台 - Long e8Id = syncE8Plat(person, imgByte); - if (e8Id == null) continue; - - // 更新入驻员工E8平台id - remoteResidentPersonService.updateE8Id(person.getId(), e8Id); - } } else { log.info("无待授权人员");