Commit Graph

1801 Commits

Author SHA1 Message Date
hailin 9642901710 fix(mining-wallet-service): remove remaining blockchain references
- Remove HOT_WALLET and COLD_WALLET from initializeCoreAccounts
- Remove BLOCKCHAIN from counterpartyType union

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 06:34:46 -08:00
hailin 8e30438433 refactor(mining-wallet-service): remove KAVA blockchain integration
- Remove KavaBlockchainService and blockchain.repository
- Remove BlockchainIntegrationService and BlockchainController
- Update health controller to remove blockchain check
- Clean up Prisma schema (remove blockchain models and enums)
- Add migration to drop blockchain-related tables

This functionality will be re-implemented when needed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 06:31:30 -08:00
hailin 025cc6871b fix(mining-wallet-service): 修复模块依赖注入问题
将 Kafka consumers 从 InfrastructureModule 移到 ApplicationModule,
因为 consumers 依赖 application 层的服务 (ContributionWalletService, SystemAccountService)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 06:20:32 -08:00
hailin 7fe954e563 feat(contribution/wallet): 实现贡献值2.0计算与钱包存储架构
主要变更:
- contribution-service: 添加省市字段到认种同步数据
- contribution-service: 实现分配结果发布服务,通过Outbox模式发布到Kafka
- contribution-service: 更新Outbox调度器,支持4小时最大退避重试
- mining-wallet-service: 添加贡献值消费者,处理分配结果入账
- mining-wallet-service: 添加用户注册消费者,自动创建钱包
- mining-wallet-service: 添加贡献值过期调度器
- mining-wallet-service: 系统账户添加contributionBalance字段

Kafka事件流:
- contribution.distribution.completed: 分配结果事件
- auth.user.registered: 用户注册事件

可靠性保证:
- Outbox模式确保事件可靠发布
- 4小时幂等退避策略(30s,1m,2m,5m,10m,30m,1h,2h,4h)
- Redis+DB双重幂等检查

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 06:13:18 -08:00
hailin 1b8791fe5d fix(contribution-service): 添加 unlockedBonusTiers 字段到同步事件
事件和 API 返回中缺少 unlockedBonusTiers 字段,导致
mining-admin-service 无法正确显示团队奖励解锁状态

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 05:09:01 -08:00
hailin 180e5ad057 feat(mining-admin): 重构算力构成展示,添加解锁状态
- 后端添加 unlockedBonusTiers 字段同步
- 前端算力构成卡片展示层级解锁(L1-15)和团队奖励解锁(3档)状态
- 移除无用的系统运营/省级/市级字段

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 04:59:51 -08:00
hailin 4ca4fc9135 fix(mining-admin-web): 适配planting-ledger后端返回数据格式
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 04:12:22 -08:00
hailin bc191791e8 fix(mining-admin-service): getPlantingLedger从synced_adoptions读取真实数据
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 04:02:28 -08:00
hailin 9a34e9d399 feat(mining-admin-web): 引荐关系改为树形可视化布局
- 仿照1.0 admin-web的树形结构
- 显示引荐人链(向上)、总部节点、当前用户
- 递归展开/收起直推下级
- 圆形+-按钮控制展开

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:55:51 -08:00
hailin c141c3f6cd fix: TypeScript null check for originalUserId
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:50:29 -08:00
hailin 9e9a7364b9 fix(mining-admin-service): 实现getReferralTree返回真实推荐关系数据
- 从synced_referrals和synced_adoptions获取数据
- 实现getAncestors获取向上引荐人链
- 实现getDirectReferrals获取直推下级
- 实现getUserAdoptionStats获取认种统计

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:48:59 -08:00
hailin 2025c6ce36 fix(mining-admin): 用户列表API添加认种统计和推荐人信息
- 后端getUsers添加批量查询认种统计和推荐人信息
- 后端formatUserListItem返回adoption和referral字段
- 前端transformUserOverview映射新字段

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:42:54 -08:00
hailin 3074748d15 fix(mining-admin-web): 修复用户详情数据映射 - 正确映射referral/adoption/team字段
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:37:40 -08:00
hailin 5ad71e2e4b fix(mining-admin-service): 用户列表API添加nickname字段
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:29:38 -08:00
hailin 5cff606e87 feat(mining-admin-service): 完善用户详情API返回字段
- getUserDetail 添加以下字段:
  - nickname: 昵称
  - referral: 推荐人信息 (referrerAccountSequence, referrerNickname, depth)
  - adoption: 认种统计 (personalAdoptionCount, directReferralAdoptions, teamAdoptions)
  - team: 团队统计 (directReferralCount, teamMemberCount)

