Forráskód Böngészése

fix: EnterpriseHandler PENDING为null时新建企业兜底避免NPE

alphaH 1 napja
szülő
commit
83e2962be7

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

@@ -99,12 +99,23 @@ public class EnterpriseHandler extends BaseNotifyHandler {
         if (entity == null) {
             // 通知到达时本地尚未创建 → 先查预登记记录(applyInvite 创建的 PENDING 记录)
             entity = enterpriseMapper.selectByOutBizNoIgnoreTenant(outBizNo);
-            entity.setEnterpriseId(enterpriseId);
-            entity.setOutBizNo(outBizNo);
-            entity.setAccountId(accountId);
-            entity.setStatus(status);
-            entity.setRemark(remark);
-            enterpriseMapper.updateIgnoreTenant(entity);
+            if (entity == null) {
+                // PENDING 也不存在(历史数据),直接新建
+                entity = new EnterpriseEntity();
+                entity.setEnterpriseId(enterpriseId);
+                entity.setOutBizNo(outBizNo);
+                entity.setAccountId(accountId);
+                entity.setStatus(status);
+                entity.setRemark(remark);
+                enterpriseMapper.insert(entity);
+            } else {
+                entity.setEnterpriseId(enterpriseId);
+                entity.setOutBizNo(outBizNo);
+                entity.setAccountId(accountId);
+                entity.setStatus(status);
+                entity.setRemark(remark);
+                enterpriseMapper.updateIgnoreTenant(entity);
+            }
             log.info("通知创建企业记录: enterprise_id={}, status={}, providerId={}", enterpriseId, status, entity.getServiceProviderId());
         } else {
             // 已存在 → 更新状态