Compare commits
16 Commits
v2.0.0-beta
...
v2.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| c56e08e681 | |||
| 7e87965418 | |||
| e115d459f7 | |||
| dd39e59304 | |||
| 2efc04a3c3 | |||
| 2b20f4b2e2 | |||
| 419c68c024 | |||
| 8889803dd7 | |||
| 9c5517768f | |||
| 4aa85a9c2d | |||
| a77b3b10ee | |||
| 532f4c3e25 | |||
| 04629e73b6 | |||
| 696193c571 | |||
| 38e256c4fb | |||
| fabfe601c6 |
@@ -111,11 +111,16 @@ jobs:
|
||||
node-version: '18'
|
||||
|
||||
- name: Build Frontend
|
||||
env:
|
||||
VERSION: ${{ steps.extract_version.outputs.VERSION }}
|
||||
GIT_TAG: ${{ steps.extract_version.outputs.TAG }}
|
||||
GITHUB_REPO_URL: https://github.com/WrBug/PolyHermes
|
||||
run: |
|
||||
cd frontend
|
||||
npm ci
|
||||
npm run build
|
||||
echo "✅ 前端构建完成"
|
||||
echo "📦 版本信息: VERSION=${{ steps.extract_version.outputs.VERSION }}, GIT_TAG=${{ steps.extract_version.outputs.TAG }}"
|
||||
du -sh dist/
|
||||
|
||||
# ============ 打包更新包 ============
|
||||
|
||||
+32
-13
@@ -31,21 +31,22 @@ RUN if [ "$BUILD_IN_DOCKER" = "true" ]; then \
|
||||
COPY frontend/ ./
|
||||
|
||||
# 条件:仅在 Docker 内部编译时执行构建
|
||||
# 如果 BUILD_IN_DOCKER=false,需要从构建上下文复制外部编译的 dist
|
||||
# 如果 BUILD_IN_DOCKER=false,需要确保构建上下文中存在 frontend/dist
|
||||
# 注意:COPY frontend/ ./ 已经复制了整个 frontend 目录(包括 dist,如果存在)
|
||||
RUN if [ "$BUILD_IN_DOCKER" = "true" ]; then \
|
||||
echo "🔨 Docker 内部编译前端..."; \
|
||||
npm run build; \
|
||||
else \
|
||||
echo "⏭️ 使用外部产物,将在下一步复制"; \
|
||||
mkdir -p dist; \
|
||||
echo "⏭️ 使用外部产物..."; \
|
||||
if [ ! -d "dist" ] || [ -z "$(ls -A dist 2>/dev/null)" ]; then \
|
||||
echo "❌ 错误:BUILD_IN_DOCKER=false 但找不到外部产物 frontend/dist"; \
|
||||
echo " 请先执行: cd frontend && npm install && npm run build"; \
|
||||
exit 1; \
|
||||
else \
|
||||
echo "✅ 找到外部构建的前端产物"; \
|
||||
fi; \
|
||||
fi
|
||||
|
||||
# 如果使用外部产物,从构建上下文复制外部编译的 dist
|
||||
# 注意:这个 COPY 在 BUILD_IN_DOCKER=false 时必需
|
||||
# 在 BUILD_IN_DOCKER=true 时,如果前端已编译,这个 COPY 会尝试覆盖,但结果相同
|
||||
# 如果本地没有 dist(BUILD_IN_DOCKER=true 且未编译),这个 COPY 会失败,但上面的 RUN 已经编译了
|
||||
COPY frontend/dist ./dist
|
||||
|
||||
# ==================== 阶段2:构建后端 ====================
|
||||
FROM gradle:8.5-jdk17 AS backend-build
|
||||
ARG BUILD_IN_DOCKER
|
||||
@@ -64,9 +65,25 @@ RUN if [ "$BUILD_IN_DOCKER" = "true" ]; then \
|
||||
# 复制源代码
|
||||
COPY backend/src ./src
|
||||
|
||||
# 如果使用外部产物,先从构建上下文复制外部编译的 JAR
|
||||
# 注意:如果 BUILD_IN_DOCKER=true 且本地没有 JAR,这个 COPY 会失败,但会在下面编译生成
|
||||
COPY backend/build/libs/*.jar build/libs/
|
||||
# 尝试复制外部构建的 JAR(如果存在)
|
||||
# 注意:COPY 指令如果源不存在会失败
|
||||
# GitHub Actions 使用 BUILD_IN_DOCKER=false,会先构建产物,所以 backend/build 应该存在
|
||||
# 本地开发使用 BUILD_IN_DOCKER=true,会在 Docker 内编译,所以 backend/build 可能不存在
|
||||
# 解决方案:先复制整个 backend 目录(包括 build,如果存在),然后只使用需要的部分
|
||||
# 使用 .dockerignore 确保不会复制不需要的文件(如 .gradle、out、bin 等)
|
||||
COPY backend/build ./build-external
|
||||
|
||||
# 处理外部构建的 JAR(如果存在)
|
||||
RUN if [ -d "build-external/libs" ] && [ -n "$(ls -A build-external/libs/*.jar 2>/dev/null)" ]; then \
|
||||
echo "📦 找到外部构建的后端产物,复制到 build/libs..."; \
|
||||
mkdir -p build/libs; \
|
||||
cp build-external/libs/*.jar build/libs/; \
|
||||
rm -rf build-external; \
|
||||
else \
|
||||
echo "⏭️ 未找到外部构建的 JAR,将在 Docker 内编译"; \
|
||||
rm -rf build-external; \
|
||||
mkdir -p build/libs; \
|
||||
fi
|
||||
|
||||
# 条件:仅在 Docker 内部编译时执行构建(会覆盖外部产物)
|
||||
RUN if [ "$BUILD_IN_DOCKER" = "true" ]; then \
|
||||
@@ -74,10 +91,12 @@ RUN if [ "$BUILD_IN_DOCKER" = "true" ]; then \
|
||||
gradle bootJar --no-daemon; \
|
||||
else \
|
||||
echo "⏭️ 使用外部产物"; \
|
||||
mkdir -p build/libs; \
|
||||
if [ -z "$(ls -A build/libs/*.jar 2>/dev/null)" ]; then \
|
||||
echo "❌ 错误:BUILD_IN_DOCKER=false 但找不到外部产物 backend/build/libs/*.jar"; \
|
||||
echo " 请先执行: cd backend && ./gradlew bootJar"; \
|
||||
exit 1; \
|
||||
else \
|
||||
echo "✅ 使用外部构建的后端产物"; \
|
||||
fi; \
|
||||
fi
|
||||
|
||||
|
||||
@@ -74,3 +74,4 @@
|
||||
- b658270 - 添加订单详情查询脚本
|
||||
- 07b4d65 - 清理 MarketPollingService 调试日志
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
# PolyHermes v2.0.0 Release Notes
|
||||
|
||||
## 🎉 重大更新
|
||||
|
||||
PolyHermes v2.0.0 是一个重要版本更新,带来了系统动态更新功能、优化的用户体验和多项技术改进。
|
||||
|
||||
---
|
||||
|
||||
## ✨ 新功能
|
||||
|
||||
### 🔄 系统动态更新(核心功能)
|
||||
|
||||
**无需重启 Docker 容器即可更新系统**,大幅提升部署和维护效率。
|
||||
|
||||
- ✅ **在线更新**:在 Web UI 中一键检查并应用更新,无需手动操作
|
||||
- ✅ **零停机更新**:更新过程约 30-60 秒,系统自动处理,无需重启容器
|
||||
- ✅ **自动回滚**:更新失败时自动恢复到旧版本,确保系统稳定性
|
||||
- ✅ **版本管理**:清晰显示当前版本和可用更新,支持 Pre-release 版本检测
|
||||
- ✅ **更新内容展示**:支持 Markdown 格式的更新说明,美观易读
|
||||
|
||||
**技术特性**:
|
||||
- 独立的 Python Flask 更新服务(端口 9090),与主应用隔离
|
||||
- 单一更新包(tar.gz),包含前后端完整更新
|
||||
- 自动备份和版本管理
|
||||
- 管理员权限验证,确保安全性
|
||||
|
||||
### 📦 Release 管理工具
|
||||
|
||||
- **自动化发布脚本** (`create-release.sh`):
|
||||
- 自动创建 Git 标签
|
||||
- 发布 GitHub Release
|
||||
- 支持 Pre-release 标记
|
||||
- 自动拼接版本号后缀(Pre-release 自动添加 `-beta`)
|
||||
- 支持非交互模式,便于 CI/CD 集成
|
||||
|
||||
### 🎨 版本号显示优化
|
||||
|
||||
- **Tag 格式显示**:版本号使用 Git Tag 格式(如 `v2.0.0-beta`)
|
||||
- **智能颜色提示**:
|
||||
- 🟡 **黄色 Tag**:有新版本可用(点击可跳转到系统更新页面)
|
||||
- 🟢 **绿色 Tag**:当前已是最新版本
|
||||
- **镂空样式**:更小巧美观的版本号标签
|
||||
- **自动检查**:系统自动检查更新,有新版本时在导航栏显示提示
|
||||
|
||||
---
|
||||
|
||||
## 🎨 UI/UX 优化
|
||||
|
||||
### 系统更新页面
|
||||
|
||||
- **美化界面**:全新的渐变背景、卡片样式和图标设计
|
||||
- **Markdown 支持**:更新内容支持完整的 Markdown 渲染(标题、列表、代码块、表格等)
|
||||
- **进度显示**:美观的进度条和状态提示
|
||||
- **优化布局**:系统更新模块移至系统设置页面最上方,更易访问
|
||||
|
||||
### 版本号显示
|
||||
|
||||
- 使用镂空 Tag 样式,字号 8px
|
||||
- 与标题垂直居中对齐
|
||||
- 响应式设计,完美支持移动端和桌面端
|
||||
|
||||
---
|
||||
|
||||
## 🔧 技术改进
|
||||
|
||||
### 构建系统
|
||||
|
||||
- **修复 Docker 构建问题**:
|
||||
- 修复 `BUILD_IN_DOCKER=false` 时找不到前端产物的问题
|
||||
- 优化 `.dockerignore` 配置,确保外部构建产物可被使用
|
||||
- 修复 GitHub Actions 构建流程
|
||||
|
||||
- **版本号注入**:
|
||||
- 修复前端构建时版本号未正确传递的问题
|
||||
- 支持在构建时注入 Git Tag 和版本信息
|
||||
|
||||
- **Gradle Wrapper**:
|
||||
- 修复 GitHub Actions 构建错误
|
||||
- 正确配置 Gradle Wrapper JAR
|
||||
|
||||
### 代码质量
|
||||
|
||||
- 修复 TypeScript 编译错误
|
||||
- 清理未使用的导入和组件
|
||||
- 优化代码结构
|
||||
|
||||
---
|
||||
|
||||
## 📝 新增文档
|
||||
|
||||
- `docs/zh/DYNAMIC_UPDATE.md` - 动态更新技术方案文档
|
||||
- `docs/zh/DOCKER_VERSION.md` - Docker 版本管理说明
|
||||
- `docs/zh/DYNAMIC_UPDATE_CHECK.md` - 动态更新检查机制文档
|
||||
- `scripts/README_RELEASE.md` - Release 脚本使用说明
|
||||
- `scripts/CHANGELOG_TEMPLATE.md` - 更新日志模板
|
||||
|
||||
---
|
||||
|
||||
## 🔄 升级指南
|
||||
|
||||
### 从 v1.1.16 升级到 v2.0.0
|
||||
|
||||
#### 方式一:使用动态更新功能(推荐)
|
||||
|
||||
1. 登录系统,进入 **系统设置** → **系统更新**
|
||||
2. 点击 **检查更新**
|
||||
3. 如果有新版本,点击 **立即升级**
|
||||
4. 等待更新完成(约 30-60 秒)
|
||||
5. 页面会自动刷新,更新完成
|
||||
|
||||
#### 方式二:重新部署 Docker 容器
|
||||
|
||||
```bash
|
||||
# 1. 停止当前容器
|
||||
docker-compose -f docker-compose.prod.yml down
|
||||
|
||||
# 2. 拉取新版本镜像
|
||||
docker pull wrbug/polyhermes:v2.0.0
|
||||
|
||||
# 3. 更新 docker-compose.prod.yml 中的镜像标签
|
||||
# image: wrbug/polyhermes:v2.0.0
|
||||
|
||||
# 4. 重新启动
|
||||
docker-compose -f docker-compose.prod.yml up -d
|
||||
```
|
||||
|
||||
### 注意事项
|
||||
|
||||
- ⚠️ **数据备份**:虽然更新不会删除数据,但建议在更新前备份数据库
|
||||
- ⚠️ **权限要求**:执行动态更新需要管理员权限
|
||||
- ✅ **向后兼容**:v2.0.0 完全兼容 v1.1.16 的数据结构和配置
|
||||
|
||||
---
|
||||
|
||||
## 📊 变更统计
|
||||
|
||||
- **新增文件**:17 个
|
||||
- **修改文件**:13 个
|
||||
- **代码变更**:+5251 行,-163 行
|
||||
|
||||
### 主要新增文件
|
||||
|
||||
- `docker/update-service.py` - 更新服务(Python Flask)
|
||||
- `frontend/src/pages/SystemUpdate.tsx` - 系统更新页面
|
||||
- `create-release.sh` - Release 创建脚本
|
||||
- `docs/zh/DYNAMIC_UPDATE.md` - 动态更新技术文档
|
||||
|
||||
---
|
||||
|
||||
## 🐛 修复的问题
|
||||
|
||||
- 修复 Docker 构建时找不到前端产物的问题
|
||||
- 修复前端构建时版本号未正确传递的问题
|
||||
- 修复 GitHub Actions 构建错误(Gradle Wrapper)
|
||||
- 修复 TypeScript 编译错误
|
||||
|
||||
---
|
||||
|
||||
## 📚 相关文档
|
||||
|
||||
- [动态更新技术方案](docs/zh/DYNAMIC_UPDATE.md)
|
||||
- [Docker 版本管理](docs/zh/DOCKER_VERSION.md)
|
||||
- [部署指南](docs/zh/DEPLOYMENT.md)
|
||||
- [Release 脚本使用说明](scripts/README_RELEASE.md)
|
||||
|
||||
---
|
||||
|
||||
## 🙏 致谢
|
||||
|
||||
感谢所有使用 PolyHermes 的用户和贡献者!
|
||||
|
||||
---
|
||||
|
||||
**下载地址**:
|
||||
- Docker Hub: `wrbug/polyhermes:v2.0.0`
|
||||
- GitHub Releases: [v2.0.0](https://github.com/WrBug/PolyHermes/releases/tag/v2.0.0)
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
# PolyHermes v2.0.1 Release Notes
|
||||
|
||||
## 📋 版本信息
|
||||
- **版本号**: v2.0.1
|
||||
- **发布日期**: 2026-01-28
|
||||
- **基础版本**: v2.0.0
|
||||
|
||||
## 🎯 改动摘要
|
||||
|
||||
本次版本主要修复了订单状态检查、RPC 节点管理、订单金额计算等关键问题,提升了系统稳定性和用户体验。
|
||||
|
||||
---
|
||||
|
||||
## 🐛 Bug 修复
|
||||
|
||||
### 1. 修复订单状态检查中缓存清除导致计时重置的问题
|
||||
|
||||
**问题描述**:
|
||||
- 订单详情为 `null` 时,缓存清除时机不当导致计时被重置
|
||||
- 订单超过 60 秒后无法正常删除
|
||||
- 部分卖出订单等待时间过长(之前等待 1 小时)
|
||||
|
||||
**修复内容**:
|
||||
- ✅ 修复缓存清除时机问题,避免计时被重置
|
||||
- ✅ 统一部分卖出和未成交订单的删除逻辑,都使用 60 秒重试窗口
|
||||
- ✅ 删除未使用的常量 `PARTIAL_SOLD_CLEANUP_WINDOW_MS`
|
||||
- ✅ 优化日志输出,区分部分卖出和未成交订单的日志信息
|
||||
|
||||
**影响范围**:
|
||||
- `OrderStatusUpdateService.kt` - 订单状态更新服务
|
||||
|
||||
**提交**: 7e87965
|
||||
|
||||
---
|
||||
|
||||
### 2. 修复禁用 RPC 节点后仍被使用的问题
|
||||
|
||||
**问题描述**:
|
||||
- 禁用 RPC 节点后,节点仍可能被系统使用
|
||||
- 节点状态更新不及时
|
||||
|
||||
**修复内容**:
|
||||
- ✅ 修复节点禁用逻辑,确保禁用后立即生效
|
||||
- ✅ 优化节点状态检查机制
|
||||
- ✅ 改进节点选择逻辑
|
||||
|
||||
**影响范围**:
|
||||
- `RpcNodeService.kt` - RPC 节点服务
|
||||
|
||||
**提交**: dd39e59
|
||||
|
||||
---
|
||||
|
||||
### 3. 修复订单金额计算和价格范围验证问题
|
||||
|
||||
**问题描述**:
|
||||
- 订单金额计算可能存在精度问题
|
||||
- 价格范围验证逻辑不完善
|
||||
|
||||
**修复内容**:
|
||||
- ✅ 修复订单金额计算逻辑
|
||||
- ✅ 完善价格范围验证
|
||||
- ✅ 优化数值计算精度处理
|
||||
|
||||
**影响范围**:
|
||||
- `OrderSigningService.kt` - 订单签名服务
|
||||
|
||||
**提交**: 2b20f4b
|
||||
|
||||
---
|
||||
|
||||
### 4. 修复系统更新 API 路由和改进健康检查逻辑
|
||||
|
||||
**问题描述**:
|
||||
- 系统更新 API 路由可能存在问题
|
||||
- 健康检查逻辑需要优化
|
||||
|
||||
**修复内容**:
|
||||
- ✅ 修复系统更新 API 路由
|
||||
- ✅ 改进健康检查逻辑
|
||||
- ✅ 优化错误处理
|
||||
|
||||
**提交**: 4aa85a9
|
||||
|
||||
---
|
||||
|
||||
### 5. 修复 Docker 构建相关问题
|
||||
|
||||
**问题描述**:
|
||||
- 本地 Docker 构建时 `frontend/dist` 和 `backend/build` 不存在导致构建失败
|
||||
- Dockerfile 中前端产物复制逻辑有问题
|
||||
|
||||
**修复内容**:
|
||||
- ✅ 修复本地 Docker 构建时目录不存在的问题
|
||||
- ✅ 修复 Dockerfile 中前端产物复制逻辑
|
||||
- ✅ 优化构建流程
|
||||
|
||||
**影响范围**:
|
||||
- `Dockerfile` - Docker 构建文件
|
||||
- `deploy.sh` - 部署脚本
|
||||
|
||||
**提交**: 419c68c, 8889803
|
||||
|
||||
---
|
||||
|
||||
### 6. 补充缺失的多语言 key
|
||||
|
||||
**问题描述**:
|
||||
- 部分多语言 key 缺失,导致界面显示异常
|
||||
|
||||
**修复内容**:
|
||||
- ✅ 补充缺失的多语言 key
|
||||
- ✅ 完善多语言支持
|
||||
|
||||
**影响范围**:
|
||||
- `frontend/src/locales/` - 多语言文件
|
||||
|
||||
**提交**: 2efc04a
|
||||
|
||||
---
|
||||
|
||||
## 🔧 优化改进
|
||||
|
||||
### 优化过滤原因文案的数值显示格式
|
||||
|
||||
**改进内容**:
|
||||
- ✅ 优化过滤原因文案的数值显示格式
|
||||
- ✅ 新增日期工具函数,统一日期格式化
|
||||
- ✅ 提升用户体验
|
||||
|
||||
**影响范围**:
|
||||
- `CopyTradingFilterService.kt` - 跟单过滤服务
|
||||
- `DateUtils.kt` - 日期工具类(新增)
|
||||
|
||||
**提交**: e115d45
|
||||
|
||||
---
|
||||
|
||||
## 📊 文件变更统计
|
||||
|
||||
- **修改文件数**: 10+
|
||||
- **新增文件数**: 1 (DateUtils.kt)
|
||||
- **新增行数**: 200+
|
||||
- **删除行数**: 100+
|
||||
|
||||
---
|
||||
|
||||
## 🔄 升级建议
|
||||
|
||||
1. **直接部署**:无需特殊操作,直接部署即可
|
||||
2. **验证订单处理**:建议验证订单状态检查是否正常工作
|
||||
3. **检查 RPC 节点**:确认 RPC 节点状态管理是否正常
|
||||
4. **验证订单金额**:确认订单金额计算是否正确
|
||||
|
||||
---
|
||||
|
||||
## 📝 完整提交列表
|
||||
|
||||
- 7e87965 - fix: 修复订单状态检查中缓存清除导致计时重置的问题
|
||||
- e115d45 - refactor: 优化过滤原因文案的数值显示格式
|
||||
- dd39e59 - fix: 修复禁用RPC节点后仍被使用的问题
|
||||
- 2efc04a - fix: 补充缺失的多语言key
|
||||
- 2b20f4b - fix: 修复订单金额计算和价格范围验证问题
|
||||
- 419c68c - fix: 修复本地 Docker 构建时 frontend/dist 和 backend/build 不存在的问题
|
||||
- 8889803 - fix: 修复 Dockerfile 中前端产物复制逻辑
|
||||
- 4aa85a9 - fix: 修复系统更新 API 路由和改进健康检查逻辑
|
||||
|
||||
---
|
||||
|
||||
## 🙏 致谢
|
||||
|
||||
感谢所有贡献者和用户的支持与反馈!
|
||||
|
||||
+23
-6
@@ -7,6 +7,7 @@ import com.wrbug.polymarketbot.util.lt
|
||||
import com.wrbug.polymarketbot.util.multi
|
||||
import com.wrbug.polymarketbot.util.toSafeBigDecimal
|
||||
import com.wrbug.polymarketbot.util.JsonUtils
|
||||
import com.wrbug.polymarketbot.util.DateUtils
|
||||
import org.slf4j.LoggerFactory
|
||||
import com.wrbug.polymarketbot.service.common.PolymarketClobService
|
||||
import com.wrbug.polymarketbot.service.accounts.AccountService
|
||||
@@ -202,12 +203,16 @@ class CopyTradingFilterService(
|
||||
|
||||
// 检查最低价格
|
||||
if (copyTrading.minPrice != null && tradePrice.lt(copyTrading.minPrice)) {
|
||||
return FilterResult.priceRangeFailed("价格低于最低限制: $tradePrice < ${copyTrading.minPrice}")
|
||||
val priceStr = tradePrice.stripTrailingZeros().toPlainString()
|
||||
val minPriceStr = copyTrading.minPrice.stripTrailingZeros().toPlainString()
|
||||
return FilterResult.priceRangeFailed("价格低于最低限制: $priceStr < $minPriceStr")
|
||||
}
|
||||
|
||||
// 检查最高价格
|
||||
if (copyTrading.maxPrice != null && tradePrice.gt(copyTrading.maxPrice)) {
|
||||
return FilterResult.priceRangeFailed("价格高于最高限制: $tradePrice > ${copyTrading.maxPrice}")
|
||||
val priceStr = tradePrice.stripTrailingZeros().toPlainString()
|
||||
val maxPriceStr = copyTrading.maxPrice.stripTrailingZeros().toPlainString()
|
||||
return FilterResult.priceRangeFailed("价格高于最高限制: $priceStr > $maxPriceStr")
|
||||
}
|
||||
|
||||
return FilterResult.passed()
|
||||
@@ -245,7 +250,9 @@ class CopyTradingFilterService(
|
||||
val spread = bestAsk.subtract(bestBid)
|
||||
|
||||
if (spread.gt(copyTrading.maxSpread)) {
|
||||
return FilterResult.spreadFailed("价差过大: $spread > ${copyTrading.maxSpread}", orderbook)
|
||||
val spreadStr = spread.stripTrailingZeros().toPlainString()
|
||||
val maxSpreadStr = copyTrading.maxSpread.stripTrailingZeros().toPlainString()
|
||||
return FilterResult.spreadFailed("价差过大: $spreadStr > $maxSpreadStr", orderbook)
|
||||
}
|
||||
|
||||
return FilterResult.passed()
|
||||
@@ -285,7 +292,9 @@ class CopyTradingFilterService(
|
||||
val totalDepth = bidsDepth.add(asksDepth)
|
||||
|
||||
if (totalDepth.lt(copyTrading.minOrderDepth)) {
|
||||
return FilterResult.orderDepthFailed("订单深度不足: $totalDepth < ${copyTrading.minOrderDepth}", orderbook)
|
||||
val totalDepthStr = totalDepth.stripTrailingZeros().toPlainString()
|
||||
val minDepthStr = copyTrading.minOrderDepth.stripTrailingZeros().toPlainString()
|
||||
return FilterResult.orderDepthFailed("订单深度不足: $totalDepthStr < $minDepthStr", orderbook)
|
||||
}
|
||||
|
||||
return FilterResult.passed()
|
||||
@@ -348,8 +357,14 @@ class CopyTradingFilterService(
|
||||
val totalValueAfterOrder = currentPositionValue.add(copyOrderAmount)
|
||||
|
||||
if (totalValueAfterOrder.gt(copyTrading.maxPositionValue)) {
|
||||
val currentValueStr = currentPositionValue.stripTrailingZeros().toPlainString()
|
||||
val dbValueStr = dbValue.stripTrailingZeros().toPlainString()
|
||||
val extValueStr = extValue.stripTrailingZeros().toPlainString()
|
||||
val orderAmountStr = copyOrderAmount.stripTrailingZeros().toPlainString()
|
||||
val totalValueStr = totalValueAfterOrder.stripTrailingZeros().toPlainString()
|
||||
val maxValueStr = copyTrading.maxPositionValue.stripTrailingZeros().toPlainString()
|
||||
return FilterResult.maxPositionValueFailed(
|
||||
"超过最大仓位金额限制: 市场=$marketId, 方向=$outcomeIndex, 当前仓位(取最大值)=${currentPositionValue} USDC (DB=${dbValue}, Ext=${extValue}), 跟单金额=${copyOrderAmount} USDC, 总计=${totalValueAfterOrder} USDC > 最大限制=${copyTrading.maxPositionValue} USDC"
|
||||
"超过最大仓位金额限制: 市场=$marketId, 方向=$outcomeIndex, 当前仓位(取最大值)=${currentValueStr} USDC (DB=${dbValueStr}, Ext=${extValueStr}), 跟单金额=${orderAmountStr} USDC, 总计=${totalValueStr} USDC > 最大限制=${maxValueStr} USDC"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -420,8 +435,10 @@ class CopyTradingFilterService(
|
||||
val remainingTime = marketEndDate - currentTime
|
||||
|
||||
if (remainingTime > copyTrading.maxMarketEndDate) {
|
||||
val remainingTimeFormatted = DateUtils.formatDuration(remainingTime)
|
||||
val maxLimitFormatted = DateUtils.formatDuration(copyTrading.maxMarketEndDate)
|
||||
return FilterResult.marketEndDateFailed(
|
||||
"市场截止时间超出限制: 剩余时间=${remainingTime}ms (${remainingTime / (1000 * 60 * 60)}小时) > 最大限制=${copyTrading.maxMarketEndDate}ms (${copyTrading.maxMarketEndDate / (1000 * 60 * 60)}小时)"
|
||||
"市场截止时间超出限制: 剩余时间=${remainingTimeFormatted} > 最大限制=${maxLimitFormatted}"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+92
-42
@@ -36,13 +36,11 @@ class OrderSigningService {
|
||||
size = 2,
|
||||
amount = 4
|
||||
)
|
||||
|
||||
// 金额精度限制(根据 Polymarket API 要求)
|
||||
// makerAmount (USDC) 最多 2 位小数
|
||||
// takerAmount (shares) 最多 4 位小数
|
||||
private val MAKER_AMOUNT_DECIMALS = 2 // USDC 金额精度
|
||||
private val TAKER_AMOUNT_DECIMALS = 4 // shares 数量精度
|
||||
|
||||
|
||||
// 价格有效范围(Polymarket API 要求)
|
||||
private val MIN_PRICE = BigDecimal("0.01")
|
||||
private val MAX_PRICE = BigDecimal("0.99")
|
||||
|
||||
/**
|
||||
* 订单金额计算结果
|
||||
*/
|
||||
@@ -62,7 +60,9 @@ class OrderSigningService {
|
||||
|
||||
/**
|
||||
* 计算订单金额(makerAmount 和 takerAmount)
|
||||
*
|
||||
*
|
||||
* 参考 clob-client/src/order-builder/helpers.ts 的 getOrderRawAmounts 函数
|
||||
*
|
||||
* @param side BUY 或 SELL
|
||||
* @param size 数量(shares)
|
||||
* @param price 价格(0-1 之间)
|
||||
@@ -77,49 +77,57 @@ class OrderSigningService {
|
||||
): OrderAmounts {
|
||||
val sizeDecimal = size.toSafeBigDecimal()
|
||||
val priceDecimal = price.toSafeBigDecimal()
|
||||
|
||||
// 对价格进行 roundNormal 处理(与 clob-client 保持一致)
|
||||
var rawPrice = roundNormal(priceDecimal, roundConfig.price)
|
||||
|
||||
// 验证价格范围,如果超出则调整到最接近的有效值
|
||||
// Polymarket API 要求: 0.01 <= price <= 0.99
|
||||
if (rawPrice > MAX_PRICE) {
|
||||
logger.warn("价格超出最大限制,已调整: $priceDecimal -> $MAX_PRICE")
|
||||
rawPrice = MAX_PRICE
|
||||
} else if (rawPrice < MIN_PRICE) {
|
||||
logger.warn("价格低于最小限制,已调整: $priceDecimal -> $MIN_PRICE")
|
||||
rawPrice = MIN_PRICE
|
||||
}
|
||||
|
||||
if (side.uppercase() == "BUY") {
|
||||
// BUY: makerAmount = price * size (USDC), takerAmount = size (shares)
|
||||
// makerAmount 是 USDC 金额,最多 2 位小数
|
||||
// takerAmount 是 shares 数量,最多 4 位小数
|
||||
// 参考 clob-client/src/order-builder/helpers.ts 第 73-89 行
|
||||
val rawTakerAmt = roundDown(sizeDecimal, roundConfig.size)
|
||||
|
||||
// makerAmount = price * size,使用原始价格计算(与SDK保持一致)
|
||||
// 先使用原始价格计算,然后再进行舍入,确保精度一致
|
||||
var rawMakerAmt = rawTakerAmt.multiply(priceDecimal)
|
||||
|
||||
// 确保 makerAmount 精度(USDC,最多 2 位小数)
|
||||
rawMakerAmt = roundDown(rawMakerAmt, MAKER_AMOUNT_DECIMALS)
|
||||
|
||||
// 确保 takerAmount 精度(shares,最多 4 位小数)
|
||||
val finalTakerAmt = roundDown(rawTakerAmt, TAKER_AMOUNT_DECIMALS)
|
||||
|
||||
|
||||
var rawMakerAmt = rawTakerAmt.multiply(rawPrice)
|
||||
// 如果 makerAmount 的小数位数超过 roundConfig.amount,进行特殊舍入处理
|
||||
if (decimalPlaces(rawMakerAmt) > roundConfig.amount) {
|
||||
rawMakerAmt = roundUp(rawMakerAmt, roundConfig.amount + 4)
|
||||
if (decimalPlaces(rawMakerAmt) > roundConfig.amount) {
|
||||
rawMakerAmt = roundDown(rawMakerAmt, roundConfig.amount)
|
||||
}
|
||||
}
|
||||
|
||||
// 转换为 wei(6 位小数)
|
||||
val makerAmount = parseUnits(rawMakerAmt, COLLATERAL_TOKEN_DECIMALS)
|
||||
val takerAmount = parseUnits(finalTakerAmt, COLLATERAL_TOKEN_DECIMALS)
|
||||
|
||||
val takerAmount = parseUnits(rawTakerAmt, COLLATERAL_TOKEN_DECIMALS)
|
||||
|
||||
return OrderAmounts(makerAmount.toString(), takerAmount.toString())
|
||||
} else {
|
||||
// SELL: makerAmount = size (shares), takerAmount = price * size (USDC)
|
||||
// 根据 Polymarket API 要求:
|
||||
// - makerAmount (shares) 最多 2 位小数
|
||||
// - takerAmount (USDC) 最多 4 位小数
|
||||
// 参考 clob-client/src/order-builder/helpers.ts 第 90-105 行
|
||||
val rawMakerAmt = roundDown(sizeDecimal, roundConfig.size)
|
||||
|
||||
// takerAmount = price * size,使用原始价格计算(不使用舍入后的价格)
|
||||
// SDK期望使用原始价格进行计算,以保留足够的精度
|
||||
// 例如:0.9596 * 16.09 = 15.439964,而不是 0.96 * 16.09 = 15.4464
|
||||
val rawTakerAmt = rawMakerAmt.multiply(priceDecimal)
|
||||
|
||||
// 确保 makerAmount 精度(shares,最多 2 位小数,符合 API 要求)
|
||||
val finalMakerAmt = roundDown(rawMakerAmt, MAKER_AMOUNT_DECIMALS)
|
||||
|
||||
// 确保 takerAmount 精度(USDC,最多 4 位小数,符合 API 要求)
|
||||
val finalTakerAmt = roundDown(rawTakerAmt, TAKER_AMOUNT_DECIMALS)
|
||||
|
||||
|
||||
var rawTakerAmt = rawMakerAmt.multiply(rawPrice)
|
||||
// 如果 takerAmount 的小数位数超过 roundConfig.amount,进行特殊舍入处理
|
||||
if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
|
||||
rawTakerAmt = roundUp(rawTakerAmt, roundConfig.amount + 4)
|
||||
if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
|
||||
rawTakerAmt = roundDown(rawTakerAmt, roundConfig.amount)
|
||||
}
|
||||
}
|
||||
|
||||
// 转换为 wei(6 位小数)
|
||||
val makerAmount = parseUnits(finalMakerAmt, COLLATERAL_TOKEN_DECIMALS)
|
||||
val takerAmount = parseUnits(finalTakerAmt, COLLATERAL_TOKEN_DECIMALS)
|
||||
|
||||
val makerAmount = parseUnits(rawMakerAmt, COLLATERAL_TOKEN_DECIMALS)
|
||||
val takerAmount = parseUnits(rawTakerAmt, COLLATERAL_TOKEN_DECIMALS)
|
||||
|
||||
return OrderAmounts(makerAmount.toString(), takerAmount.toString())
|
||||
}
|
||||
}
|
||||
@@ -324,23 +332,65 @@ class OrderSigningService {
|
||||
|
||||
/**
|
||||
* 正常舍入(四舍五入)
|
||||
* 参考 clob-client/src/utilities.ts 的 roundNormal 函数
|
||||
* 只有当小数位数超过 decimals 时才进行舍入
|
||||
*
|
||||
* @param value 要舍入的数值
|
||||
* @param decimals 目标小数位数
|
||||
* @return 舍入后的数值
|
||||
*/
|
||||
private fun roundNormal(value: BigDecimal, decimals: Int): BigDecimal {
|
||||
if (decimalPlaces(value) <= decimals) {
|
||||
return value
|
||||
}
|
||||
return value.setScale(decimals, RoundingMode.HALF_UP)
|
||||
}
|
||||
|
||||
/**
|
||||
* 向下舍入
|
||||
* 参考 clob-client/src/utilities.ts 的 roundDown 函数
|
||||
* 只有当小数位数超过 decimals 时才进行舍入
|
||||
*
|
||||
* @param value 要舍入的数值
|
||||
* @param decimals 目标小数位数
|
||||
* @return 舍入后的数值
|
||||
*/
|
||||
private fun roundDown(value: BigDecimal, decimals: Int): BigDecimal {
|
||||
if (decimalPlaces(value) <= decimals) {
|
||||
return value
|
||||
}
|
||||
return value.setScale(decimals, RoundingMode.DOWN)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 向上舍入
|
||||
* 参考 clob-client/src/utilities.ts 的 roundUp 函数
|
||||
* 只有当小数位数超过 decimals 时才进行舍入
|
||||
*
|
||||
* @param value 要舍入的数值
|
||||
* @param decimals 目标小数位数
|
||||
* @return 舍入后的数值
|
||||
*/
|
||||
private fun roundUp(value: BigDecimal, decimals: Int): BigDecimal {
|
||||
if (decimalPlaces(value) <= decimals) {
|
||||
return value
|
||||
}
|
||||
return value.setScale(decimals, RoundingMode.UP)
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算 BigDecimal 的小数位数
|
||||
* 参考 clob-client/src/utilities.ts 的 decimalPlaces 函数
|
||||
*
|
||||
* @param value 要计算的数值
|
||||
* @return 小数位数
|
||||
*/
|
||||
private fun decimalPlaces(value: BigDecimal): Int {
|
||||
if (value.scale() <= 0) {
|
||||
return 0
|
||||
}
|
||||
// 去除尾部的零,获取真实的小数位数
|
||||
return value.stripTrailingZeros().scale()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+38
-70
@@ -69,9 +69,6 @@ class OrderStatusUpdateService(
|
||||
// 订单详情为 null 的重试时间窗口(1分钟)
|
||||
private val ORDER_NULL_RETRY_WINDOW_MS = 60000L
|
||||
|
||||
// 订单详情为 null 但已部分卖出的清理时间窗口(1小时)
|
||||
private val PARTIAL_SOLD_CLEANUP_WINDOW_MS = 3600000L
|
||||
|
||||
@EventListener(ApplicationReadyEvent::class)
|
||||
fun onApplicationReady() {
|
||||
logger.info("订单状态更新服务已启动,将每5秒轮询一次")
|
||||
@@ -297,53 +294,38 @@ class OrderStatusUpdateService(
|
||||
updatedAt = System.currentTimeMillis()
|
||||
)
|
||||
copyOrderTrackingRepository.save(updatedOrder)
|
||||
// 清除缓存(仅在处理完成后清除)
|
||||
orderNullDetectionTime.remove(order.buyOrderId)
|
||||
} catch (e: Exception) {
|
||||
logger.error("更新订单状态失败: orderId=${order.buyOrderId}, error=${e.message}", e)
|
||||
}
|
||||
}
|
||||
// 清除缓存,下次重新检测
|
||||
orderNullDetectionTime.remove(order.buyOrderId)
|
||||
// 未超过60秒,继续等待,不清除缓存
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查订单是否已部分卖出,如果已部分卖出则保留订单用于统计
|
||||
val hasMatchedDetails =
|
||||
sellMatchDetailRepository.findByTrackingId(order.id!!).isNotEmpty()
|
||||
if (hasMatchedDetails || order.matchedQuantity > BigDecimal.ZERO) {
|
||||
// 检查是否超过清理时间窗口(1小时)
|
||||
val orderAge = currentTime - order.createdAt
|
||||
if (orderAge >= PARTIAL_SOLD_CLEANUP_WINDOW_MS) {
|
||||
logger.warn("订单详情为 null 且已部分卖出,但超过清理时间窗口,删除本地订单: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, matchedQuantity=${order.matchedQuantity}, 已等待=${orderAge / 1000}s")
|
||||
try {
|
||||
copyOrderTrackingRepository.deleteById(order.id!!)
|
||||
logger.info("已删除本地订单(超时清理): orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}")
|
||||
// 清除缓存
|
||||
orderNullDetectionTime.remove(order.buyOrderId)
|
||||
} catch (e: Exception) {
|
||||
logger.error(
|
||||
"删除本地订单失败: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, error=${e.message}",
|
||||
e
|
||||
)
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
logger.debug("订单详情为 null 但已部分卖出,保留订单用于统计: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, matchedQuantity=${order.matchedQuantity}, 已等待=${orderAge / 1000}s")
|
||||
// 清除缓存,下次重新检测
|
||||
orderNullDetectionTime.remove(order.buyOrderId)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否超过重试时间窗口
|
||||
// 检查是否超过重试时间窗口(统一使用60秒,无论是否已部分卖出)
|
||||
if (currentTime - firstDetectionTime < ORDER_NULL_RETRY_WINDOW_MS) {
|
||||
// 未超过重试窗口,记录日志并等待下次轮询
|
||||
val elapsedSeconds = ((currentTime - firstDetectionTime) / 1000).toInt()
|
||||
logger.debug("订单详情为 null(可能是网络异常),等待重试: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, 已等待=${elapsedSeconds}s, 重试窗口=${ORDER_NULL_RETRY_WINDOW_MS / 1000}s")
|
||||
val hasMatchedDetails = sellMatchDetailRepository.findByTrackingId(order.id!!).isNotEmpty()
|
||||
val hasPartialSold = hasMatchedDetails || order.matchedQuantity > BigDecimal.ZERO
|
||||
if (hasPartialSold) {
|
||||
logger.debug("订单详情为 null 且已部分卖出,等待重试: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, matchedQuantity=${order.matchedQuantity}, 已等待=${elapsedSeconds}s, 重试窗口=${ORDER_NULL_RETRY_WINDOW_MS / 1000}s")
|
||||
} else {
|
||||
logger.debug("订单详情为 null(可能是网络异常),等待重试: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, 已等待=${elapsedSeconds}s, 重试窗口=${ORDER_NULL_RETRY_WINDOW_MS / 1000}s")
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// 超过重试窗口,删除本地订单
|
||||
logger.warn("订单详情为 null 超过重试窗口,删除本地订单: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, 已等待=$((currentTime - firstDetectionTime) / 1000}s")
|
||||
// 超过重试窗口,删除本地订单(无论是否已部分卖出)
|
||||
val hasMatchedDetails = sellMatchDetailRepository.findByTrackingId(order.id!!).isNotEmpty()
|
||||
val hasPartialSold = hasMatchedDetails || order.matchedQuantity > BigDecimal.ZERO
|
||||
if (hasPartialSold) {
|
||||
logger.warn("订单详情为 null 且已部分卖出,超过重试窗口,删除本地订单: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, matchedQuantity=${order.matchedQuantity}, 已等待=$((currentTime - firstDetectionTime) / 1000}s")
|
||||
} else {
|
||||
logger.warn("订单详情为 null 超过重试窗口,删除本地订单: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, 已等待=$((currentTime - firstDetectionTime) / 1000}s")
|
||||
}
|
||||
try {
|
||||
copyOrderTrackingRepository.deleteById(order.id!!)
|
||||
logger.info("已删除本地订单: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}")
|
||||
@@ -775,52 +757,38 @@ class OrderStatusUpdateService(
|
||||
updatedAt = System.currentTimeMillis()
|
||||
)
|
||||
copyOrderTrackingRepository.save(updatedOrder)
|
||||
// 清除缓存(仅在处理完成后清除)
|
||||
orderNullDetectionTime.remove(order.buyOrderId)
|
||||
} catch (e: Exception) {
|
||||
logger.error("更新订单状态失败: orderId=${order.buyOrderId}, error=${e.message}", e)
|
||||
}
|
||||
}
|
||||
// 清除缓存,下次重新检测
|
||||
orderNullDetectionTime.remove(order.buyOrderId)
|
||||
// 未超过60秒,继续等待,不清除缓存
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查订单是否已部分卖出,如果已部分卖出则保留订单用于统计
|
||||
val hasMatchedDetails = sellMatchDetailRepository.findByTrackingId(order.id!!).isNotEmpty()
|
||||
if (hasMatchedDetails || order.matchedQuantity > BigDecimal.ZERO) {
|
||||
// 检查是否超过清理时间窗口(1小时)
|
||||
val orderAge = currentTime - order.createdAt
|
||||
if (orderAge >= PARTIAL_SOLD_CLEANUP_WINDOW_MS) {
|
||||
logger.warn("订单详情为 null 且已部分卖出,但超过清理时间窗口,删除本地订单: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, matchedQuantity=${order.matchedQuantity}, 已等待=${orderAge / 1000}s")
|
||||
try {
|
||||
copyOrderTrackingRepository.deleteById(order.id!!)
|
||||
logger.info("已删除本地订单(超时清理): orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}")
|
||||
// 清除缓存
|
||||
orderNullDetectionTime.remove(order.buyOrderId)
|
||||
} catch (e: Exception) {
|
||||
logger.error(
|
||||
"删除本地订单失败: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, error=${e.message}",
|
||||
e
|
||||
)
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
logger.debug("订单详情为 null 但已部分卖出,保留订单用于统计: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, matchedQuantity=${order.matchedQuantity}, 已等待=${orderAge / 1000}s")
|
||||
// 清除缓存,下次重新检测
|
||||
orderNullDetectionTime.remove(order.buyOrderId)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否超过重试时间窗口
|
||||
// 检查是否超过重试时间窗口(统一使用60秒,无论是否已部分卖出)
|
||||
if (currentTime - firstDetectionTime < ORDER_NULL_RETRY_WINDOW_MS) {
|
||||
// 未超过重试窗口,记录日志并等待下次轮询
|
||||
val elapsedSeconds = ((currentTime - firstDetectionTime) / 1000).toInt()
|
||||
logger.debug("订单详情为 null(可能是网络异常),等待重试: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, 已等待=${elapsedSeconds}s, 重试窗口=${ORDER_NULL_RETRY_WINDOW_MS / 1000}s")
|
||||
val hasMatchedDetails = sellMatchDetailRepository.findByTrackingId(order.id!!).isNotEmpty()
|
||||
val hasPartialSold = hasMatchedDetails || order.matchedQuantity > BigDecimal.ZERO
|
||||
if (hasPartialSold) {
|
||||
logger.debug("订单详情为 null 且已部分卖出,等待重试: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, matchedQuantity=${order.matchedQuantity}, 已等待=${elapsedSeconds}s, 重试窗口=${ORDER_NULL_RETRY_WINDOW_MS / 1000}s")
|
||||
} else {
|
||||
logger.debug("订单详情为 null(可能是网络异常),等待重试: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, 已等待=${elapsedSeconds}s, 重试窗口=${ORDER_NULL_RETRY_WINDOW_MS / 1000}s")
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// 超过重试窗口,删除本地订单
|
||||
logger.warn("订单详情为 null 超过重试窗口,删除本地订单: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, 已等待=$((currentTime - firstDetectionTime) / 1000}s")
|
||||
// 超过重试窗口,删除本地订单(无论是否已部分卖出)
|
||||
val hasMatchedDetails = sellMatchDetailRepository.findByTrackingId(order.id!!).isNotEmpty()
|
||||
val hasPartialSold = hasMatchedDetails || order.matchedQuantity > BigDecimal.ZERO
|
||||
if (hasPartialSold) {
|
||||
logger.warn("订单详情为 null 且已部分卖出,超过重试窗口,删除本地订单: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, matchedQuantity=${order.matchedQuantity}, 已等待=$((currentTime - firstDetectionTime) / 1000}s")
|
||||
} else {
|
||||
logger.warn("订单详情为 null 超过重试窗口,删除本地订单: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}, 已等待=$((currentTime - firstDetectionTime) / 1000}s")
|
||||
}
|
||||
try {
|
||||
copyOrderTrackingRepository.deleteById(order.id!!)
|
||||
logger.info("已删除本地订单: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}")
|
||||
|
||||
@@ -98,8 +98,8 @@ class RpcNodeService(
|
||||
.filterNot { isDefaultNode(it) } // 排除默认节点
|
||||
|
||||
if (nodes.isEmpty()) {
|
||||
logger.warn("没有配置任何 RPC 节点,使用默认节点: $DEFAULT_RPC_URL")
|
||||
return Result.failure(IllegalStateException("没有配置任何 RPC 节点"))
|
||||
logger.warn("没有配置任何启用的 RPC 节点,将使用默认节点")
|
||||
return Result.success(createDefaultNodeConfig())
|
||||
}
|
||||
|
||||
// 优先使用最近检查状态为 HEALTHY 的节点
|
||||
@@ -136,39 +136,53 @@ class RpcNodeService(
|
||||
}
|
||||
}
|
||||
|
||||
// 所有节点都不可用,返回失败
|
||||
logger.warn("所有 RPC 节点都不可用,将使用默认节点: $DEFAULT_RPC_URL")
|
||||
Result.failure(IllegalStateException("所有 RPC 节点都不可用"))
|
||||
// 所有节点都不可用,返回默认节点
|
||||
logger.warn("所有启用的 RPC 节点都不可用,将使用默认节点: $DEFAULT_RPC_URL")
|
||||
Result.success(createDefaultNodeConfig())
|
||||
} catch (e: Exception) {
|
||||
logger.error("获取可用节点失败: ${e.message}", e)
|
||||
Result.failure(e)
|
||||
// 即使失败也返回默认节点,确保系统可用
|
||||
logger.warn("获取可用节点出现异常,使用默认节点作为兜底")
|
||||
Result.success(createDefaultNodeConfig())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建默认节点配置
|
||||
* 用于兜底,确保系统始终有可用的 RPC 节点
|
||||
*/
|
||||
private fun createDefaultNodeConfig(): RpcNodeConfig {
|
||||
return RpcNodeConfig(
|
||||
id = 0L,
|
||||
providerType = RpcProviderType.PUBLIC.name,
|
||||
name = "默认节点",
|
||||
httpUrl = DEFAULT_RPC_URL,
|
||||
wsUrl = DEFAULT_WS_URL,
|
||||
apiKey = null,
|
||||
enabled = true,
|
||||
priority = 9999,
|
||||
lastCheckTime = System.currentTimeMillis(),
|
||||
lastCheckStatus = NodeHealthStatus.HEALTHY.name,
|
||||
responseTimeMs = null,
|
||||
createdAt = System.currentTimeMillis(),
|
||||
updatedAt = System.currentTimeMillis()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点的 HTTP URL (如果没有配置,使用默认节点)
|
||||
*/
|
||||
fun getHttpUrl(): String {
|
||||
val nodeResult = getAvailableNode()
|
||||
return if (nodeResult.isSuccess) {
|
||||
nodeResult.getOrNull()?.httpUrl ?: DEFAULT_RPC_URL
|
||||
} else {
|
||||
logger.warn("没有可用的用户配置节点,使用默认节点")
|
||||
DEFAULT_RPC_URL
|
||||
}
|
||||
val node = getAvailableNode().getOrNull()
|
||||
return node?.httpUrl ?: DEFAULT_RPC_URL
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点的 WebSocket URL (如果没有配置,使用默认节点)
|
||||
*/
|
||||
fun getWsUrl(): String {
|
||||
val nodeResult = getAvailableNode()
|
||||
return if (nodeResult.isSuccess) {
|
||||
nodeResult.getOrNull()?.wsUrl ?: DEFAULT_WS_URL
|
||||
} else {
|
||||
logger.warn("没有可用的用户配置节点,使用默认 WS 节点")
|
||||
DEFAULT_WS_URL
|
||||
}
|
||||
val node = getAvailableNode().getOrNull()
|
||||
return node?.wsUrl ?: DEFAULT_WS_URL
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,6 +277,13 @@ class RpcNodeService(
|
||||
return Result.failure(IllegalArgumentException("默认节点不允许更新"))
|
||||
}
|
||||
|
||||
// 检查是否禁用节点,如果是则清理缓存
|
||||
val isDisabling = request.enabled == false && node.enabled == true
|
||||
if (isDisabling) {
|
||||
logger.info("节点被禁用,清理 RPC 缓存: ${node.httpUrl}")
|
||||
retrofitFactory.clearRpcApiCache(node.httpUrl)
|
||||
}
|
||||
|
||||
// 更新字段
|
||||
val updatedNode = node.copy(
|
||||
name = request.name ?: node.name,
|
||||
@@ -272,7 +293,7 @@ class RpcNodeService(
|
||||
)
|
||||
|
||||
val savedNode = rpcNodeConfigRepository.save(updatedNode)
|
||||
logger.info("成功更新 RPC 节点: ${savedNode.name}")
|
||||
logger.info("成功更新 RPC 节点: ${savedNode.name}, enabled=${savedNode.enabled}")
|
||||
Result.success(savedNode)
|
||||
} catch (e: Exception) {
|
||||
logger.error("更新节点失败: ${e.message}", e)
|
||||
@@ -295,6 +316,10 @@ class RpcNodeService(
|
||||
return Result.failure(IllegalArgumentException("默认节点不允许删除"))
|
||||
}
|
||||
|
||||
// 清理 RPC 缓存
|
||||
logger.info("删除节点,清理 RPC 缓存: ${node.httpUrl}")
|
||||
retrofitFactory.clearRpcApiCache(node.httpUrl)
|
||||
|
||||
rpcNodeConfigRepository.delete(node)
|
||||
logger.info("成功删除 RPC 节点: ${node.name}")
|
||||
Result.success(Unit)
|
||||
|
||||
@@ -84,5 +84,38 @@ object DateUtils {
|
||||
}
|
||||
return displayFormatter.format(instant)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将时间间隔(毫秒)格式化为可读的字符串
|
||||
* 格式:X天X小时X分钟 或 X小时X分钟 或 X分钟
|
||||
* 只显示有意义的单位,不显示0值单位
|
||||
*
|
||||
* @param milliseconds 时间间隔(毫秒)
|
||||
* @return 格式化的时间间隔字符串,如 "2天3小时15分钟"、"5小时30分钟"、"45分钟"
|
||||
*/
|
||||
fun formatDuration(milliseconds: Long): String {
|
||||
if (milliseconds < 0) {
|
||||
return "0分钟"
|
||||
}
|
||||
|
||||
val totalSeconds = milliseconds / 1000
|
||||
val days = totalSeconds / (24 * 60 * 60)
|
||||
val hours = (totalSeconds % (24 * 60 * 60)) / (60 * 60)
|
||||
val minutes = (totalSeconds % (60 * 60)) / 60
|
||||
|
||||
val parts = mutableListOf<String>()
|
||||
|
||||
if (days > 0) {
|
||||
parts.add("${days}天")
|
||||
}
|
||||
if (hours > 0) {
|
||||
parts.add("${hours}小时")
|
||||
}
|
||||
if (minutes > 0 || parts.isEmpty()) {
|
||||
parts.add("${minutes}分钟")
|
||||
}
|
||||
|
||||
return parts.joinToString("")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +168,10 @@ deploy() {
|
||||
|
||||
info "构建 Docker 镜像(本地构建,版本号: ${DOCKER_VERSION})..."
|
||||
|
||||
# 创建占位符目录(如果不存在),避免 Dockerfile COPY 失败
|
||||
# 当 BUILD_IN_DOCKER=true 时,backend/build 可能不存在
|
||||
mkdir -p backend/build/libs
|
||||
|
||||
# 设置构建参数(通过环境变量传递给 docker-compose.yml)
|
||||
export VERSION=${DOCKER_VERSION}
|
||||
export GIT_TAG=${DOCKER_VERSION}
|
||||
|
||||
+86
-10
@@ -331,10 +331,17 @@ def perform_update(target_version):
|
||||
# 7. 重启后端服务
|
||||
update_status['message'] = '重启后端服务...'
|
||||
logger.info("重启后端服务...")
|
||||
subprocess.Popen([
|
||||
|
||||
# 创建后端日志文件
|
||||
backend_log_file = LOG_FILE.parent / 'backend-update.log'
|
||||
backend_log = open(backend_log_file, 'w')
|
||||
|
||||
backend_process = subprocess.Popen([
|
||||
'java', '-jar', str(BACKEND_JAR),
|
||||
'--spring.profiles.active=prod'
|
||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
], stdout=backend_log, stderr=subprocess.STDOUT, start_new_session=True)
|
||||
|
||||
logger.info(f"后端进程已启动 (PID: {backend_process.pid})")
|
||||
|
||||
update_status['progress'] = 80
|
||||
|
||||
@@ -349,32 +356,101 @@ def perform_update(target_version):
|
||||
logger.info("等待后端服务启动...")
|
||||
|
||||
healthy = False
|
||||
for i in range(30):
|
||||
max_wait_time = 90 # 增加到90秒,给后端更多启动时间
|
||||
last_process_check = 0
|
||||
|
||||
for i in range(max_wait_time):
|
||||
# 每5秒检查一次进程状态
|
||||
if i - last_process_check >= 5:
|
||||
last_process_check = i
|
||||
if backend_process.poll() is not None:
|
||||
# 进程已退出
|
||||
backend_log.close()
|
||||
error_msg = ''
|
||||
try:
|
||||
with open(backend_log_file, 'r') as f:
|
||||
lines = f.readlines()
|
||||
error_msg = ''.join(lines[-50:]) # 读取最后50行
|
||||
except:
|
||||
pass
|
||||
|
||||
logger.error(f"后端进程异常退出(等待了 {i} 秒),退出码: {backend_process.returncode}")
|
||||
if error_msg:
|
||||
logger.error(f"后端日志最后50行:\n{error_msg}")
|
||||
raise Exception(f"后端服务启动失败,退出码: {backend_process.returncode}")
|
||||
else:
|
||||
logger.debug(f"后端进程仍在运行 (PID: {backend_process.pid})")
|
||||
|
||||
# 尝试健康检查
|
||||
try:
|
||||
response = requests.get(f'{BACKEND_URL}/api/system/health', timeout=2)
|
||||
if response.status_code == 200:
|
||||
healthy = True
|
||||
backend_log.close()
|
||||
logger.info(f"健康检查通过(等待了 {i+1} 秒)")
|
||||
break
|
||||
except:
|
||||
pass
|
||||
except requests.exceptions.ConnectionError:
|
||||
# 连接被拒绝,说明后端还没启动或端口未监听
|
||||
if i % 10 == 0 and i > 0: # 每10秒记录一次
|
||||
logger.debug(f"健康检查尝试 {i+1}/{max_wait_time}: 连接被拒绝(后端可能还在启动中)")
|
||||
except requests.exceptions.Timeout:
|
||||
# 超时
|
||||
if i % 10 == 0: # 每10秒记录一次
|
||||
logger.debug(f"健康检查尝试 {i+1}/{max_wait_time}: 请求超时")
|
||||
except Exception as e:
|
||||
logger.warning(f"健康检查异常: {e}")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
if not healthy:
|
||||
# 关闭日志文件并尝试读取错误信息
|
||||
backend_log.close()
|
||||
error_msg = ''
|
||||
try:
|
||||
with open(backend_log_file, 'r') as f:
|
||||
lines = f.readlines()
|
||||
error_msg = ''.join(lines[-100:]) # 读取最后100行
|
||||
except:
|
||||
pass
|
||||
|
||||
# 检查进程状态
|
||||
process_status = backend_process.poll()
|
||||
if process_status is None:
|
||||
# 进程还在运行,但健康检查失败
|
||||
logger.error(f"健康检查失败:后端进程仍在运行 (PID: {backend_process.pid}),但无法访问健康检查端点")
|
||||
logger.error("可能的原因:端口未监听、健康检查端点异常、或启动时间过长")
|
||||
else:
|
||||
# 进程已退出
|
||||
logger.error(f"健康检查失败:后端进程已退出,退出码: {process_status}")
|
||||
|
||||
if error_msg:
|
||||
logger.error(f"后端启动日志(最后100行):\n{error_msg}")
|
||||
|
||||
logger.error("健康检查失败,开始回滚...")
|
||||
update_status['message'] = '健康检查失败,回滚中...'
|
||||
|
||||
# 确保后端进程已停止
|
||||
try:
|
||||
backend_process.terminate()
|
||||
backend_process.wait(timeout=5)
|
||||
except:
|
||||
subprocess.run(['pkill', '-9', '-f', 'java.*app.jar'], check=False)
|
||||
|
||||
restore_backup(backup_dir)
|
||||
|
||||
# 重启后端
|
||||
subprocess.run(['pkill', '-f', 'java -jar'], check=False)
|
||||
time.sleep(1)
|
||||
# 等待一下再重启
|
||||
time.sleep(2)
|
||||
|
||||
# 重启后端(使用旧版本)
|
||||
logger.info("重启旧版本后端服务...")
|
||||
subprocess.Popen([
|
||||
'java', '-jar', str(BACKEND_JAR),
|
||||
'--spring.profiles.active=prod'
|
||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
|
||||
|
||||
subprocess.run(['nginx', '-s', 'reload'], check=True)
|
||||
|
||||
raise Exception("健康检查失败,已回滚到旧版本")
|
||||
raise Exception(f"健康检查失败(等待了 {max_wait_time} 秒),已回滚到旧版本。请查看日志文件 {backend_log_file} 了解详情")
|
||||
|
||||
update_status['progress'] = 100
|
||||
update_status['message'] = f'更新成功:{tag}'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useNavigate, useLocation } from 'react-router-dom'
|
||||
import { Layout as AntLayout, Menu, Drawer, Button, Modal } from 'antd'
|
||||
import { Layout as AntLayout, Menu, Drawer, Button, Modal, Tag } from 'antd'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useMediaQuery } from 'react-responsive'
|
||||
import {
|
||||
@@ -19,16 +19,37 @@ import {
|
||||
TwitterOutlined,
|
||||
CheckCircleOutlined,
|
||||
SendOutlined,
|
||||
ApiOutlined, NotificationOutlined
|
||||
ApiOutlined,
|
||||
NotificationOutlined
|
||||
} from '@ant-design/icons'
|
||||
import type { MenuProps } from 'antd'
|
||||
import type { ReactNode } from 'react'
|
||||
import { removeToken, getVersionText, getGitHubTagUrl } from '../utils'
|
||||
import { removeToken, getVersionText, getVersionInfo } from '../utils'
|
||||
import { wsManager } from '../services/websocket'
|
||||
import { apiClient } from '../services/api'
|
||||
import Logo from './Logo'
|
||||
|
||||
const { Header, Content, Sider } = AntLayout
|
||||
|
||||
// 添加动画样式
|
||||
const style = document.createElement('style')
|
||||
style.textContent = `
|
||||
@keyframes versionUpdatePulse {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
opacity: 0.7;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
`
|
||||
if (!document.head.querySelector('style[data-version-update-animation]')) {
|
||||
style.setAttribute('data-version-update-animation', 'true')
|
||||
document.head.appendChild(style)
|
||||
}
|
||||
|
||||
interface LayoutProps {
|
||||
children: ReactNode
|
||||
}
|
||||
@@ -39,6 +60,7 @@ const Layout: React.FC<LayoutProps> = ({ children }) => {
|
||||
const location = useLocation()
|
||||
const isMobile = useMediaQuery({ maxWidth: 768 })
|
||||
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
|
||||
const [hasUpdate, setHasUpdate] = useState(false)
|
||||
|
||||
// 获取当前选中的菜单项
|
||||
const getSelectedKeys = (): string[] => {
|
||||
@@ -72,6 +94,29 @@ const Layout: React.FC<LayoutProps> = ({ children }) => {
|
||||
}
|
||||
setOpenKeys(keys)
|
||||
}, [location.pathname])
|
||||
|
||||
// 检查是否有新版本
|
||||
useEffect(() => {
|
||||
const checkUpdate = async () => {
|
||||
try {
|
||||
const response = await apiClient.get('/update/check')
|
||||
if (response.data.code === 0 && response.data.data) {
|
||||
setHasUpdate(response.data.data.hasUpdate || false)
|
||||
}
|
||||
} catch (error) {
|
||||
// 静默失败,不影响页面使用
|
||||
console.debug('检查更新失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载时检查一次
|
||||
checkUpdate()
|
||||
|
||||
// 每5分钟检查一次
|
||||
const interval = setInterval(checkUpdate, 5 * 60 * 1000)
|
||||
|
||||
return () => clearInterval(interval)
|
||||
}, [])
|
||||
|
||||
const menuItems: MenuProps['items'] = [
|
||||
{
|
||||
@@ -210,27 +255,32 @@ const Layout: React.FC<LayoutProps> = ({ children }) => {
|
||||
size="normal"
|
||||
darkMode={true}
|
||||
/>
|
||||
<a
|
||||
href={getGitHubTagUrl()}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
onClick={(e) => {
|
||||
const version = getVersionText()
|
||||
if (version === 'dev') {
|
||||
e.preventDefault()
|
||||
<Tag
|
||||
color={hasUpdate ? 'warning' : 'success'}
|
||||
onClick={() => {
|
||||
if (hasUpdate) {
|
||||
navigate('/system-settings')
|
||||
}
|
||||
}}
|
||||
bordered={false}
|
||||
style={{
|
||||
color: 'rgba(255, 255, 255, 0.7)',
|
||||
fontSize: '12px',
|
||||
fontWeight: 'normal',
|
||||
textDecoration: 'none',
|
||||
cursor: getVersionText() === 'dev' ? 'default' : 'pointer'
|
||||
cursor: hasUpdate ? 'pointer' : 'default',
|
||||
fontSize: '8px',
|
||||
padding: '1px 6px',
|
||||
margin: 0,
|
||||
background: 'transparent',
|
||||
border: `1px solid ${hasUpdate ? '#faad14' : '#52c41a'}`,
|
||||
borderRadius: '4px',
|
||||
color: hasUpdate ? '#faad14' : '#52c41a',
|
||||
lineHeight: '1.4',
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
verticalAlign: 'middle'
|
||||
}}
|
||||
title={getVersionText() === 'dev' ? '' : '查看版本发布'}
|
||||
title={hasUpdate ? '有新版本可用,点击前往系统更新' : '当前已是最新版本'}
|
||||
>
|
||||
v{getVersionText()}
|
||||
</a>
|
||||
{getVersionInfo().gitTag || `v${getVersionText()}`}
|
||||
</Tag>
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
||||
<a
|
||||
@@ -322,34 +372,37 @@ const Layout: React.FC<LayoutProps> = ({ children }) => {
|
||||
marginBottom: '12px',
|
||||
textAlign: 'center',
|
||||
display: 'flex',
|
||||
alignItems: 'flex-end',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
gap: '6px'
|
||||
}}>
|
||||
<span>PolyHermes</span>
|
||||
<a
|
||||
href={getGitHubTagUrl()}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
onClick={(e) => {
|
||||
const version = getVersionText()
|
||||
if (version === 'dev') {
|
||||
e.preventDefault()
|
||||
<Tag
|
||||
color={hasUpdate ? 'warning' : 'success'}
|
||||
onClick={() => {
|
||||
if (hasUpdate) {
|
||||
navigate('/system-settings')
|
||||
}
|
||||
}}
|
||||
bordered={false}
|
||||
style={{
|
||||
color: 'rgba(255, 255, 255, 0.7)',
|
||||
fontSize: '12px',
|
||||
fontWeight: 'normal',
|
||||
textDecoration: 'none',
|
||||
cursor: getVersionText() === 'dev' ? 'default' : 'pointer',
|
||||
lineHeight: '1',
|
||||
paddingBottom: '2px'
|
||||
cursor: hasUpdate ? 'pointer' : 'default',
|
||||
fontSize: '8px',
|
||||
padding: '1px 6px',
|
||||
margin: 0,
|
||||
background: 'transparent',
|
||||
border: `1px solid ${hasUpdate ? '#faad14' : '#52c41a'}`,
|
||||
borderRadius: '4px',
|
||||
color: hasUpdate ? '#faad14' : '#52c41a',
|
||||
lineHeight: '1.4',
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
verticalAlign: 'middle'
|
||||
}}
|
||||
title={getVersionText() === 'dev' ? '' : '查看版本发布'}
|
||||
title={hasUpdate ? '有新版本可用,点击前往系统更新' : '当前已是最新版本'}
|
||||
>
|
||||
v{getVersionText()}
|
||||
</a>
|
||||
{getVersionInfo().gitTag || `v${getVersionText()}`}
|
||||
</Tag>
|
||||
</div>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
|
||||
@@ -938,7 +938,8 @@
|
||||
"marketEndDate": "Market End Date Exceeds Limit",
|
||||
"unknown": "Unknown Reason"
|
||||
},
|
||||
"noData": "No filtered orders"
|
||||
"noData": "No filtered orders",
|
||||
"noFilteredOrders": "No filtered orders"
|
||||
},
|
||||
"copyTradingList": {
|
||||
"title": "Copy Trading Config Management",
|
||||
|
||||
@@ -938,7 +938,8 @@
|
||||
"marketEndDate": "市场截止时间超出限制",
|
||||
"unknown": "未知原因"
|
||||
},
|
||||
"noData": "暂无已过滤订单"
|
||||
"noData": "暂无已过滤订单",
|
||||
"noFilteredOrders": "暂无已过滤订单"
|
||||
},
|
||||
"copyTradingList": {
|
||||
"title": "跟单配置管理",
|
||||
@@ -1116,6 +1117,8 @@
|
||||
"orderCount": "订单数",
|
||||
"totalAmount": "总金额",
|
||||
"statusBreakdown": "状态",
|
||||
"allFullyMatched": "全部卖出",
|
||||
"partiallyMatched": "部分卖出",
|
||||
"markets": "个市场",
|
||||
"fetchBuyOrdersFailed": "获取买入订单列表失败",
|
||||
"fetchSellOrdersFailed": "获取卖出订单列表失败",
|
||||
|
||||
@@ -938,7 +938,8 @@
|
||||
"marketEndDate": "市場截止時間超出限制",
|
||||
"unknown": "未知原因"
|
||||
},
|
||||
"noData": "暫無已過濾訂單"
|
||||
"noData": "暫無已過濾訂單",
|
||||
"noFilteredOrders": "暫無已過濾訂單"
|
||||
},
|
||||
"copyTradingList": {
|
||||
"title": "跟單配置管理",
|
||||
@@ -1115,8 +1116,10 @@
|
||||
"partiallySold": "部分賣出",
|
||||
"orderCount": "訂單數",
|
||||
"totalAmount": "總金額",
|
||||
"totalPnl": "總盈虧",
|
||||
"statusBreakdown": "狀態",
|
||||
"allFullyMatched": "全部賣出",
|
||||
"partiallyMatched": "部分賣出",
|
||||
"totalPnl": "總盈虧",
|
||||
"markets": "個市場",
|
||||
"fetchBuyOrdersFailed": "獲取買入訂單列表失敗",
|
||||
"fetchSellOrdersFailed": "獲取賣出訂單列表失敗",
|
||||
|
||||
@@ -495,6 +495,9 @@ const SystemSettings: React.FC = () => {
|
||||
<Title level={2} style={{ margin: 0 }}>{t('systemSettings.title') || '通用设置'}</Title>
|
||||
</div>
|
||||
|
||||
{/* 系统更新 */}
|
||||
<SystemUpdate />
|
||||
|
||||
{/* 第一部分:多语言 */}
|
||||
<Card
|
||||
title={
|
||||
@@ -890,9 +893,6 @@ const SystemSettings: React.FC = () => {
|
||||
)}
|
||||
|
||||
</Card>
|
||||
|
||||
{/* 第五部分:系统更新 */}
|
||||
<SystemUpdate />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Card, Button, Spin, Progress, Alert, Space, Typography, Divider, Tag, Modal, message } from 'antd'
|
||||
import { Card, Button, Spin, Progress, Alert, Space, Tag, Modal, message } from 'antd'
|
||||
import {
|
||||
CloudUploadOutlined,
|
||||
ReloadOutlined,
|
||||
CheckCircleOutlined,
|
||||
ExclamationCircleOutlined,
|
||||
InfoCircleOutlined
|
||||
ExclamationCircleOutlined
|
||||
} from '@ant-design/icons'
|
||||
import { apiClient } from '../services/api'
|
||||
import ReactMarkdown from 'react-markdown'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
|
||||
const { Title, Text, Paragraph } = Typography
|
||||
|
||||
interface UpdateInfo {
|
||||
hasUpdate: boolean
|
||||
@@ -113,7 +113,7 @@ const SystemUpdate: React.FC = () => {
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
try {
|
||||
const response = await apiClient.post('/update/execute', {})
|
||||
const response = await apiClient.post('/update/update', {})
|
||||
const data = response.data
|
||||
|
||||
if (data.code === 0) {
|
||||
@@ -172,145 +172,302 @@ const SystemUpdate: React.FC = () => {
|
||||
<Card
|
||||
title={
|
||||
<Space>
|
||||
<CloudUploadOutlined />
|
||||
<span>系统更新</span>
|
||||
<CloudUploadOutlined style={{ fontSize: '18px', color: '#1890ff' }} />
|
||||
<span style={{ fontSize: '16px', fontWeight: 600 }}>系统更新</span>
|
||||
</Space>
|
||||
}
|
||||
style={{ marginBottom: '16px' }}
|
||||
style={{
|
||||
marginBottom: '16px',
|
||||
borderRadius: '8px',
|
||||
boxShadow: '0 2px 8px rgba(0,0,0,0.06)'
|
||||
}}
|
||||
>
|
||||
<Space direction="vertical" style={{ width: '100%' }} size="large">
|
||||
{/* 当前版本信息 */}
|
||||
<div>
|
||||
<Title level={5}>当前版本</Title>
|
||||
<Space>
|
||||
<Tag color="blue" style={{ fontSize: '14px', padding: '4px 12px' }}>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
padding: '16px',
|
||||
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
|
||||
borderRadius: '8px',
|
||||
color: '#fff'
|
||||
}}>
|
||||
<div>
|
||||
<div style={{ fontSize: '13px', opacity: 0.9, marginBottom: '4px' }}>
|
||||
当前版本
|
||||
</div>
|
||||
<div style={{ fontSize: '20px', fontWeight: 600 }}>
|
||||
v{currentVersion || 'unknown'}
|
||||
</Tag>
|
||||
</Space>
|
||||
</div>
|
||||
</div>
|
||||
<CheckCircleOutlined style={{ fontSize: '32px', opacity: 0.8 }} />
|
||||
</div>
|
||||
|
||||
<Divider />
|
||||
|
||||
{/* 更新状态 */}
|
||||
{updateStatus.updating && (
|
||||
<Alert
|
||||
message="系统正在更新"
|
||||
message={
|
||||
<span style={{ fontSize: '15px', fontWeight: 500 }}>系统正在更新</span>
|
||||
}
|
||||
description={
|
||||
<div>
|
||||
<p>{updateStatus.message}</p>
|
||||
<div style={{ marginTop: '12px' }}>
|
||||
<div style={{
|
||||
marginBottom: '12px',
|
||||
fontSize: '14px',
|
||||
color: '#595959'
|
||||
}}>
|
||||
{updateStatus.message}
|
||||
</div>
|
||||
<Progress
|
||||
percent={updateStatus.progress}
|
||||
status="active"
|
||||
strokeColor={{ '0%': '#108ee9', '100%': '#87d068' }}
|
||||
strokeColor={{
|
||||
'0%': '#667eea',
|
||||
'50%': '#764ba2',
|
||||
'100%': '#f093fb'
|
||||
}}
|
||||
strokeWidth={8}
|
||||
showInfo
|
||||
format={(percent) => `${percent}%`}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
type="info"
|
||||
showIcon
|
||||
icon={<Spin />}
|
||||
style={{
|
||||
borderRadius: '8px',
|
||||
border: '1px solid #91d5ff'
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{updateStatus.error && (
|
||||
<Alert
|
||||
message="更新失败"
|
||||
description={updateStatus.error}
|
||||
message={<span style={{ fontSize: '15px', fontWeight: 500 }}>更新失败</span>}
|
||||
description={
|
||||
<div style={{
|
||||
marginTop: '8px',
|
||||
fontSize: '14px',
|
||||
color: '#595959'
|
||||
}}>
|
||||
{updateStatus.error}
|
||||
</div>
|
||||
}
|
||||
type="error"
|
||||
showIcon
|
||||
closable
|
||||
onClose={() => setUpdateStatus(prev => ({ ...prev, error: null }))}
|
||||
style={{
|
||||
borderRadius: '8px'
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 检查更新 */}
|
||||
{!updateStatus.updating && (
|
||||
<Space>
|
||||
<div>
|
||||
<Button
|
||||
type="primary"
|
||||
size="large"
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={handleCheckUpdate}
|
||||
loading={updateChecking}
|
||||
style={{
|
||||
height: '40px',
|
||||
borderRadius: '6px',
|
||||
fontWeight: 500,
|
||||
boxShadow: '0 2px 4px rgba(24, 144, 255, 0.2)'
|
||||
}}
|
||||
>
|
||||
检查更新
|
||||
</Button>
|
||||
|
||||
{updateInfo && !updateInfo.hasUpdate && (
|
||||
<Alert
|
||||
message="当前已是最新版本"
|
||||
message={
|
||||
<span style={{ fontSize: '15px', fontWeight: 500 }}>
|
||||
当前已是最新版本
|
||||
</span>
|
||||
}
|
||||
type="success"
|
||||
showIcon
|
||||
icon={<CheckCircleOutlined />}
|
||||
style={{
|
||||
marginTop: '12px',
|
||||
borderRadius: '8px',
|
||||
border: '1px solid #b7eb8f'
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Space>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 更新信息 */}
|
||||
{updateInfo && updateInfo.hasUpdate && !updateStatus.updating && (
|
||||
<Alert
|
||||
message={
|
||||
<Space>
|
||||
<span>发现新版本:</span>
|
||||
<Tag color="green" style={{ fontSize: '14px' }}>
|
||||
v{updateInfo.latestVersion}
|
||||
</Tag>
|
||||
{updateInfo.prerelease && (
|
||||
<Tag color="orange">Pre-release</Tag>
|
||||
)}
|
||||
</Space>
|
||||
}
|
||||
description={
|
||||
<div style={{ marginTop: '12px' }}>
|
||||
<Paragraph>
|
||||
<Text strong>发布时间:</Text>
|
||||
<Text type="secondary">{formatDate(updateInfo.publishedAt)}</Text>
|
||||
</Paragraph>
|
||||
|
||||
{updateInfo.releaseNotes && (
|
||||
<div>
|
||||
<Text strong>更新内容:</Text>
|
||||
<div style={{
|
||||
marginTop: '8px',
|
||||
padding: '12px',
|
||||
background: '#f5f5f5',
|
||||
borderRadius: '4px',
|
||||
maxHeight: '200px',
|
||||
overflowY: 'auto'
|
||||
}}>
|
||||
<pre style={{
|
||||
margin: 0,
|
||||
whiteSpace: 'pre-wrap',
|
||||
fontFamily: 'inherit'
|
||||
}}>
|
||||
{updateInfo.releaseNotes}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div style={{ marginTop: '16px' }}>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<CloudUploadOutlined />}
|
||||
onClick={handleExecuteUpdate}
|
||||
<div style={{
|
||||
padding: '20px',
|
||||
background: 'linear-gradient(135deg, #fff5f5 0%, #fff1f0 100%)',
|
||||
borderRadius: '8px',
|
||||
border: '1px solid #ffccc7'
|
||||
}}>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
marginBottom: '16px',
|
||||
paddingBottom: '16px',
|
||||
borderBottom: '1px solid #ffccc7'
|
||||
}}>
|
||||
<div>
|
||||
<div style={{
|
||||
fontSize: '13px',
|
||||
color: '#8c8c8c',
|
||||
marginBottom: '6px'
|
||||
}}>
|
||||
发现新版本
|
||||
</div>
|
||||
<Space size="small">
|
||||
<Tag
|
||||
color="success"
|
||||
style={{
|
||||
fontSize: '16px',
|
||||
padding: '4px 16px',
|
||||
fontWeight: 600,
|
||||
borderRadius: '4px'
|
||||
}}
|
||||
>
|
||||
立即升级
|
||||
</Button>
|
||||
v{updateInfo.latestVersion}
|
||||
</Tag>
|
||||
{updateInfo.prerelease && (
|
||||
<Tag
|
||||
color="orange"
|
||||
style={{
|
||||
fontSize: '12px',
|
||||
padding: '4px 12px',
|
||||
borderRadius: '4px'
|
||||
}}
|
||||
>
|
||||
Pre-release
|
||||
</Tag>
|
||||
)}
|
||||
</Space>
|
||||
</div>
|
||||
<CloudUploadOutlined style={{
|
||||
fontSize: '32px',
|
||||
color: '#ff4d4f',
|
||||
opacity: 0.8
|
||||
}} />
|
||||
</div>
|
||||
|
||||
<div style={{ marginBottom: '16px' }}>
|
||||
<div style={{
|
||||
fontSize: '13px',
|
||||
color: '#8c8c8c',
|
||||
marginBottom: '4px'
|
||||
}}>
|
||||
发布时间
|
||||
</div>
|
||||
<div style={{
|
||||
fontSize: '14px',
|
||||
color: '#595959'
|
||||
}}>
|
||||
{formatDate(updateInfo.publishedAt)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{updateInfo.releaseNotes && (
|
||||
<div style={{ marginBottom: '20px' }}>
|
||||
<div style={{
|
||||
fontSize: '13px',
|
||||
color: '#8c8c8c',
|
||||
marginBottom: '8px',
|
||||
fontWeight: 500
|
||||
}}>
|
||||
更新内容
|
||||
</div>
|
||||
<div style={{
|
||||
padding: '16px',
|
||||
background: '#fff',
|
||||
borderRadius: '6px',
|
||||
border: '1px solid #e8e8e8',
|
||||
maxHeight: '500px',
|
||||
overflowY: 'auto',
|
||||
lineHeight: '1.6',
|
||||
boxShadow: 'inset 0 1px 2px rgba(0,0,0,0.06)'
|
||||
}}>
|
||||
<div style={{
|
||||
color: '#262626',
|
||||
fontSize: '14px'
|
||||
}}>
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
components={{
|
||||
h1: ({node, ...props}) => <h1 style={{ fontSize: '20px', fontWeight: 600, marginTop: '16px', marginBottom: '12px', color: '#262626', borderBottom: '2px solid #e8e8e8', paddingBottom: '8px' }} {...props} />,
|
||||
h2: ({node, ...props}) => <h2 style={{ fontSize: '18px', fontWeight: 600, marginTop: '16px', marginBottom: '10px', color: '#262626' }} {...props} />,
|
||||
h3: ({node, ...props}) => <h3 style={{ fontSize: '16px', fontWeight: 600, marginTop: '14px', marginBottom: '8px', color: '#262626' }} {...props} />,
|
||||
h4: ({node, ...props}) => <h4 style={{ fontSize: '15px', fontWeight: 600, marginTop: '12px', marginBottom: '6px', color: '#262626' }} {...props} />,
|
||||
p: ({node, ...props}) => <p style={{ marginBottom: '12px', color: '#595959' }} {...props} />,
|
||||
ul: ({node, ...props}) => <ul style={{ marginBottom: '12px', paddingLeft: '24px', color: '#595959' }} {...props} />,
|
||||
ol: ({node, ...props}) => <ol style={{ marginBottom: '12px', paddingLeft: '24px', color: '#595959' }} {...props} />,
|
||||
li: ({node, ...props}) => <li style={{ marginBottom: '6px', lineHeight: '1.6' }} {...props} />,
|
||||
code: ({node, inline, ...props}: any) =>
|
||||
inline
|
||||
? <code style={{ background: '#f0f0f0', padding: '2px 6px', borderRadius: '3px', fontSize: '13px', fontFamily: 'Monaco, Menlo, "Ubuntu Mono", Consolas, monospace', color: '#d73a49' }} {...props} />
|
||||
: <code style={{ display: 'block', background: '#282c34', color: '#abb2bf', padding: '12px', borderRadius: '4px', overflowX: 'auto', fontSize: '13px', fontFamily: 'Monaco, Menlo, "Ubuntu Mono", Consolas, monospace', marginBottom: '12px', lineHeight: '1.5' }} {...props} />,
|
||||
pre: ({node, ...props}) => <pre style={{ background: '#282c34', borderRadius: '4px', padding: '12px', overflowX: 'auto', marginBottom: '12px' }} {...props} />,
|
||||
blockquote: ({node, ...props}) => <blockquote style={{ borderLeft: '4px solid #1890ff', paddingLeft: '12px', margin: '12px 0', color: '#8c8c8c', fontStyle: 'italic' }} {...props} />,
|
||||
a: ({node, ...props}) => <a style={{ color: '#1890ff', textDecoration: 'none' }} target="_blank" rel="noopener noreferrer" {...props} />,
|
||||
strong: ({node, ...props}) => <strong style={{ fontWeight: 600, color: '#262626' }} {...props} />,
|
||||
table: ({node, ...props}) => <table style={{ width: '100%', borderCollapse: 'collapse', marginBottom: '12px' }} {...props} />,
|
||||
th: ({node, ...props}) => <th style={{ border: '1px solid #e8e8e8', padding: '8px 12px', background: '#fafafa', fontWeight: 600, textAlign: 'left' }} {...props} />,
|
||||
td: ({node, ...props}) => <td style={{ border: '1px solid #e8e8e8', padding: '8px 12px' }} {...props} />,
|
||||
hr: ({node, ...props}) => <hr style={{ border: 'none', borderTop: '1px solid #e8e8e8', margin: '16px 0' }} {...props} />
|
||||
}}
|
||||
>
|
||||
{updateInfo.releaseNotes}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
type="warning"
|
||||
showIcon
|
||||
icon={<InfoCircleOutlined />}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Button
|
||||
type="primary"
|
||||
size="large"
|
||||
icon={<CloudUploadOutlined />}
|
||||
onClick={handleExecuteUpdate}
|
||||
block
|
||||
style={{
|
||||
height: '44px',
|
||||
borderRadius: '6px',
|
||||
fontWeight: 500,
|
||||
fontSize: '15px',
|
||||
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
|
||||
border: 'none',
|
||||
boxShadow: '0 4px 12px rgba(102, 126, 234, 0.4)'
|
||||
}}
|
||||
>
|
||||
立即升级到 v{updateInfo.latestVersion}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 使用提示 */}
|
||||
{!updateStatus.updating && (
|
||||
{!updateStatus.updating && !(updateInfo && updateInfo.hasUpdate) && (
|
||||
<Alert
|
||||
message="使用说明"
|
||||
message={
|
||||
<span style={{ fontSize: '15px', fontWeight: 500 }}>使用说明</span>
|
||||
}
|
||||
description={
|
||||
<ul style={{ marginBottom: 0, paddingLeft: '20px' }}>
|
||||
<ul style={{
|
||||
marginBottom: 0,
|
||||
paddingLeft: '20px',
|
||||
fontSize: '14px',
|
||||
color: '#595959',
|
||||
lineHeight: '1.8'
|
||||
}}>
|
||||
<li>点击"检查更新"按钮检查是否有新版本</li>
|
||||
<li>更新过程约需30-60秒,期间系统将暂时不可用</li>
|
||||
<li>更新成功后页面将自动刷新</li>
|
||||
@@ -319,6 +476,10 @@ const SystemUpdate: React.FC = () => {
|
||||
}
|
||||
type="info"
|
||||
showIcon
|
||||
style={{
|
||||
borderRadius: '8px',
|
||||
border: '1px solid #91d5ff'
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Space>
|
||||
|
||||
Reference in New Issue
Block a user