- 从 synced_referrals 表获取推荐关系
- 从 synced_adoptions 表统计认种数量
- 通过 ancestorPath 计算团队成员和团队认种

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:11:19 -08:00
hailin 7b310c554b fix(migrations): 修复数据库迁移脚本语法
- 移除 IF NOT EXISTS,使用标准 Prisma 迁移格式
- 确保 full-reset 能正确执行迁移

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:07:14 -08:00
hailin 4635fea693 chore(migrations): 添加数据库迁移脚本
- auth-service: 20260112110000_add_nickname_to_synced_legacy_users
  - synced_legacy_users 表添加 nickname 字段

- mining-admin-service: 20260112110000_add_referral_adoption_nickname
  - synced_users 表添加 nickname 字段
  - 创建 synced_referrals 表 (推荐关系)
  - 创建 synced_adoptions 表 (认种记录)
  - 相关索引和外键约束

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:02:55 -08:00
hailin 30b04c6376 feat(sync): 完善 CDC 数据同步 - 添加推荐关系、认种记录和昵称字段
- auth-service:
  - SyncedLegacyUser 表添加 nickname 字段
  - LegacyUserMigratedEvent 添加 nickname 参数
  - CDC consumer 同步 nickname 字段
  - SyncedLegacyUserData 接口添加 nickname

- contribution-service:
  - 新增 ReferralSyncedEvent 事件类
  - 新增 AdoptionSyncedEvent 事件类
  - admin.controller 添加 publish-all APIs:
    - POST /admin/referrals/publish-all
    - POST /admin/adoptions/publish-all

- mining-admin-service:
  - SyncedUser 表添加 nickname 字段
  - 新增 SyncedReferral 表 (推荐关系)
  - 新增 SyncedAdoption 表 (认种记录)
  - handleReferralSynced 处理器
  - handleAdoptionSynced 处理器
  - handleLegacyUserMigrated 处理 nickname

- deploy-mining.sh:
  - full_reset 更新为 14 步
  - Step 13: 发布推荐关系
  - Step 14: 发布认种记录

解决 mining-admin-web 缺少昵称、推荐人、认种数据的问题

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:48:15 -08:00
hailin 11eb1f8a04 fix(postgres): 增加数据库最大连接数到 300
- max_connections: 100 -> 300
- max_replication_slots: 10 -> 20
- max_wal_senders: 10 -> 20

支持更多服务和 Debezium connectors 同时连接

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:29:35 -08:00
hailin a4e1859fd2 fix(debezium): 修复 outbox connector 配置中的数据库凭证
使用实际的用户名和密码替代环境变量占位符,
因为 envsubst 不支持带默认值的变量语法

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:13:07 -08:00
hailin 93c9007045 fix(deploy): 修正 Debezium Connect 默认端口为 8084
docker-compose 中 Debezium Connect 映射到 8084 端口

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:11:19 -08:00
hailin cbdb449533 fix(auth): 修复 LegacyUserCdcConsumer 的 OutboxService 依赖注入
- 在 ApplicationModule 中导出 OutboxService
- 在 InfrastructureModule 中使用 forwardRef 导入 ApplicationModule
- 解决循环依赖问题

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:00:21 -08:00
hailin 4cbdf0b503 fix(auth): 修复 CDC consumer 类型错误
使用 ?? 运算符正确处理可选字段:
- update 使用 undefined 保持字段不变
- create 使用 null 明确设置为空值

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 01:45:10 -08:00
hailin 40745ca580 feat(cdc): 完善 2.0 服务数据聚合到 mining-admin-service
1. deploy-mining.sh:
   - 添加 outbox connectors 配置数组 (auth, contribution, mining, trading, wallet)
   - 添加 register_outbox_connectors() 函数自动注册 Debezium 连接器
   - 添加 outbox-register, outbox-status, outbox-delete 命令
   - full-reset 更新为 12 步,包含注册 outbox connectors 和初始数据发布

