From ec7c3e5aa5d2b3b94ddb47bc94eb32aa77f6e75e Mon Sep 17 00:00:00 2001 From: dzq Date: Fri, 25 Apr 2025 15:21:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor(QywxScheduleJob):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E5=90=8C=E6=AD=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除冗余的用户列表查询和删除用户逻辑,简化代码结构并提高执行效率 --- .../customize/service/QywxScheduleJob.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/QywxScheduleJob.java b/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/QywxScheduleJob.java index f5fbca5..9b8392b 100644 --- a/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/QywxScheduleJob.java +++ b/agileboot-admin/src/main/java/com/agileboot/admin/customize/service/QywxScheduleJob.java @@ -411,13 +411,6 @@ public class QywxScheduleJob { .filter(d -> Objects.equals(d.getCorpid(), authCorpInfo.getCorpid())) .collect(Collectors.toList()); - List qyUserList = qyUserApplicationService.selectAll(); - if (null == qyUserList) { - qyUserList = new ArrayList<>(); - } - qyUserList = qyUserList.stream() - .filter(u -> u.getCorpid().equals(authCorpInfo.getCorpid())) - .collect(Collectors.toList()); for (QyDepartmentEntity department : departmentList) { // 获取部门用户列表 @@ -440,26 +433,29 @@ public class QywxScheduleJob { Map wxUserMap = wxUsers.stream() .collect(Collectors.toMap(UserListResponse.UserInfo::getUserid, Function.identity())); - List localUsers = qyUserList.stream() - .filter(u -> u.getAppid().equals(appid)) - .collect(Collectors.toList()); - Map localUserMap = localUsers.stream() - .collect(Collectors.toMap(QyUserEntity::getUserid, Function.identity())); + List qyUserList = qyUserApplicationService.selectAll(); + if (null == qyUserList) { + qyUserList = new ArrayList<>(); + } + qyUserList = qyUserList.stream() + .filter(u -> u.getCorpid().equals(authCorpInfo.getCorpid()) && u.getAppid().equals(appid)) + .collect(Collectors.toList()); // 识别需要新增的用户 + List finalQyUserList = qyUserList; List toAdd = wxUsers.stream() - .filter(wxUser -> !localUserMap.containsKey(wxUser.getUserid())) + .filter(wxUser -> finalQyUserList.stream().noneMatch(u -> u.getUserid().equals(wxUser.getUserid()))) .collect(Collectors.toList()); log.info("syncUserInfo toAdd: {}", JSONUtil.toJsonStr(toAdd)); // 识别需要删除的用户 - List toRemove = localUsers.stream() +/* List toRemove = qyUserList.stream() .filter(localUser -> !wxUserMap.containsKey(localUser.getUserid())) .collect(Collectors.toList()); - log.info("syncUserInfo toRemove: {}", JSONUtil.toJsonStr(toRemove)); + log.info("syncUserInfo toRemove: {}", JSONUtil.toJsonStr(toRemove));*/ // 识别需要更新的用户 - List toUpdate = localUsers.stream() + List toUpdate = qyUserList.stream() .filter(localUser -> wxUserMap.containsKey(localUser.getUserid())) .filter(localUser -> { UserListResponse.UserInfo wxUser = wxUserMap.get(localUser.getUserid()); @@ -557,12 +553,12 @@ public class QywxScheduleJob { } // 删除用户 - if (!toRemove.isEmpty()) { + /*if (!toRemove.isEmpty()) { BulkOperationCommand command = new BulkOperationCommand<>( toRemove.stream().map(QyUserEntity::getId).collect(Collectors.toList()) ); qyUserApplicationService.deleteUser(command); - } + }*/ } } catch (Exception e) { log.error("syncUserInfo error", e);