Go to file
hailin eaead7d4f3 feat(contribution-service): 添加算力管理微服务
## 概述
为榴莲生态2.0添加 contribution-service 微服务,负责算力计算、分配和快照管理。

## 架构设计
- 采用 DDD + Hexagonal Architecture (六边形架构)
- 使用 NestJS 框架 + Prisma ORM
- 通过 Kafka CDC (Debezium) 从 user-service 同步数据
- 使用 accountSequence (而非 userId) 进行跨服务关联

## 核心功能模块

### 1. Domain Layer (领域层)
- ContributionAccountAggregate: 算力账户聚合根
- ContributionRecordAggregate: 算力记录聚合根
- ContributionAmount: 算力金额值对象 (基于 Decimal.js)
- DistributionRate: 分配比例值对象
- ContributionSourceType: 算力来源类型枚举 (PERSONAL/TEAM_LEVEL/TEAM_BONUS)

### 2. Application Layer (应用层)
- ContributionCalculationService: 算力计算核心服务
  - 个人算力: 认种金额 × 10
  - 团队等级奖励: 基于直推有效认种人数
  - 团队极差奖励: 多级分销算法
- SnapshotService: 每日算力快照服务
- CDC Event Handlers: 处理用户、认种、引荐关系同步事件

### 3. Infrastructure Layer (基础设施层)
- Prisma Repositories:
  - ContributionAccountRepository
  - ContributionRecordRepository
  - SyncedDataRepository (同步数据)
  - OutboxRepository (发件箱模式)
  - SystemAccountRepository
  - UnallocatedContributionRepository
- Kafka CDC Consumer: 消费 Debezium CDC 事件
- Redis: 缓存支持
- UnitOfWork: 事务管理

### 4. API Layer (接口层)
- ContributionController: 算力查询接口
- SnapshotController: 快照管理接口
- HealthController: 健康检查

## 数据模型 (Prisma Schema)
- ContributionAccount: 算力账户
- ContributionRecord: 算力记录 (支持过期)
- DailyContributionSnapshot: 每日快照
- SyncedUser/SyncedAdoption/SyncedReferral: CDC 同步数据
- OutboxEvent: 发件箱事件
- SystemContributionAccount: 系统账户
- UnallocatedContribution: 未分配算力

## TypeScript 类型修复
- 修复所有 Repository 接口与实现的类型不匹配
- 修复 ContributionAmount.multiply() 返回值类型
- 修复 isZero getter vs method 问题
- 修复 bigint vs string 类型转换
- 统一使用 items/total 返回格式
- 修复 Prisma schema 字段名映射 (unallocType, contributionBalance 等)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 17:39:25 -08:00
.claude feat(mobile-app): 增强合同PDF下载可靠性和用户体验 2026-01-09 07:12:21 -08:00
backend feat(contribution-service): 添加算力管理微服务 2026-01-10 17:39:25 -08:00
contracts feat(contracts): add DurianUSDT ERC-20 token contract 2026-01-02 19:02:19 -08:00
docs feat(co-managed-wallet): 添加签名会话API和Service-Party-App HTTP客户端 2025-12-28 22:34:35 -08:00
frontend chore(mobile-app): 更新开屏静态图片 2026-01-09 10:42:53 -08:00
kubernetes . 2025-11-25 10:29:24 +08:00
scripts fix(snapshot): 修改 Services PostgreSQL 用户名为 rwa_user 2026-01-08 09:05:22 -08:00
tests . 2025-11-25 10:29:24 +08:00
.gitignore feat(contribution-service): 添加算力管理微服务 2026-01-10 17:39:25 -08:00
README.md first commit 2025-11-23 21:21:44 -08:00
SEED01-qrcode.png fix: 短信超时返回成功状态避免前端报错 2025-12-21 20:55:31 -08:00
STKAITI.TTF feat(mobile-app): 添加合同签署 API 详细调试日志 2025-12-25 03:14:10 -08:00
contract.docx feat(kyc): 实名认证前检查手机号验证状态 2025-12-24 21:00:53 -08:00
docker-compose.yml first commit 2025-11-23 21:21:44 -08:00
榴莲皇后数据.xlsx fix(mobile-app): 修复多账号切换后账号列表只显示一个的问题 2025-12-27 11:12:50 -08:00
联合种植协议董事长_release_form.pdf fix(reporting-service): add /api/v1 prefix to wallet and reward service API calls 2026-01-04 23:18:10 -08:00

README.md