2. contribution-service:
   - 添加 ContributionAccountSyncedEvent 事件
   - 添加 POST /admin/contribution-accounts/publish-all API 用于初始全量同步

3. mining-admin-service:
   - 添加 ContributionAccountSynced 事件处理(复用 ContributionAccountUpdated 处理器)
   - 添加 ContributionCalculated 事件处理

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 01:41:46 -08:00
hailin 489966fae9 feat(auth): 新 1.0 用户自动发布事件到 mining-admin-service
- auth-service CDC consumer 在同步新用户时自动发布 LegacyUserMigratedEvent
- 只有 op='c' (create) 的新用户才发布事件,snapshot 由 publish-all API 处理
- deploy-mining.sh full-reset 更新步骤编号为 10 步

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 01:25:01 -08:00
hailin 50854f04d5 fix(deploy): 添加 mining-admin-service-cdc-group 到 CDC 重置列表
确保 full-reset 时同时重置 mining-admin-service 的 consumer group,
使其能从头消费所有 outbox 事件。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 01:18:44 -08:00
hailin 0d06080760 fix(mining-admin): 兼容 Debezium outbox 消息格式
问题:Debezium 产生的 outbox 消息使用下划线命名(event_type,
aggregate_type),而代码期望驼峰格式(eventType, aggregateType)

解决方案:
- isServiceEvent() 同时检查两种命名格式
- 新增 normalizeServiceEvent() 转换 Debezium 格式到驼峰格式
- 解析 payload JSON 字符串

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 01:10:24 -08:00
hailin 273f2f1d96 fix(deploy): 在 migration 后再次重置 CDC offset
问题:migration 会启动容器执行迁移,导致 CDC consumer
自动启动并消费消息。在数据库重建后启动服务时,消息
已经被消费完毕。

解决方案:在 migration 后增加 Step 7,停止容器并
再次重置 CDC offset,确保最终启动时能重新消费。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 00:53:55 -08:00
hailin 350ce28c40 fix(deploy): 修复 sync-reset CDC offset 重置失败问题
- sync_reset() 添加 20 秒等待时间,确保 consumer group 变成 inactive
- 添加重试逻辑(最多 3 次,每次间隔 10 秒)
- 使用 grep NEW-OFFSET 检测 offset reset 是否成功

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 00:49:09 -08:00
hailin 24412794e6 fix(deploy-mining): 修正 full-reset 步骤顺序避免 CDC offset 重置失败
- 在 migration 之前重置 CDC offsets(因为 migration 会启动容器)
- 停止服务后等待 15 秒让 Kafka consumer 变成 inactive
- 添加重试机制,最多重试 3 次,每次间隔 10 秒
- 步骤从 6 步改为 7 步

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 00:33:19 -08:00
hailin ff27195be2 fix(cdc): 修复用户同步字段映射和多 consumer group 重置
contribution-service:
- 修复 UserSyncedHandler 使用错误字段名 (data.id -> data.user_id)
- 兼容 CDC snake_case 字段命名 (user_id, account_sequence, phone_number)
- 添加数据验证,跳过无效记录

