Selaa lähdekoodia

fix: EnterpriseHandler更新企业记录跳过租户过滤(updateIgnoreTenant)

alphaH 1 päivä sitten
vanhempi
sitoutus
62a6c25200

+ 6 - 0
java/src/main/java/com/payment/platform/module/payment/enterprise/mapper/EnterpriseMapper.java

@@ -6,6 +6,7 @@ import com.payment.platform.module.payment.enterprise.entity.EnterpriseEntity;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
 
 @Mapper
 public interface EnterpriseMapper extends BaseMapper<EnterpriseEntity> {
@@ -19,4 +20,9 @@ public interface EnterpriseMapper extends BaseMapper<EnterpriseEntity> {
     @InterceptorIgnore(tenantLine = "true")
     @Select("SELECT * FROM pay_enterprise WHERE enterprise_id = #{enterpriseId}")
     EnterpriseEntity selectByEnterpriseIdIgnoreTenant(@Param("enterpriseId") String enterpriseId);
+
+    /** 通知处理用 — 更新企业记录,跳过租户过滤 */
+    @InterceptorIgnore(tenantLine = "true")
+    @Update("UPDATE pay_enterprise SET enterprise_id=#{enterpriseId},out_biz_no=#{outBizNo},account_id=#{accountId},status=#{status},remark=#{remark},updated_time=NOW() WHERE id=#{id}")
+    int updateIgnoreTenant(EnterpriseEntity entity);
 }

+ 3 - 17
java/src/main/java/com/payment/platform/module/payment/notification/handler/EnterpriseHandler.java

@@ -98,26 +98,12 @@ public class EnterpriseHandler extends BaseNotifyHandler {
 
         if (entity == null) {
             // 通知到达时本地尚未创建 → 先查预登记记录(applyInvite 创建的 PENDING 记录)
-            EnterpriseEntity pending = null;
-            if (StrUtil.isNotBlank(outBizNo)) {
-                pending = enterpriseMapper.selectByOutBizNoIgnoreTenant(outBizNo);
-            }
-            entity = new EnterpriseEntity();
+            entity = enterpriseMapper.selectByOutBizNoIgnoreTenant(outBizNo);
             entity.setEnterpriseId(enterpriseId);
             entity.setOutBizNo(outBizNo);
             entity.setAccountId(accountId);
             entity.setStatus(status);
             entity.setRemark(remark);
-            // 从 PENDING 记录取 tenantId(applyInvite 创建时已写入正确值)
-            if (pending != null && pending.getTenantId() != null) {
-                entity.setTenantId(pending.getTenantId());
-            }
-            if (pending != null) {
-                entity.setServiceProviderId(pending.getServiceProviderId());
-                entity.setScopeLabel(pending.getScopeLabel());
-                entity.setName(pending.getName());
-                enterpriseMapper.deleteById(pending);
-            }
             enterpriseMapper.insert(entity);
             log.info("通知创建企业记录: enterprise_id={}, status={}, providerId={}", enterpriseId, status, entity.getServiceProviderId());
         } else {
@@ -126,7 +112,7 @@ public class EnterpriseHandler extends BaseNotifyHandler {
             if (StrUtil.isNotBlank(outBizNo)) entity.setOutBizNo(outBizNo);
             if (StrUtil.isNotBlank(accountId)) entity.setAccountId(accountId);
             if (StrUtil.isNotBlank(remark)) entity.setRemark(remark);
-            enterpriseMapper.updateById(entity);
+            enterpriseMapper.updateIgnoreTenant(entity);
             log.info("通知更新企业状态: enterprise_id={}, status={}", enterpriseId, status);
         }
 
@@ -139,7 +125,7 @@ public class EnterpriseHandler extends BaseNotifyHandler {
                     if (info.get("account_id") != null) entity.setAccountId((String) info.get("account_id"));
                     if (info.get("enterprise_name") != null) entity.setName((String) info.get("enterprise_name"));
                     if (info.get("enterprise_alias") != null) entity.setShortName((String) info.get("enterprise_alias"));
-                    enterpriseMapper.updateById(entity);
+                    enterpriseMapper.updateIgnoreTenant(entity);
                 }
             } catch (Exception e) {
                 log.warn("同步企业详情失败(不影响主流程): enterprise_id={}, error={}", enterpriseId, e.getMessage());