Commit Graph

4 Commits

Author SHA1 Message Date
hailin 3b733462ce fix(auth): add local JwtStrategy to all services, fix @genex/common import
6 services (user/issuer/clearing/compliance/notification/telemetry) were
missing JwtStrategy provider, causing 'Unknown authentication strategy jwt'
500 errors on all auth-protected endpoints.

- Create infrastructure/strategies/jwt.strategy.ts in each service
- Update each module to import from local path (not @genex/common)
- Revert @genex/common/index.ts strategy export (passport-jwt not in each
  service's node_modules, causes runtime 'Cannot find module' error)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-04 23:00:39 -08:00
hailin 75ed31cc04 fix: 全服务注册 JwtStrategy + 修复微信 WxApi 未配置 crash
**后端**
- packages/common: 新增并导出 JwtStrategy(共享 Passport JWT 策略)
- 6 个服务模块(user/issuer/clearing/compliance/notification/telemetry)
  均缺少 JwtStrategy provider,导致所有受保护接口返回 500
  "Unknown authentication strategy jwt"
- 统一修复:各模块 providers 添加 JwtStrategy

**Flutter**
- welcome_page: _onWechatTap() 的 isWeChatInstalled 调用未设 WECHAT_APP_ID
  时会抛出 PlatformException,catch 后降级为"未安装"提示

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-04 22:24:07 -08:00
hailin acaec56849 feat: 全12服务DDD重构 + 公告定向推送系统 (移植自rwadurian)
## 一、DDD + Clean Architecture 重构 (全12服务)

对全部12个微服务(9 NestJS + 3 Go)实施严格的DDD分层:

### NestJS 服务 (9个):
- auth-service: JWT策略已在domain层
- user-service: 新增 5 个 repository interface + implementation,
  5 个 value objects (Email/Phone/KycLevel/Money), 3 组 domain events
- issuer-service: 新增 5 个 repository interface + implementation,
  3 个 value objects, 2 组 domain events, external AI client port
- clearing-service: 新增 5 个 repository interface + implementation,
  2 个 value objects, domain events
- compliance-service: 新增 7 个 repository interface + implementation,
  2 个 value objects, domain events, audit logger service
- ai-service: 新增 conversation repository + TypeORM entity,
  AI agent client port 移至 domain/ports/
- notification-service: 新增 notification repository interface +
  implementation, channel providers, value objects
- telemetry-service: 新增 3 个 repository interface + implementation
- admin-service: 新增 app-version repository interface + implementation

### Go 服务 (3个):
- trading-service: 重构为 domain/application/infrastructure 分层,
  新增 repository interface + postgres 实现, matching engine 移入
  application/service, 新增 value objects (Price/Quantity/OrderSide/OrderType),
  Kafka event publisher
- translate-service: 新增 repository interface + postgres 实现,
  value objects (Address/ChainType)
- chain-indexer: 新增 repository interface + postgres 实现,
  value objects (BlockHeight/TxHash), Kafka event publisher

### 关键模式:
- NestJS: Symbol token DI (provide: Symbol → useClass: Impl)
- Go: compile-time interface check (var _ Interface = (*Impl)(nil))
- TypeORM entity 保留 domain methods (pragmatic DDD)
- Repository interface 在 domain/, 实现在 infrastructure/persistence/

## 二、公告定向推送系统 (ported from rwadurian)

在 notification-service 中新增 Announcement 公告体系,
支持管理端向全体/标签/指定用户推送消息:

### 数据库:
- 038_create_announcements.sql: 5张新表
  - announcements (公告主表)
  - announcement_tag_targets (标签定向)
  - announcement_user_targets (用户定向)
  - announcement_reads (已读记录)
  - user_tags (用户标签)

### 三种定向模式:
- ALL: 推送给全体用户
- BY_TAG: 按标签筛选用户 (用户标签与公告标签有交集)
- SPECIFIC: 指定用户ID列表

### 新增文件 (15个):
- 5 个 TypeORM entity (Announcement + Read + TagTarget + UserTarget + UserTag)
- 2 个 repository interface (IAnnouncementRepository 11方法, IUserTagRepository 6方法)
- 2 个 repository 实现 (TypeORM QueryBuilder, targeting filter SQL)
- 2 个 application service (AnnouncementService, UserTagService)
- 2 个 DTO 文件 (announcement.dto.ts, user-tag.dto.ts)
- 1 个 controller 文件 (含3个controller: AdminAnnouncement/AdminUserTag/UserAnnouncement)
- 1 个 migration SQL

### API 端点:
管理端:
  POST   /admin/announcements       创建公告(含定向配置)
  GET    /admin/announcements       公告列表
  GET    /admin/announcements/:id   公告详情
  PUT    /admin/announcements/:id   更新公告
  DELETE /admin/announcements/:id   删除公告
  GET    /admin/user-tags           所有标签(含用户数)
  POST   /admin/user-tags/:userId   添加用户标签
  DELETE /admin/user-tags/:userId   移除用户标签
  PUT    /admin/user-tags/:userId/sync  同步用户标签

用户端:
  GET    /announcements             用户公告(按定向过滤+已读状态)
  GET    /announcements/unread-count  未读数
  PUT    /announcements/:id/read    标记已读
  PUT    /announcements/read-all    全部已读

### 设计决策:
- Announcement 与现有 Notification 并存 (双轨):
  Notification = 事件驱动1:1通知, Announcement = 管理端广播/定向
- rwadurian accountSequences → gcx userIds (UUID)
- rwadurian Prisma → gcx TypeORM

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 21:11:24 -08:00
hailin ad93bc728f feat: 完成全部后端微服务开发 (10服务/373文件/15586行代码)
## 架构概览
- 10个微服务: 7 NestJS + 3 Go/Gin
- DDD + Clean Architecture (Domain/Application/Infrastructure/Interface 四层)
- Kong API Gateway (8080) 统一入口
- PostgreSQL + Redis + Kafka(KRaft) + MinIO 基础设施

## 微服务清单
| 服务 | 技术 | 端口 | 职责 |
|------|------|------|------|
| auth-service | NestJS | 3010 | JWT双Token认证(15min+7d)、注册/登录/刷新/登出 |
| user-service | NestJS | 3001 | 用户Profile、KYC审核、钱包(充值/提现)、消息 |
| issuer-service | NestJS | 3002 | 发行方入驻、券CRUD/搜索/购买、定价引擎、信用评分 |
| trading-service | Go/Gin | 3003 | 撮合引擎(价格-时间优先)、订单簿、做市商API |
| clearing-service | NestJS | 3004 | 交易结算、退款、Breakage、ASC 606会计分录 |
| compliance-service | NestJS | 3005 | AML(5模式)、OFAC筛查、Travel Rule、SAR报告 |
| ai-service | NestJS | 3006 | ACL反腐败层→外部AI Agent集群(含本地降级) |
| translate-service | Go/Gin | 3007 | 区块链地址映射翻译 |
| notification-service | NestJS | 3008 | 推送/短信/邮件/站内通知、事件消费 |
| chain-indexer | Go/Gin | 3009 | 区块链索引器(Mock) |

## Admin API (18个管理模块)
覆盖admin-web全部18+页面:
Dashboard、用户管理、系统管理、用户分析、发行方管理、券管理、
券分析、商户核销、交易监控、做市商管理、财务管理、报表中心、
风控中心、合规审计、争议处理、保险理赔、AI Agent面板、通知管理

## 数据库
- 31个SQL迁移 (000-031) + 种子数据
- 乐观锁(@VersionColumn) + 悲观锁(SELECT FOR UPDATE) + Redis分布式锁
- Outbox Pattern保证消息可靠投递 + 24h幂等窗口

## 共享包
- @genex/common: Guards/Decorators/DTOs/Outbox/Health/Locking/AI-Client
- @genex/kafka-client: 生产者/消费者/Topic定义/KRaft集群支持

## 部署与测试
- docker-compose.yml: 全栈一键启动
- Swagger文档: 7个NestJS服务 /docs 端点
- E2E测试脚本: scripts/run-e2e.sh (Auth→Profile→Wallet→Trading→Admin)
- 迁移脚本: scripts/migrate.sh + scripts/test-setup.sh

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 17:09:12 -08:00