deploy-mining.sh:
- 添加 auth-service-cdc-group 到 CDC_CONSUMER_GROUPS
- full-reset 现在重置所有 CDC consumer groups
- sync_reset 和 sync_status 支持多个 consumer groups

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 23:59:39 -08:00
hailin 5cab38c7f1 fix(deploy-mining): 修正 Docker 容器名称和默认凭据
- 修正 POSTGRES_CONTAINER 为 rwa-postgres (匹配 docker-compose.yml)
- 修正 KAFKA_CONTAINER 为 rwa-kafka
- 修正 POSTGRES_USER 为 rwa_user
- 修正 POSTGRES_PASSWORD 为 rwa_secure_password
- 修复 CDC offset 重置命令使用正确的容器名和命令格式

解决 full-reset 无法删除数据库和重置 CDC offset 的问题。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 23:41:49 -08:00
hailin 5c302bfca8 fix(deploy-mining): 支持 Docker 环境的数据库操作和迁移
- 添加 run_psql helper 函数自动检测 Docker 或本地 psql
- 修改 db_create/db_drop/db_status 使用 docker exec
- 修改 db_migrate 支持通过容器运行 prisma migration
- 修改 health_check/show_stats 支持 Docker 环境

解决在服务器 Docker 环境中 full-reset 失败的问题。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 23:38:06 -08:00
hailin 5d880f011e fix(debezium): 统一 mining-wallet-outbox-connector 数据库名称
将 database.dbname 从 mining_wallet_db 改为 rwa_mining_wallet,
与 docker-compose.2.0.yml 和 deploy-mining.sh 保持一致。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 23:31:28 -08:00
hailin 63d73af135 refactor(cdc): 统一使用 Debezium CDC 进行数据同步
1. contribution-service:
   - 添加 identity topic 订阅,全量同步 1.0 用户数据
   - 修改 fromBeginning 为 true,首次启动全量同步

2. mining-admin-service:
   - 将 Outbox 事件改为 Debezium CDC 监听 outbox_events 表
   - 修改 fromBeginning 为 true,首次启动全量同步

3. 新增 5 个 2.0 服务的 Debezium connector 配置:
   - auth-outbox-connector.json
   - contribution-outbox-connector.json
   - mining-outbox-connector.json
   - trading-outbox-connector.json
   - mining-wallet-outbox-connector.json

4. 更新 register-connectors.sh 脚本

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 23:19:34 -08:00
hailin cab36fccf1 fix(docker): 修复 contribution-service 和 mining-admin-service Dockerfile healthcheck 路径
将 healthcheck 路径从 /api/v1/health 改为 /api/v2/health,
与 main.ts 中的 API 前缀保持一致。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 22:56:26 -08:00
hailin 978dfcb2bf feat(docker): 添加 mining-wallet-service 到 docker-compose.2.0.yml
- 添加 mining-wallet-service 服务配置
  - 端口: 3025
  - 数据库: rwa_mining_wallet
  - Redis DB: 15
  - KAVA 区块链配置
- 更新所有服务的 healthcheck 路径为 /api/v2/health
  - mining-service
  - trading-service
  - mining-admin-service

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 22:53:57 -08:00
hailin 83a2800941 refactor(deploy): 移除 mining-admin-web 从 deploy-mining.sh
mining-admin-web 是前端项目,不应该在后端服务部署脚本中管理。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 22:52:26 -08:00
hailin 3c73d510b1 feat(deploy): 添加 mining-wallet-service 到 deploy-mining.sh
将 mining-wallet-service 加入 2.0 系统管理脚本:

- 添加到 MINING_SERVICES 数组
- 添加别名 wallet -> mining-wallet-service
- 添加数据库 rwa_mining_wallet
- 添加 SERVICE_DB 映射
- 添加端口 3025
- 更新帮助文档

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 22:51:19 -08:00
hailin a4090cc285 fix(mining-admin-web): 修复 API rewrite 路径为 v2
将 next.config.js 中的 API rewrite 从 /api/v1 改为 /api/v2,
与 mining-admin-service 的实际 API 前缀保持一致。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 22:45:16 -08:00
hailin f790d2bbe5 refactor(api): 升级 trading-service API 前缀至 v2
将 trading-service 的 API 版本从 v1 升级到 v2,统一 2.0 系统架构:

