From b3014744abc269bfd8e76c0101c7c2301edf58c7 Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 25 Dec 2025 07:38:20 -0800 Subject: [PATCH] =?UTF-8?q?fix(identity-service):=20KYC=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E5=90=8E=E5=8F=91=E5=B8=83KYCVerified=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前实名认证成功后只更新数据库,没有发布事件, 导致planting-service无法收到通知来创建合同签署任务。 修改内容: - 注入 EventPublisherService - 查询时增加 accountSequence 字段 - 认证成功后发布 KYCVerifiedEvent 到 identity.KYCVerified topic 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../services/kyc-application.service.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/services/identity-service/src/application/services/kyc-application.service.ts b/backend/services/identity-service/src/application/services/kyc-application.service.ts index 0714bfd6..e4312205 100644 --- a/backend/services/identity-service/src/application/services/kyc-application.service.ts +++ b/backend/services/identity-service/src/application/services/kyc-application.service.ts @@ -9,6 +9,8 @@ import { SmsService } from '@/infrastructure/external/sms/sms.service'; import { StorageService } from '@/infrastructure/external/storage/storage.service'; import { AliyunKycProvider } from '@/infrastructure/external/kyc/aliyun-kyc.provider'; import { ApplicationError } from '@/shared/exceptions/domain.exception'; +import { EventPublisherService } from '@/infrastructure/kafka/event-publisher.service'; +import { KYCVerifiedEvent } from '@/domain/events'; // KYC 综合状态枚举 export enum KycStatus { @@ -39,6 +41,7 @@ export class KycApplicationService { private readonly smsService: SmsService, private readonly storageService: StorageService, private readonly aliyunKycProvider: AliyunKycProvider, + private readonly eventPublisher: EventPublisherService, ) {} /** @@ -233,6 +236,7 @@ export class KycApplicationService { realNameVerified: true, kycStatus: true, phoneNumber: true, + accountSequence: true, }, }); @@ -303,6 +307,21 @@ export class KycApplicationService { this.logger.log(`[KYC] [Level1] Verification SUCCESS for user: ${userId}`); + // 发布 KYCVerified 事件,通知其他服务(如 planting-service) + try { + const verifiedAt = new Date(); + const event = new KYCVerifiedEvent({ + userId, + accountSequence: user.accountSequence, + verifiedAt, + }); + await this.eventPublisher.publish(event); + this.logger.log(`[KYC] [Level1] Published KYCVerified event for user: ${userId}, accountSequence: ${user.accountSequence}`); + } catch (eventError) { + // 事件发布失败不影响 KYC 结果,只记录日志 + this.logger.error(`[KYC] [Level1] Failed to publish KYCVerified event for user: ${userId}`, eventError); + } + return { success: true, level: 1,