hailin
ce9cc5b72e
feat(telemetry): 完整实现 presence-service 迁移 + Flutter 遥测接入
...
## 后端 (backend/services/telemetry-service)
### 修复骨架中的关键缺陷
- 创建本地 JwtAuthGuard / AdminGuard,替换不存在的 @genex/common 包
- 修复 req.user.sub → req.user.id(与 JwtStrategy.validate() 返回值对齐)
- 重写 Dockerfile,移除对不存在的 packages/common 目录的引用
- 更新 telemetry.module.ts,将 JwtAuthGuard / AdminGuard 注册为 providers
- admin-telemetry.controller.ts 改用本地 AdminGuard(检查 role === 'admin')
### 新增功能
- GET /api/v1/telemetry/config:公开配置下发接口
Flutter TelemetryConfig.syncFromRemote() 每小时拉取,返回全局开关、采样率、
心跳间隔等配置,所有字段支持环境变量覆盖(TELEMETRY_GLOBAL_ENABLED 等)
- 设备字段(deviceBrand/deviceModel/deviceOs/appVersion/locale)提升为顶层列
BatchEventsDto / TelemetryEvent 实体 / recordEvents() 全链路补齐
原因:JSONB 内字段无法走 B-tree 索引,千万级数据分组查询需独立列
### DB 迁移
- 050_add_device_fields_to_telemetry_events.sql:为已有 telemetry_events 表
新增 5 个设备字段列和 device_brand / app_version 索引
### docker-compose 环境变量
- telemetry-service 新增 TELEMETRY_GLOBAL_ENABLED / SAMPLING_RATE /
HEARTBEAT_INTERVAL / CONFIG_VERSION 环境变量,支持生产环境热调整
## 前端
### genex-mobile (Flutter 消费者端)
- 复制 lib/core/telemetry/ 模块(11个文件):TelemetryService、
HeartbeatService、SessionManager、TelemetryUploader、TelemetryStorage 等
- 修正 API 路径:presence/heartbeat → telemetry/heartbeat,
analytics/events → telemetry/events
- pubspec.yaml 新增依赖:uuid ^4.3.3、equatable ^2.0.5、device_info_plus ^10.1.0
- main.dart:initState 首帧回调初始化 TelemetryService(需 BuildContext 采集设备信息)
已登录时自动注入 accessToken
- auth_service.dart:_setAuth() 登录成功后注入 userId + accessToken;
_clearAuth() 退出时清除(同时覆盖 Token 过期自动清除场景)
### admin-app (Flutter 发行方控制台)
- 复制 lib/core/telemetry/ 模块(同上)
- pubspec.yaml 新增依赖:uuid、equatable、device_info_plus、shared_preferences
- IssuerLoginPage:initState 首帧初始化 + 登录成功后注入 userId/token
使用 api.gogenex.cn(与 UpdateService 域名一致)
- settings_page.dart:退出登录时调用 clearUserId() + clearAccessToken()
## 架构说明
- 在线人数:Redis Sorted Set (genex:presence:online),心跳 60s/次,180s 窗口判定在线
- DAU:app_session_start 事件写入 telemetry_events,每天凌晨 1 点聚合到
daily_active_stats 表,同时每小时滚动更新当日 DAU
- 设备字段采用 Amplitude 风格:前端本地队列存 properties 内,
toServerJson() 上传时自动提升为顶层字段,后端写入独立索引列
- 心跳需要 JWT 认证(未登录用户自动跳过,不报错)
- 遥测完全异步,任何失败只打 debug 日志,不影响主流程
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-05 23:33:13 -08:00
hailin
fa512dd2eb
fix(auth): JwtStrategy.validate() return id not sub
...
All 6 service strategies were returning { sub } but controllers use req.user.id.
Change return value from { sub: payload.sub } to { id: payload.sub } so that
req.user.id resolves correctly in all protected controllers.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-04 23:52:53 -08:00
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
e8e2d14fbc
fix(health): 修正NestJS服务健康检查URL路径 /health → /api/v1/health
...
NestJS服务注册了全局路由前缀 api/v1,HealthController 实际挂载在
/api/v1/health 而非 /health,导致 Docker HEALTHCHECK 返回 404。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:50:26 -08:00
hailin
c5787020d2
feat(health): 为全部12个微服务添加Docker健康检查
...
## 变更概要
所有后端微服务均增加 Docker HEALTHCHECK 指令,统一通过 GET /health
端点检测服务存活状态。解决 `docker ps` 中13个容器无 (healthy) 状态的问题。
## NestJS 服务 (9个)
- auth-service (:3010), user-service (:3001), issuer-service (:3002),
clearing-service (:3004), compliance-service (:3005), ai-service (:3006),
notification-service (:3008), telemetry-service (:3011), admin-service (:3012)
- 7个服务的 app.module.ts 新增 `import { HealthModule } from '@genex/common'`
注册标准健康检查控制器 (GET /health, /health/ready, /health/live)
- telemetry-service 和 admin-service 已有自建 HealthController,无需导入
- Dockerfile: HEALTHCHECK --interval=30s --start-period=15s --retries=3
## Go 服务 (3个)
- trading-service (:3003), translate-service (:3007), chain-indexer (:3009)
- 已有 /health 端点 (Gin 路由),仅 Dockerfile 添加 HEALTHCHECK
- Dockerfile: HEALTHCHECK --interval=30s --start-period=10s --retries=3
## Kafka Connect
- docker-compose.yml 添加 healthcheck (curl http://localhost:8083/ )
## 健康检查方式
- 所有服务统一使用 `wget --spider http://localhost:PORT/health `
(node:20-alpine 和 alpine:3.19 均自带 BusyBox wget)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:39:25 -08:00
hailin
c42827c6c1
fix(backend): 修复所有服务编译问题 — tsconfig宽松化 + 补全缺失依赖
...
- 所有tsconfig.json: strict改为false, 移除paths映射(改用node_modules解析)
- compliance/clearing/ai/notification: 添加缺失的@nestjs/passport和@nestjs/jwt
- ai-service: 添加缺失的@nestjs/config
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:20:48 -08:00
hailin
d48bd3acb9
feat(docker): 重构Monorepo构建 — 支持@genex/common共享包
...
- docker-compose.yml build context从service目录改为backend根目录
- 所有NestJS Dockerfile改为先构建共享@genex/common包
- 共享包编译后复制到service的node_modules供运行时解析
- 新增backend/.dockerignore减少构建上下文体积
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:00:27 -08:00
hailin
d146bf0a1f
fix(tsconfig): 关闭strictPropertyInitialization以兼容TypeORM实体
...
TypeORM实体使用装饰器定义属性,不在构造函数中初始化。
strict:true隐式启用strictPropertyInitialization导致TS2564编译错误。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 17:48:48 -08:00
hailin
12bb31ede1
fix(docker): 所有NestJS服务Dockerfile使用npm install替代npm ci
...
项目未包含package-lock.json,npm ci要求该文件存在才能运行。
改用npm install确保Docker构建正常完成。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 17:33:31 -08:00
hailin
c11d009ae7
fix: admin-service/telemetry-service Dockerfile 改为多阶段构建
...
修复缺少 builder 阶段导致 COPY dist/ 找不到目录的问题
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 17:29:56 -08:00
hailin
bc0d1e0876
feat: 新增 deploy.sh 部署管理脚本体系 — 后端主控+12服务独立+区块链
...
参照 rwadurian 项目模式,为全栈系统创建统一的 deploy.sh 管理体系:
- backend/deploy.sh: 主控脚本 (up/down/restart/build/build-no-cache/health/infra-*/单服务操作)
- 12个服务独立 deploy.sh (build/rebuild/start/stop/restart/logs/health/shell/test)
- blockchain/deploy.sh: 节点+生态+合约+浏览器+监控全覆盖
- 更新 09-编译部署指南.md 新增第9章 deploy.sh 使用文档
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 17:13:09 -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
e20c321d12
refactor: 遥测与版本管理拆分为独立微服务 (telemetry-service + admin-service)
...
架构重构: 将遥测(Telemetry)和版本管理(App Version)从 user-service 拆分为两个独立微服务,
严格遵循 DDD + Clean Architecture 四层架构。
新增服务:
- telemetry-service (:3011) — 用户心跳检测、事件采集、DAU统计、Prometheus指标
- domain: 3实体 + 3值对象(EventName/InstallId/TimeWindow) + 2领域事件
- infrastructure: Redis(Sorted Set心跳) + Kafka(事件发布) + Prometheus(5指标)
- 定时任务: 每分钟在线快照、每小时清理过期、凌晨DAU精确计算、滚动DAU更新
- admin-service (:3012) — APK/IPA版本管理、OTA更新、MinIO文件存储
- domain: 1实体 + 4值对象(VersionCode/VersionName/FileSha256/DownloadUrl)
- infrastructure: MinIO(文件上传/下载) + APK/IPA解析器
- 移动端: 检查更新API(无认证) + 下载重定向(预签名URL)
- 管理端: 版本CRUD + 上传解析 + 启禁用
user-service 清理:
- 删除24个已迁移文件(4实体+4服务+4基础设施+5控制器+6DTO+1gitkeep)
- 移除不再需要的依赖: @nestjs/schedule, minio, prom-client, kafkajs
- 精简 user.module.ts,仅保留用户核心功能(Profile/KYC/Wallet/Message/Admin)
基础设施更新:
- Kong: 遥测路由 → telemetry-service:3011, 版本路由 → admin-service:3012
- docker-compose: 新增2个服务容器 + MinIO app-releases bucket
- 07开发指南: 更新为独立服务架构描述
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 18:30:39 -08:00