From 43519e6046acbb37b49ab12d8de233a1b017d2bc Mon Sep 17 00:00:00 2001 From: brunoGao Date: Fri, 5 Sep 2025 06:55:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=9B=B4=E6=96=B0=E6=97=B6=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E8=A7=A6=E5=8F=91OrgUnitsChangeListener?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改租户信息时仅同步到sys_org_units表,不发布事件,避免触发 OrgUnitsChangeListener导致重复创建配置而报错。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../impl/TCustomerConfigFacadeImpl.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/facade/impl/TCustomerConfigFacadeImpl.java b/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/facade/impl/TCustomerConfigFacadeImpl.java index 552d794..98572da 100644 --- a/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/facade/impl/TCustomerConfigFacadeImpl.java +++ b/ljwx-boot/ljwx-boot-modules/src/main/java/com/ljwx/modules/customer/facade/impl/TCustomerConfigFacadeImpl.java @@ -131,14 +131,15 @@ public class TCustomerConfigFacadeImpl implements ITCustomerConfigFacade { } /** - * 同步租户配置到 sys_org_units 表并发布事件 + * 同步租户配置到 sys_org_units 表,仅在CREATE操作时发布事件 */ private void syncToSysOrgUnits(Long customerId, String customerName, String operationType) { try { log.info("同步租户配置到sys_org_units: customerId={}, customerName={}, operation={}", customerId, customerName, operationType); - SysOrgUnits orgUnit; + SysOrgUnits orgUnit = null; + boolean shouldPublishEvent = false; if ("DELETE".equals(operationType)) { // 删除操作:标记为删除 @@ -162,8 +163,9 @@ public class TCustomerConfigFacadeImpl implements ITCustomerConfigFacade { .customerId(customerId) .build(); } - } else { - // 新增或更新操作 + shouldPublishEvent = true; // 删除操作需要发布事件 + } else if ("CREATE".equals(operationType)) { + // 新增操作 orgUnit = sysOrgUnitsService.getById(customerId); if (orgUnit == null) { // 创建新的组织单元(顶级租户) @@ -181,20 +183,29 @@ public class TCustomerConfigFacadeImpl implements ITCustomerConfigFacade { .customerId(customerId) .build(); sysOrgUnitsService.save(orgUnit); - } else if (customerName != null && !customerName.equals(orgUnit.getName())) { + shouldPublishEvent = true; // 新增操作需要发布事件 + } + } else if ("UPDATE".equals(operationType)) { + // 更新操作:只同步到sys_org_units,不触发OrgUnitsChangeListener + orgUnit = sysOrgUnitsService.getById(customerId); + if (orgUnit != null && customerName != null && !customerName.equals(orgUnit.getName())) { // 更新组织单元名称 orgUnit.setName(customerName); orgUnit.setDescription("租户: " + customerName); orgUnit.setIsDeleted(0); // 确保不是删除状态 sysOrgUnitsService.updateById(orgUnit); } + // UPDATE操作不发布事件,避免触发OrgUnitsChangeListener + log.info("租户信息更新完成,未发布事件避免触发监听器: customerId={}", customerId); + return; } - // 发布组织变更事件,触发 OrgUnitsChangeListener - SysOrgUnitsChangeEvent event = new SysOrgUnitsChangeEvent(this, orgUnit, operationType); - eventPublisher.publishEvent(event); - - log.info("成功发布组织变更事件: customerId={}, operation={}", customerId, operationType); + // 仅在需要时发布组织变更事件 + if (shouldPublishEvent && orgUnit != null) { + SysOrgUnitsChangeEvent event = new SysOrgUnitsChangeEvent(this, orgUnit, operationType); + eventPublisher.publishEvent(event); + log.info("成功发布组织变更事件: customerId={}, operation={}", customerId, operationType); + } } catch (Exception e) { log.error("同步租户配置到sys_org_units失败: customerId={}, operation={}", customerId, operationType, e);