hailin
30a2f739cb
fix(contribution): Dockerfile添加预种Prisma Client生成和migration
...
- builder和runner阶段均添加 prisma generate --schema=prisma/pre-planting/schema.prisma
- start.sh添加预种migration部署步骤
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 20:33:04 -08:00
hailin
8d7fd68509
fix(admin): 预种开关DTO添加class-validator装饰器,修复400错误
...
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 20:26:42 -08:00
hailin
37a5610d74
feat(admin): 实现预种管理页面完整API端点
...
planting-service: InternalPrePlantingController 新增4个管理员查询端点
- GET /internal/pre-planting/admin/orders (分页订单列表)
- GET /internal/pre-planting/admin/positions (分页持仓列表)
- GET /internal/pre-planting/admin/merges (分页合并记录)
- GET /internal/pre-planting/admin/stats (统计汇总)
admin-service: HTTP代理层新增5个端点
- PUT config/toggle (开关切换)
- GET orders/positions/merges/stats (代理转发到planting-service)
- 新建 PrePlantingProxyService (复用ContractService的axios代理模式)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 20:21:31 -08:00
hailin
63a169abb0
fix(cdc): deploy-mining.sh 添加预种CDC connector管理
...
更新 CDC_POSTGRES_CONNECTORS 数组和所有 case 映射(resnapshot、
full-reset topic清理、Step9重注册),确保2.0部署脚本能正确
管理预种CDC connector的生命周期。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 18:58:49 -08:00
hailin
f270b7cc27
fix(cdc): 添加3171预种计划Debezium CDC connector配置
...
预种CDC消费端(contribution-service)代码已就绪,但缺少Debezium
connector配置,导致pre_planting_orders和pre_planting_positions
表变更无法捕获到Kafka,算力无法同步。
新增:
- pre-planting-connector.json: 监听rwa_planting库的pre_planting_*表
独立slot/publication/topic前缀(cdc.pre-planting)
- register-connectors.sh: 注册pre-planting-postgres-connector
- deploy.sh: infra-status显示所有1.0 connector状态
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 18:56:42 -08:00
hailin
cfc03fe523
fix(pricing): 手动调价支持负数降价对冲
...
之前手动调价只允许非负整数,无法用负数对冲降价。
前端 (admin-web settings/page.tsx):
- 移除 input min="0" 限制,允许输入负数
- 验证改为:只校验 isNaN 和总价不低于 0(15831 + amount >= 0)
- 文案:"加价金额" → "调价金额",placeholder 改为"正数涨价,负数降价"
- 实时预览条件从 amount >= 0 改为总价 >= 0
- 提示文案更新为"正数涨价,负数降价对冲"
后端 (admin-service tree-pricing.service.ts):
- 移除 newSupplement < 0 的硬性拒绝
- 改为校验 BASE_PRICE(15831) + newSupplement >= 0,防止总价为负
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 11:58:11 -08:00
hailin
83ba9b7d54
fix(admin-service): 定价DTO添加class-validator装饰器,修复400错误
...
与auth-service支付密码DTO同样的问题:ValidationPipe的
forbidNonWhitelisted:true 导致无装饰器的DTO属性被拒绝。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 10:50:45 -08:00
hailin
81ea35b712
fix(admin-service): 修复预种价格计算公式,3566不是15831/5
...
totalPortionPrice 之前用 Math.floor(totalPrice/5) = 3166,但预种
价格 3566 是各权益项 floor(amount/5) 之和 + 总部吸收余额,不是
简单的整棵价格除以5。
修正为: BASE_PORTION_PRICE(3566) + floor(currentSupplement/5)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 10:48:07 -08:00
hailin
3a307b5db7
fix(planting): 修复认种页面动态定价不生效 + 添加涨价倒计时
...
- 修复 admin-service PublicTreePricingController 路由双重前缀问题
(@Controller('api/v1/tree-pricing') → @Controller('tree-pricing'))
- Kong 网关新增 /api/v1/tree-pricing 路由到 admin-service
- mobile-app 认种页面添加涨价倒计时功能:
显示"距下次涨价还有 X天 X小时 X分钟"及涨价后价格
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 10:22:27 -08:00
hailin
edc81cc55d
fix(trading+mining-app): 修复"全网兑换销毁量"显示为0的问题
...
根因:前端"全网兑换销毁量"读取的是circulationPool(流通池积分股),
但实际应该显示burn_records中source_type=SELL_BURN的销毁总量。
这是两个不同的概念:circulationPool是卖出交易进入流通的积分股,
而兑换销毁量是卖出时被销毁(进入黑洞)的积分股。
修复:
- 后端: BlackHoleRepository添加getTotalSellBurned()聚合查询
- 后端: asset.service.ts市场概览API新增totalSellBurned字段
- 前端: MarketOverview实体/Model新增totalSellBurned字段
- 前端: trading_page销毁明细弹窗改用totalSellBurned显示
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 09:52:10 -08:00
hailin
74f061cfeb
fix(auth-service): 修复支付密码DTO缺少class-validator装饰器导致请求被ValidationPipe拒绝
...
根因:ValidationPipe配置了whitelist+forbidNonWhitelisted,但DTO类的属性
没有任何class-validator装饰器,导致所有请求体属性被当作非白名单属性直接
返回Bad Request,请求根本未到达业务逻辑层。
修复:为SetTradePasswordDto、ChangeTradePasswordDto、VerifyTradePasswordDto
添加@IsString()和@IsNotEmpty()装饰器。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 09:39:14 -08:00
hailin
16da1d20f0
fix(auth): 修复设置支付密码时报错的问题
...
支付密码是6位纯数字,但 setTradePassword 调用了 Password.create()
走了登录密码的格式验证(要求≥8位+字母+数字),导致必然抛出异常。
新增 Password.createWithoutValidation() 方法,仅做 bcrypt hash
不走格式验证。支付密码的格式验证由 trade-password.service.ts 独立处理。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 09:01:33 -08:00
hailin
4a1bf3aafe
fix(trading): 修复已分配积分股显示为0的问题
...
mining-service 返回格式为 { success: true, data: { totalDistributed: "..." } }
但 getTotalMinedFromMiningService() 直接取 result.totalDistributed,
应该取 result.data.totalDistributed。
同时兼容两种格式,优先取 result.data.totalDistributed。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 08:36:38 -08:00
hailin
acf55b26a7
feat(pricing): 预种每份价格从 3171 调整为 3566 绿积分
...
分配规则:按 reward-service RIGHT_AMOUNTS(15831 整棵树)各项 /5 取整,
余额全归总部社区(HQ_BASE_FEE)。5 份合成一棵树 = 17830。
10 类分配金额变更:
- COST_FEE: 576 (不变, floor(2880/5))
- OPERATION_FEE: 420 (不变, floor(2100/5))
- HQ_BASE_FEE: 29.4 → 427 (3566 - 3139, 吸收全部余额)
- RWAD_POOL: 1152 (不变, floor(5760/5))
- SHARE_RIGHT: 720 (不变, floor(3600/5))
- PROVINCE_AREA: 21.6 → 21 (floor(108/5))
- PROVINCE_TEAM: 28.8 → 28 (floor(144/5))
- CITY_AREA: 50.4 → 50 (floor(252/5))
- CITY_TEAM: 57.6 → 57 (floor(288/5))
- COMMUNITY: 115.2 → 115 (floor(576/5))
- 合计: 3171 → 3566 ✓
涉及服务:planting-service, admin-service, contribution-service
涉及前端:admin-web, mobile-app (Flutter)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 08:02:17 -08:00
hailin
5adcd023e6
fix(pricing): 修复 priceSupplement 在 Kafka 事件链中丢失的问题
...
## 问题描述
认种树动态定价涨价功能 (ed6b48562 ) 在 planting-service 的资金分配
中正确计算了 HQ_PRICE_SUPPLEMENT,但 priceSupplement 字段未随
Kafka 事件传递到 reward-service,导致 reward-service 的
calculateHqPriceSupplement 永远收到 priceSupplement=0,涨价部分
的总部奖励分配不会执行。
## 事件链路径 (修复前 → 修复后)
planting-service (contract-signing.service.ts)
↓ contract.signed / contract.expired
↓ 修复前: 不含 priceSupplement ❌
↓ 修复后: 携带 order.priceSupplement ✅
referral-service (contract-signing.handler.ts)
↓ planting.order.paid / planting.order.expired
↓ 修复前: 不含 priceSupplement ❌
↓ 修复后: 透传 eventData.priceSupplement || 0 ✅
reward-service (event-consumer.controller.ts)
↓ calculateHqPriceSupplement(priceSupplement)
↓ 修复前: 始终为 0,不分配 ❌
↓ 修复后: 收到实际值,正确分配给 S0000000001 ✅
## 修改文件
1. planting-service/src/infrastructure/kafka/event-publisher.service.ts
- ContractSigningEventData 接口新增 priceSupplement?: number 字段
2. planting-service/src/application/services/contract-signing.service.ts
- signContract(): publishContractSigned 时传递 order.priceSupplement
- handleExpiredTasks(): publishContractExpired 时传递 order.priceSupplement
3. referral-service/src/application/event-handlers/contract-signing.handler.ts
- ContractSigningEvent 接口新增 priceSupplement?: number 字段
- publishOrderPaidEvent(): 透传 priceSupplement 到 planting.order.paid
- publishOrderExpiredEvent(): 透传 priceSupplement 到 planting.order.expired
## 向后兼容
- priceSupplement 为可选字段 (?: number),默认 fallback 为 0
- 已存在的订单 priceSupplement=0,不影响现有分配逻辑
- reward-service event-consumer 已有 || 0 fallback 保护
## 验证方法
1. 设置 supplement > 0 后创建认种订单
2. 签署合同后检查 reward-service 日志是否有 HQ_PRICE_SUPPLEMENT 分配记录
3. 检查总部账户 S0000000001 是否收到 priceSupplement * treeCount 的入账
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 07:13:01 -08:00
hailin
ed6b48562a
feat(pricing): 认种树动态定价涨价系统(总部运营成本压力涨价)
...
基础价 15831 USDT/棵不变,新增 HQ_PRICE_SUPPLEMENT 加价项全额归总部(S0000000001)。
支持手动调价+自动周期涨价,所有变更可审计,移动端动态展示价格及涨价预告。
- admin-service: TreePricingConfig/ChangeLog 表 + Service + Controller + 定时任务
- planting-service: 正式认种和预种订单快照 priceSupplement,动态价格校验
- reward-service: HQ_PRICE_SUPPLEMENT 分配类型,涨价金额直接入总部账户
- admin-web: Settings 页面新增定价配置区间(手动调价/自动涨价/变更历史)
- mobile-app: TreePricingService + 动态价格加载 + 涨价预告展示
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 03:02:56 -08:00
hailin
023d71ac33
feat(authorization): 提高省团队权益初始激活门槛至3000棵
...
省团队(AUTH_PROVINCE_COMPANY)初始激活门槛: 500棵 → 3000棵
当前各角色初始激活门槛汇总:
- 社区(COMMUNITY): 100棵(上次已调整: 10→100)
- 市团队(AUTH_CITY_COMPANY): 500棵(上次已调整: 100→500)
- 省团队(AUTH_PROVINCE_COMPANY): 3000棵(本次调整: 500→3000)
- 市区域(CITY_COMPANY): 10000棵(未变)
- 省区域(PROVINCE_COMPANY): 50000棵(未变)
变更说明:
- 仅调整初始激活门槛,月度阶梯考核目标不变
- 已激活用户不受影响(祖父条款),仅对新申请的授权生效
- 数据库已有记录的 initialTargetTreeCount 保持旧值不变
- 需在服务器重新部署 authorization-service 后生效
修改文件:
- assessment-config.vo.ts: 核心门槛配置 500→3000
- authorization-application.service.ts: AUTH_PROVINCE_TARGET 常量及注释同步
- authorization.dto.ts: DTO 注释同步
- authorization.response.ts: ApiProperty 注释同步
- DEVELOPMENT_GUIDE.md: 文档说明同步
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 01:44:02 -08:00
hailin
eacdfddff8
feat(authorization): 提高社区和市团队权益初始激活门槛
...
社区初始激活门槛: 10棵 → 100棵
市团队初始激活门槛: 100棵 → 500棵
变更说明:
- 仅调整初始激活门槛,月度考核目标不变(社区仍为10棵/月,市团队仍为100棵/月)
- 已激活用户不受影响(祖父条款),仅对新申请的授权生效
- 激活逻辑通过 AssessmentConfig 工厂方法动态获取门槛值,无需修改业务代码
- 数据库已有记录的 initialTargetTreeCount 保持旧值不变
修改文件:
- assessment-config.vo.ts: 核心门槛配置
- authorization-application.service.ts: 同步注释
- authorization-role.aggregate.spec.ts: 同步测试断言
- DEVELOPMENT_GUIDE.md: 同步文档描述
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 22:55:22 -08:00
hailin
a5a69645b4
fix(trading): 流通池改为显示已挖矿产出总量,解决显示为0的问题
...
前端"流通池"原来读取 circulationPool(交易流通池),因系统尚无卖出交易故为 0。
现改为读取 totalMined(全网已挖矿产出的积分股总量 = 用户已挖 + 系统已挖)。
后端新增 getTotalMinedFromMiningService() 方法,调用 mining-service 的
GET /mining/progress 接口获取 totalDistributed。
注意:价格公式中的 circulationPool 保持不变,仍用交易流通池参与计算。
新增的 totalMined 字段仅用于前端展示。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 02:54:26 -08:00
hailin
27db2a5aa2
fix(snapshot): 修复备份进行中被删除导致容器崩溃的问题
...
1. checkDone 中 statSync 加 try-catch,文件被删时 reject 而非 uncaught crash
2. 删除 API 禁止删除 RUNNING 状态的任务,返回 409 Conflict
3. compose 补充 restart: unless-stopped,防止异常退出后服务不可用
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 01:30:44 -08:00
hailin
716b37041e
fix(snapshot): PG_HOST 改用容器名 rwa-postgres 避免跨网络 DNS 冲突
...
snapshot-service 同时在 rwa-network 和 mpc-network 中,
服务名 "postgres" 在两个网络都存在导致解析到 mpc-postgres。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 04:02:01 -08:00
hailin
b6fb421316
feat(snapshot): 新增 MPC PostgreSQL 备份目标
...
MPC 系统使用独立的 PostgreSQL 实例 (mpc-postgres),之前不在备份范围内。
新增 MPC_POSTGRES handler,通过 MPC_PG_* 环境变量连接,snapshot-service
加入 mpc-network 实现跨 compose 网络访问。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 03:12:16 -08:00
hailin
08161c64d4
fix(snapshot): API 响应补上 progressMsg 字段
...
toSnapshotResponse 手动映射字段时遗漏了 progressMsg,
导致前端轮询拿不到 MB 进度消息。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 02:11:42 -08:00
hailin
8855491637
feat(snapshot): 进度精度升级 — Float百分比 + MB消息存DB
...
- schema: progress Int→Float,新增 progressMsg 字段
- PG handler: 百分比保留2位小数(toFixed(2)),不再 Math.floor
- orchestrator: 每2秒写DB时同时写 progressMsg (含MB信息)
- 前端: 百分比显示 toFixed(1),message 优先读 progressMsg
效果: 113GB库每次轮询进度条和MB数都有变化,不再卡在整数百分比
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 01:57:47 -08:00
hailin
9cbc0ba580
fix(snapshot): DATABASE_URL 改绝对路径,修复 SQLite 每次重建丢数据
...
Prisma 的 file:./data/snapshot.db 相对于 schema.prisma 所在目录
(/app/prisma/),实际创建在 /app/prisma/data/snapshot.db,不在
volume 挂载的 /app/data/ 下,导致容器重建后数据丢失。
改为 file:/app/data/snapshot.db 绝对路径,确保 SQLite 存入
volume 挂载目录,数据跨容器持久化。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 01:48:24 -08:00
hailin
7b7bfcac93
fix(snapshot): onModuleInit 增加扫描临时目录清理孤儿文件
...
SQLite 可能因重建丢失任务记录,导致 onModuleInit 仅靠查数据库
无法清理遗留的临时目录。新增逻辑:启动时扫描临时目录所有子目录,
若数据库中不存在对应任务则直接删除。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 01:45:24 -08:00
hailin
669a8a7248
fix(snapshot): 进度写 DB 改为每 2 秒一次,避免前端长时间显示 0%
...
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 01:40:32 -08:00
hailin
f14f685ea9
fix(snapshot): PG 进度改字节百分比 + Redis 备份防崩溃 + 启动清理遗留任务
...
- postgres-backup: 用 pg_database_size 做分母,统计 stdout 字节数算进度(与 pv 方案一致)
- redis-backup: BGSAVE 后先 copyFileSync 到临时目录再打包,防止 tar-stream Size mismatch 崩溃
- orchestrator: onModuleInit 清理遗留 RUNNING 任务,标记 FAILED 并删除临时文件
- docker-compose: 临时文件改挂宿主机 /tmp 目录,方便手动清理
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 01:30:52 -08:00
hailin
ee94f1420d
fix(snapshot): 前端 API 改走 Next.js rewrites 代理 + WebSocket 改 REST 轮询
...
- snapshot.api.ts: 从直连 localhost:port 改为 /api/snapshots/* 走 Next.js 代理
- next.config: 两个前端都添加 /api/snapshots/:path* → snapshot-service 代理规则
- docker-compose.2.0-snapshot.yml: overlay 中追加 mining-admin-web 的 SNAPSHOT_SERVICE_URL
- useSnapshotWebSocket → useSnapshotPolling: 2秒轮询 GET /snapshots/:id 获取进度
- 移除 socket.io-client 依赖(Next.js standalone 不支持 WebSocket proxy)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 00:37:41 -08:00
hailin
9a88fb473a
fix(snapshot): Dockerfile 安装 postgresql-client-16 匹配目标 PG 版本
...
bookworm 默认 postgresql-client 是 15,目标数据库是 PG16
添加 PGDG 源安装 postgresql-client-16
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 23:20:45 -08:00
hailin
470dc1ccd0
fix(snapshot): PostgreSQL 备份从 pg_basebackup 改为 pg_dumpall
...
pg_basebackup -D - -Ft -z 在 PG15 中不支持同时 WAL streaming
改用 pg_dumpall | gzip 逻辑备份,更轻量且不需要 replication 权限
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 23:18:52 -08:00
hailin
a4689d5e8b
fix(snapshot): 修复 listSnapshots 分页参数 NaN 问题
...
NestJS @Query() 返回 string,需手动 parseInt 再传给 Prisma
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 23:15:26 -08:00
hailin
b8b4305ea5
fix(snapshot): Dockerfile 添加 ca-certificates 修复 mc 下载 SSL 错误
...
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 23:11:07 -08:00
hailin
685aced4e4
fix(snapshot): 修复 6 个 TypeScript 严格模式编译错误
...
- infrastructure.module: handler union type 修正
- minio-storage.adapter: obj.name 可选属性安全检查
- minio-backup.handler: listAllObjects 返回 string[] 避免 BucketItem.name 可选问题
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 23:10:08 -08:00
hailin
18c9f8b389
chore(snapshot): 添加 snapshot-service package-lock.json
...
Docker build 的 npm ci 需要 lock 文件。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 23:06:42 -08:00
hailin
cf07eb03be
feat(snapshot): 数据快照备份服务全量实现(纯新增,零侵入)
...
一套代码两处部署的在线备份编排服务,为 1.0 认种分配系统和 2.0 算力挖矿系统
分别提供 PostgreSQL / Redis / Kafka / ZooKeeper / MinIO / Uploads 的在线备份能力。
管理员在 admin-web / mining-admin-web 中选择备份目标和存储方式,点击备份后系统
串行执行各组件备份,通过 Socket.IO WebSocket 实时推送进度到前端。
## 后端 snapshot-service(NestJS 10 + Prisma 5 + SQLite)
架构: DDD 四层(api / application / domain / infrastructure)
- api 层:
· SnapshotController — REST API(创建/查询/删除/下载)含 Range/206 断点续传
· SnapshotGateway — Socket.IO WebSocket 实时推送 5 类事件
· HealthController — 健康检查
· CreateSnapshotDto — class-validator 验证
· toSnapshotResponse — BigInt→string 序列化
- application 层:
· SnapshotOrchestratorService — 核心编排引擎
- startSnapshot() 异步启动,不阻塞 HTTP
- 按 PG→Redis→Kafka→ZK→MinIO→Uploads 顺序串行执行
- 单目标失败不中断整体任务
- MinIO 模式: 备份完上传到 MinIO 后删除本地临时文件
- LOCAL 模式: 保留在服务器临时目录供下载
- @Cron(EVERY_HOUR) 自动清理过期本地备份(默认 72h)
- runningTaskId 防止并发执行
- domain 层:
· BackupTarget 枚举(6 种目标)+ BACKUP_TARGET_ORDER 执行顺序
· SnapshotStatus 枚举(PENDING/RUNNING/COMPLETED/FAILED)
· StorageType 枚举(MINIO/LOCAL)
· BackupHandler 接口 + BACKUP_HANDLER_TOKEN
- infrastructure 层:
· 6 个备份 Handler(均实现 BackupHandler 接口):
- PostgresBackupHandler: pg_basebackup 通过网络流式备份,解析 stderr 进度
- RedisBackupHandler: BGSAVE + LASTSAVE 轮询 + 打包 dump.rdb/AOF
- KafkaBackupHandler: archiver 打包数据卷,按字节计算进度
- ZookeeperBackupHandler: archiver 打包 data/ + log/
- MinioBackupHandler: SDK 列举并下载所有桶(排除备份桶)后打包
- UploadsBackupHandler: archiver 打包上传文件目录
· 2 个存储适配器:
- MinioStorageAdapter: fPutObject 上传 / removeObjects 批量删除
- LocalStorageAdapter: 本地临时目录管理 + 过期清理
· PrismaService (SQLite) + SnapshotRepository (完整 CRUD)
· BACKUP_HANDLER_TOKEN 工厂: 根据 AVAILABLE_TARGETS 环境变量过滤可用 handler
- Prisma Schema (SQLite):
· SnapshotTask: 主表,targets 存 JSON 字符串,totalSize 用 BigInt
· SnapshotDetail: 明细表,每个目标一行,@@index([taskId])
· onDelete: Cascade 级联删除
- Dockerfile: 多阶段构建,生产镜像安装 postgresql-client + mc (MinIO CLI)
SQLite 使用 prisma db push 而非 migrate deploy
- 部署端口: 1.0 系统 = 3099,2.0 系统 = 3199
## Docker Compose overlay(纯新增,不修改现有 docker-compose)
- docker-compose.snapshot.yml (1.0):
· 挂载 redis_data/kafka_data/zookeeper_data/zookeeper_log/admin_uploads_data 只读卷
· AVAILABLE_TARGETS=POSTGRES,REDIS,KAFKA,ZOOKEEPER,MINIO,UPLOADS
· 依赖 postgres + redis 健康检查
- docker-compose.2.0-snapshot.yml (2.0 standalone):
· 挂载 redis_2_data/mining-admin-uploads/trading-uploads 只读卷
· AVAILABLE_TARGETS=POSTGRES,REDIS,UPLOADS
· 依赖 postgres-2 + redis-2 健康检查
## 前端 admin-web(Next.js 15 + SCSS)
- 新增 /snapshots 页面: 创建备份表单 + 实时进度条 + 历史列表 + 下载/删除
- 新增 useSnapshotWebSocket hook: Socket.IO 连接 + 5 类事件监听
- 新增 snapshot.api.ts: 独立 fetch(不走通用 apiClient,snapshot 服务独立端口)
- 新增 snapshot.types.ts: 共享类型定义
- 新增 page.module.scss: 表单/进度条/表格样式
- 修改 Sidebar.tsx: 添加「数据快照」菜单项
- package.json: 添加 socket.io-client 依赖
## 前端 mining-admin-web(Next.js 14 + Tailwind CSS)
- 新增 /snapshots 页面: 同 admin-web 功能,Tailwind CSS 风格
- 新增 useSnapshotWebSocket hook
- 新增 snapshot.api.ts + snapshot.types.ts
- 修改 sidebar.tsx: 添加「数据快照」菜单项 + HardDrive 图标
- package.json: 添加 socket.io-client 依赖
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 21:53:09 -08:00
hailin
a11e4d0261
fix(pre-planting): 修复 5 个预种模块 Bug + 补全 3 服务 migration
...
Bug #1 (HIGH): allocateFunds 从 Prisma 事务内移到事务外
- pre-planting-reward.service.ts: distributeRewards 拆为
prepareAndPersistRewards(事务内持久化)+ executeAllocations(事务后转账)
- pre-planting-application.service.ts: 事务后调用 executeAllocations
Bug #2 (HIGH): signContract 后触发 hasPlanted
- 签约事务成功后发布 PlantingOrderPaid 到 planting-events topic
- wallet-service 消费后执行 markUserAsPlanted + settleUserPendingRewards
- event-publisher.service.ts: 新增 publishRawToPlantingEvents 方法
Bug #3 (MEDIUM): PENDING 推荐奖励改为全部 SETTLED
- 与现有认种行为对齐,推荐奖励立即发放
Bug #4 (HIGH): 补全 3 个服务的数据库迁移文件
- planting-service: 4 张预种表(orders/positions/merges/reward_entries)
- admin-service: 1 张配置表(pre_planting_configs)+ 默认数据
- contribution-service: 4 张 CDC 追踪表(synced_orders/positions/freeze_states/processed_cdc_events)
Bug #5 (LOW): 合并循环 if→while,支持一次购买多份触发多次合并
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 18:09:14 -08:00
hailin
b3a3652f21
feat(transfer): 树转让功能全量实现(纯新增,零侵入)
...
实现已认种果树所有权在用户间转让的完整功能。采用方案一:
独立 transfer-service 微服务 + Saga 编排器模式。
=== 架构设计 ===
- Saga 编排器 8 步正向流程:卖方确认 → 冻结资金 → 锁定树 →
变更所有权 → 调整算力 → 更新统计 → 结算资金 → 完成
- 补偿回滚:任一步骤失败自动反向补偿(解冻资金 → 解锁树)
- 13 种状态:PENDING → SELLER_CONFIRMED → PAYMENT_FROZEN →
TREES_LOCKED → OWNERSHIP_TRANSFERRED → CONTRIBUTION_ADJUSTED →
STATS_UPDATED → PAYMENT_SETTLED → COMPLETED / CANCELLED /
FAILED / ROLLING_BACK / ROLLED_BACK
=== Phase 1-2: transfer-service(独立微服务) ===
新建文件:
- Prisma Schema:transfer_orders + transfer_status_logs + outbox_events
- Domain:TransferOrder 聚合根 + TransferFeeService(5% 手续费)
- Application:TransferApplicationService + SagaOrchestratorService
- Infrastructure:Kafka 事件消费/生产 + Outbox Pattern
- API:TransferController(用户端)+ AdminTransferController(管理端)
- External Clients:wallet/planting/identity-service HTTP 客户端
- Docker + 环境配置
=== Phase 3: 现有微服务扩展(纯追加) ===
planting-service:
- Prisma schema 追加 transferLockId 可空字段
- InternalTransferController:锁定/解锁/执行 3 个新端点
- Kafka handlers:transfer-lock/execute/rollback 事件处理
- main.ts 追加 Kafka consumer group 配置
referral-service:
- PlantingTransferredHandler:处理转让后团队统计更新
- TeamStatisticsAggregate 追加 handleTransfer() 方法
- TeamStatisticsRepository 追加 adjustForTransfer() 方法
- ProvinceCityDistribution 追加 transferTrees() 方法
contribution-service:
- TransferOwnershipHandler:处理所有权变更事件
- TransferAdjustmentService:算力调整(879 行核心逻辑)
- Prisma schema 追加 transferOrderId 可空字段
- ContributionAccount 追加 applyTransferAdjustment() 方法
=== Phase 4A: wallet-service(3 个新内部端点) ===
新建文件:
- FreezeForTransferDto / UnfreezeForTransferDto / SettleTransferDto
- FreezeForTransferCommand / UnfreezeForTransferCommand / SettleTransferPaymentCommand
- InternalTransferWalletController(POST freeze/unfreeze/settle-transfer)
修改文件:
- wallet-application.service.ts 追加 3 组方法(+437 行):
freezeForTransfer / unfreezeForTransfer / settleTransferPayment
(乐观锁 + 3 次重试 + Prisma $transaction + 幂等检查)
- 结算操作:单事务内更新 3 个钱包(买方扣减 + 卖方入账 + 手续费归集)
=== Phase 4B: admin-web(转让管理页面) ===
新建文件:
- transferService.ts:API 调用服务 + 完整类型定义
- useTransfers.ts:React Query hooks(list/detail/stats/forceCancel)
- /transfers/page.tsx:列表页(统计卡片 + 搜索筛选 + 分页 + 13 种状态 badge)
- /transfers/[transferOrderNo]/page.tsx:详情页(Saga 时间线 + 状态日志 + 强制取消)
- transfers.module.scss:完整样式
修改文件:
- endpoints.ts 追加 TRANSFERS 端点配置
- Sidebar.tsx 追加「转让管理」菜单项
- hooks/index.ts 追加 useTransfers 导出
=== Phase 4C: mobile-app(转让 UI) ===
新建文件:
- transfer_service.dart:Flutter API 服务 + Model(TransferOrder/Detail/StatusLog)
- transfer_list_page.dart:转让记录列表(全部/转出/转入 Tab + 下拉刷新)
- transfer_detail_page.dart:转让详情(Saga 时间线 + 确认/取消操作)
- transfer_initiate_page.dart:发起转让表单(手续费自动计算)
修改文件:
- injection_container.dart 追加 transferServiceProvider
- route_paths.dart + route_names.dart 追加 3 个路由
- app_router.dart 追加 3 个 GoRoute
- profile_page.dart 追加「发起转让」+「转让记录」按钮行
=== 基础设施 ===
- docker-compose.yml 追加 transfer-service 容器配置
- deploy.sh 追加 transfer-service 部署
- init-databases.sh 追加 transfer_db 数据库初始化
=== 纯新增原则 ===
所有变更均为追加式修改,不修改任何现有业务逻辑:
- 新增 nullable 字段(不影响现有数据)
- 新增 enum 值(不影响现有枚举使用)
- 新增 providers/controllers(不影响现有依赖注入)
- 新增页面/路由(不影响现有页面行为)
回滚方式:删除 transfer-service 目录 + 移除各服务中带 [2026-02-19] 标记的代码
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 03:44:02 -08:00
hailin
e1cd8ed7f2
feat(pre-planting): 3171 预种计划 2.0 算力集成(contribution-service CDC 模块)
...
Phase 5:将预种数据集成到 contribution-service 2.0 算力体系。
=== 新增文件(11 个) ===
- prisma/pre-planting/schema.prisma:独立 Prisma schema(4 张追踪表)
- PrePlantingPrismaService + Module:独立 PrismaClient
- PrePlantingCdcConsumerService:独立 CDC 消费者(consumer group: contribution-pre-planting-cdc)
- PrePlantingOrderSyncedHandler:订单 CDC handler + synced_adoptions marker 插入
- PrePlantingPositionSyncedHandler:持仓 CDC handler
- PrePlantingCdcDispatcher:CDC 事件分发器
- PrePlantingContributionService:1/5 算力计算(复用领域计算器)
- PrePlantingFreezeScheduler:每日冻结/解冻调度(凌晨 5 点)
- PrePlantingCdcModule:模块注册
- constants.ts:10B 偏移量、冻结期限等常量
=== 隔离保证 ===
- 独立 Kafka consumer group(contribution-pre-planting-cdc)
- 独立 CDC topics(cdc.pre-planting.public.*)
- 独立 Prisma schema + generated client
- sourceAdoptionId 使用 10,000,000,000 偏移避免 ID 冲突
- synced_adoptions marker: contributionDistributed=true + treeCount=0
- 不更新 NetworkAdoptionProgress(预种不推高全网算力系数)
- 现有代码文件零修改(仅 app.module.ts 加 1 行 import)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 05:25:14 -08:00
hailin
010b0392fd
feat(pre-planting): 3171 预种计划 1.0 全量实现(纯新增,零侵入)
...
预种计划(拼种团购):用户以 3171 USDT/份参与认种(1棵树的1/5价格),
累计5份自动合成1棵树,触发合同签署并解除交易/提现限制。
涉及服务(现有代码仅 app.module.ts 加 1 行 import,其余全部为新增文件):
- planting-service: PrePlantingModule(独立聚合根、购买/合并/签约/分配)
- admin-service: 预种开关管理(PrePlantingConfig 表 + API)
- referral-service: PrePlantingStatsModule(消费预种事件更新团队统计)
- authorization-service: PrePlantingGuardModule(未合并不可申请授权)
- wallet-service: PrePlantingGuardModule(未合并不可提现)
新增数据表:pre_planting_orders, pre_planting_positions,
pre_planting_merges, pre_planting_reward_entries, pre_planting_configs
新增 Kafka Topics:pre-planting.portion.purchased, pre-planting.merged,
pre-planting.contract.signed
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 05:06:03 -08:00
hailin
875f86c263
fix(reporting): 修复 contract.signed 事件 BigInt(undefined) 错误
...
根因:planting-service 发送的 contract.signed 消息为嵌套结构
{ eventName: 'contract.signed', data: { orderNo, userId, ... } }
但 reporting-service handleContractSigned 按扁平结构解析
message.userId → undefined → BigInt(undefined) → TypeError
导致 ~200 次/10分钟持续报错。
修复:
- 消息类型改为匹配实际嵌套格式 { eventName, data: { ... } }
- 解构 message.data 后再访问各字段
- 添加 userId 防御性检查,避免再次 BigInt 崩溃
- 与 referral-service ContractSigningHandler 消息结构保持一致
影响范围:仅 reporting-service 活动记录,不影响核心业务流程
(referral-service / reward-service 已正确处理嵌套格式)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 07:59:16 -08:00
hailin
2a725af83e
fix: Debezium CDC 全面安全加固 (1.0 + 2.0)
...
问题背景:
- 1.0 生产环境发现 6 个孤儿 replication slot, WAL 积压 8.6GB (已清理)
- 1.0 使用 Debezium 2.4, 存在 DBZ-7316 (WAL 无限积压) bug
- 1.0 和 2.0 均无 max_slot_wal_keep_size 安全阀 (已在线设置 10GB)
- 2.0 outbox connector 使用 pg_logical_emit_message 心跳, 不经 publication
- 2.0 outbox connector RegexRouter regex=".*" 导致 heartbeat 污染消费者
修复内容:
[docker-compose.yml - 1.0 基础设施]
- Debezium: 2.4 → 2.5.4.Final (修复 DBZ-7316)
- PostgreSQL: 添加 max_slot_wal_keep_size=10GB
- Debezium REST API: 端口绑定 127.0.0.1 (防 SSRF 注入)
- PostgreSQL: 端口绑定 127.0.0.1 (防公网直连)
- Kafka Connect: 添加 OFFSET_FLUSH_INTERVAL_MS=10s
[docker-compose.2.0.yml - 2.0 基础设施]
- Debezium: 2.5 → 2.5.4.Final (锁定精确版本)
- PostgreSQL: 添加 max_slot_wal_keep_size=10GB
- Kafka Connect: 添加 OFFSET_FLUSH_INTERVAL_MS=10s
[1.0 Connector 配置 - identity/authorization]
- 添加 heartbeat.action.query (INSERT INTO debezium_heartbeat TABLE 方式)
- 之前只有 heartbeat.interval.ms 无 action.query, 心跳不生效
[2.0 Outbox Connector 配置 - 5个全部更新]
- heartbeat: pg_logical_emit_message → INSERT INTO debezium_heartbeat TABLE 方式
(TABLE 方式经过 publication → Debezium 消费 → 推进 confirmed_flush_lsn)
- RegexRouter: regex ".*" → ".*outbox_events" (只路由 outbox 事件, heartbeat 走默认 topic)
- table.include.list: 添加 debezium_heartbeat (确保心跳变更生成 Kafka 消息)
- publication.autocreate.mode: filtered → disabled (使用预创建的 publication)
- auth/contribution: 添加 signal channel 配置 (支持增量快照数据重放)
经验总结:
1. pg_logical_emit_message 写 WAL 但不经 publication, 无法推进 confirmed_flush_lsn
2. RegexRouter regex=".*" 把所有变更(含 heartbeat)路由到 outbox topic, 污染消费者
3. 删除 Kafka Connect connector 不会自动清理 PostgreSQL replication slot
4. max_slot_wal_keep_size 是 sighup 级参数, 可在线 ALTER SYSTEM + pg_reload_conf
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 07:32:13 -08:00
hailin
54eb472faa
fix(debezium): 添加 heartbeat.action.query 防止 WAL 无限积压
...
问题根因:
- 5个 Debezium outbox connector 配置了 heartbeat.interval.ms=10000
但缺少 heartbeat.action.query,导致低写入频率的数据库
(auth/contribution/mining-wallet) 无法向 PostgreSQL 回传
confirmed_flush_lsn 确认位点
- PostgreSQL 无法回收旧 WAL,磁盘占用持续增长至 293GB
修复方案 (参考 Debezium 创始人 Gunnar Morling 推荐):
- 使用 pg_logical_emit_message() 代替心跳表方案
- 每10秒向 WAL 写入逻辑解码消息,绕过 publication 过滤
- 无需建表、无需改 table.include.list、无需改 publication
- 不产生额外 Kafka 消息,对消费端零影响
- 要求 PostgreSQL >= 14 (当前 16.11)
影响范围: 全部5个 outbox connector 配置文件
操作方式: PUT /connectors/{name}/config 热更新,触发 task 重启
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 02:44:38 -08:00
hailin
ab9212cefa
security: 基础设施端口绑定 127.0.0.1,封堵公网暴露
...
PostgreSQL(5432)、Redis(6379)、Debezium REST API(8084) 此前绑定
0.0.0.0,直接暴露在公网。安全审查发现 Debezium 已被注入 3 个恶意
connector(SSRF 攻击尝试读取 /etc/passwd),恶意 connector 已清除。
修改内容:
- PostgreSQL: 0.0.0.0:5432 → 127.0.0.1:5432
- Redis: 0.0.0.0:6379 → 127.0.0.1:6379
- Debezium: 0.0.0.0:8084 → 127.0.0.1:8084
deploy-mining.sh 通过 docker exec 和 localhost 访问,不受影响。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 19:23:42 -08:00
hailin
bc3d800936
feat(mining-app): 贡献值730天失效倒计时功能
...
将贡献值页面的"贡献值失效倒计时"从硬编码静态文字改为基于用户
首次挖矿时间的真实730天倒计时。纯新增方式实现,不影响现有功能。
后端 (mining-service):
- get-mining-account.query.ts: MiningAccountDto 新增 firstMiningDate
字段,在 Promise.all 中并行查询用户最早的 miningRecord,利用
@@unique([accountSequence, miningMinute]) 索引高效查询
前端实体/模型:
- share_account.dart: 新增 DateTime? firstMiningDate(可空,向后兼容)
- share_account_model.dart: fromJson/toJson 解析和序列化 firstMiningDate
前端 UI (contribution_page.dart):
- watch shareAccountProvider 获取首次挖矿时间
- 计算已过天数和剩余天数(730 - 已过天数)
- 进度条显示实际已用时间占比
- 显示具体失效日期和剩余天数
- 无挖矿记录 → 显示"暂无挖矿记录"
- 已过期 → 显示"贡献值已失效"
- 剩余 ≤30 天 → 进度条和文字变红色警告
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 07:30:01 -08:00
hailin
80e3fdb7e0
fix(admin-service): 修复合同服务调用 planting-service 端口和路径错误
...
- 端口从 3002 改为 3003(与 planting-service 实际端口一致)
- API 路径添加 /api/v1 前缀(planting-service 有全局前缀)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 23:20:26 -08:00
hailin
6845ad4a0f
fix(contracts): 移除控制器路径中的重复 v1 前缀
...
全局前缀已是 api/v1,控制器路径应为 admin/contracts
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 23:12:34 -08:00
hailin
0e058caa28
fix(contracts): Prisma JSON 字段使用 undefined 替代 null
...
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 23:02:02 -08:00
hailin
05e2c29f37
chore(admin-service): 更新 package-lock.json 添加 archiver/axios 依赖
...
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 22:58:18 -08:00
hailin
1bb12783db
fix(contracts): 修复合同状态枚举 EXPIRED -> UNSIGNED_TIMEOUT
...
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 22:55:06 -08:00