**trading-service:**
- main.ts: 全局前缀 api/v1 → api/v2
- Dockerfile: 健康检查路径 /api/v1/health → /api/v2/health
- transfer.service.ts: 更新调用 mining-service 的 API 路径
  - /api/v1/mining/accounts/.../transfer-out → /api/v2/...
  - /api/v1/mining/accounts/.../transfer-in → /api/v2/...

此变更使 trading-service 正式成为 2.0 系统的一部分,
与 auth-service、contribution-service、mining-service、
mining-admin-service、mining-wallet-service 保持一致。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 22:37:17 -08:00
hailin 6d619c0a02 refactor(api): 升级 mining-service 和 mining-wallet-service API 前缀至 v2
将以下服务的 API 版本从 v1 升级到 v2,统一 2.0 系统架构:

**mining-service:**
- main.ts: 全局前缀 api/v1 → api/v2
- Dockerfile: 健康检查路径 /api/v1/health → /api/v2/health

**mining-wallet-service:**
- main.ts: 全局前缀 api/v1 → api/v2
- Dockerfile: 健康检查路径 /api/v1/health → /api/v2/health

此变更使 mining-service 和 mining-wallet-service 正式成为 2.0 系统的一部分,
与 auth-service、contribution-service、mining-admin-service 保持一致。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 22:31:06 -08:00
hailin 05f98def6d fix(sync): 修复数据同步 API 认证和响应解析
- 为 contribution/mining/trading 服务的 AdminController 添加 @Public 装饰器
- 修复 initialization.service.ts 中响应格式解析,支持 { data: { ... } } 格式

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 21:47:32 -08:00
hailin 6fedebf020 fix(trading-service): 更新 package-lock.json
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 21:35:33 -08:00
hailin 3fe6bdbbf0 feat(sync): 添加批量同步 API 端点
- 为 contribution-service、mining-service、trading-service 添加 AdminController
- 提供 /admin/accounts/sync 端点用于批量获取账户数据
- 在 mining-admin-service 添加同步 mining/trading 账户的初始化端点
- 添加 sync-all 端点支持一键同步所有数据

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 21:27:35 -08:00
hailin 033f94c0c2 fix(mining-admin-web): 修复 API 响应格式转换
后端返回 records/pagination 格式,前端期望 items/total/totalPages 格式

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 21:14:12 -08:00
hailin 1a7c73e531 feat(mining-admin): 添加用户详情页缺失的 API 端点
- 添加 referral-tree API(返回空推荐关系数据)
- 添加 planting-ledger API(返回空认种数据)
- 添加 wallet-ledger API(返回空钱包流水数据)
- 修复前端 referral-tree 组件空数据处理

注:这些 API 目前返回占位数据,完整数据需要通过 CDC 从各服务同步

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 20:53:18 -08:00
hailin fc3efe6a27 fix(mining-admin-web): 修复 React hydration 错误 #418 #423
- 修改 Zustand sidebar store 使用 skipHydration 避免 SSR 不匹配
- 移除 Redux auth slice 初始状态中的 localStorage 读取
- 在 providers 中使用 useEffect 初始化客户端状态

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 20:47:00 -08:00
hailin dc27044dab fix(mining-admin-web): 修复 formatNumber 导致的 hydration 错误
将 toLocaleString 替换为确定性格式化方法,避免服务器和客户端
输出不一致导致的 React hydration 错误 #418 #423

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 20:37:32 -08:00
hailin e0f529799f fix(mining-admin): 添加 syncAllUsers 和 syncAllContributionAccounts 方法
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 20:24:48 -08:00