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;