From 9b576de069d98cbbc46816de069dfe5830c6c0fe Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Wed, 25 Mar 2026 07:52:13 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AD=96=E7=95=A5=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. GetPortfolioDetailAsync: 移除硬编码逻辑模型信息 - 根据策略ID从数据库读取真实策略信息 - 无策略时返回 null,前端显示'未绑定策略' 2. GetStrategies: 修复返回格式 - 改为返回 { items: [...] } 格式,匹配前端期望 - 修复 StrategyListResponse.Items 类型为 StrategyListItemDto --- .../Controllers/StrategyController.cs | 10 ++--- AssetManager.Models/DTOs/StrategyDTO.cs | 2 +- AssetManager.Services/PortfolioService.cs | 41 ++++++++++++++----- sql/fix_strategy_id_nullable.sql | 7 ++++ 4 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 sql/fix_strategy_id_nullable.sql diff --git a/AssetManager.API/Controllers/StrategyController.cs b/AssetManager.API/Controllers/StrategyController.cs index 4b1f994..1d5bd60 100755 --- a/AssetManager.API/Controllers/StrategyController.cs +++ b/AssetManager.API/Controllers/StrategyController.cs @@ -64,7 +64,7 @@ public class StrategyController : ControllerBase /// 此接口用于获取当前登录用户的所有策略列表。 /// [HttpGet("strategies")] - public ActionResult>> GetStrategies() + public ActionResult> GetStrategies() { try { @@ -74,12 +74,12 @@ public class StrategyController : ControllerBase var strategies = _strategyService.GetStrategies(userId); var strategyListItems = strategies.Select(MapToStrategyListItemDTO).ToList(); - _logger.LogInformation("Strategies retrieved successfully"); + _logger.LogInformation("Strategies retrieved successfully, count: {Count}", strategyListItems.Count); - return Ok(new ApiResponse> + return Ok(new ApiResponse { code = AssetManager.Models.StatusCodes.Success, - data = strategyListItems, + data = new StrategyListResponse { Items = strategyListItems }, message = "Success" }); } @@ -87,7 +87,7 @@ public class StrategyController : ControllerBase { _logger.LogError(ex, "Error retrieving strategies"); - return StatusCode(AssetManager.Models.StatusCodes.InternalServerError, new ApiResponse> + return StatusCode(AssetManager.Models.StatusCodes.InternalServerError, new ApiResponse { code = AssetManager.Models.StatusCodes.InternalServerError, data = null, diff --git a/AssetManager.Models/DTOs/StrategyDTO.cs b/AssetManager.Models/DTOs/StrategyDTO.cs index eaabcb0..a231017 100755 --- a/AssetManager.Models/DTOs/StrategyDTO.cs +++ b/AssetManager.Models/DTOs/StrategyDTO.cs @@ -5,7 +5,7 @@ namespace AssetManager.Models.DTOs; /// public class StrategyListResponse { - public List? Items { get; set; } + public List? Items { get; set; } } /// diff --git a/AssetManager.Services/PortfolioService.cs b/AssetManager.Services/PortfolioService.cs index 50541db..cef0636 100755 --- a/AssetManager.Services/PortfolioService.cs +++ b/AssetManager.Services/PortfolioService.cs @@ -550,27 +550,48 @@ public class PortfolioService : IPortfolioService decimal TotalReturn = totalPortfolioValue - totalCost; double totalReturnRate = totalCost > 0 ? (double)(TotalReturn / totalCost * 100) : 0; + // 获取策略信息(如果有的话) + StrategyInfo? strategyInfo = null; + string? logicModel = null; + string? logicModelStatus = null; + string? logicModelDescription = null; + + if (!string.IsNullOrEmpty(portfolio.StrategyId)) + { + var strategy = _db.Queryable() + .Where(s => s.Id == portfolio.StrategyId) + .First(); + + if (strategy != null) + { + strategyInfo = new StrategyInfo + { + Id = strategy.Id, + Name = strategy.Name, + Description = strategy.Description + }; + logicModel = strategy.Name; + logicModelStatus = "监控中"; + logicModelDescription = strategy.Description; + } + } + return new PortfolioDetailResponse { Id = portfolio.Id, Name = portfolio.Name, Currency = targetCurrency, Status = portfolio.Status, - Strategy = new StrategyInfo - { - Id = portfolio.StrategyId, - Name = "策略名称", - Description = "策略描述" - }, + Strategy = strategyInfo, PortfolioValue = (double)totalPortfolioValue, TotalReturn = (double)TotalReturn, TodayProfit = (double)totalTodayProfit, HistoricalChange = totalReturnRate, - DailyVolatility = 0, // 后续实现 + DailyVolatility = 0, TodayProfitCurrency = targetCurrency, - LogicModel = "HFEA 风险平价逻辑", - LogicModelStatus = "监控中", - LogicModelDescription = "目标权重 季度调仓", + LogicModel = logicModel, + LogicModelStatus = logicModelStatus, + LogicModelDescription = logicModelDescription, TotalItems = Positions.Count, TotalRatio = 100.0, Positions = positionItems diff --git a/sql/fix_strategy_id_nullable.sql b/sql/fix_strategy_id_nullable.sql new file mode 100644 index 0000000..6d319c2 --- /dev/null +++ b/sql/fix_strategy_id_nullable.sql @@ -0,0 +1,7 @@ +-- 修改 portfolios 表 strategy_id 字段允许 NULL +-- 组合可能不使用任何策略,所以应该允许 NULL + +ALTER TABLE portfolios MODIFY COLUMN strategy_id VARCHAR(50) NULL; + +-- 验证 +DESCRIBE portfolios;