fix: 策略相关修复
1. GetPortfolioDetailAsync: 移除硬编码逻辑模型信息
- 根据策略ID从数据库读取真实策略信息
- 无策略时返回 null,前端显示'未绑定策略'
2. GetStrategies: 修复返回格式
- 改为返回 { items: [...] } 格式,匹配前端期望
- 修复 StrategyListResponse.Items 类型为 StrategyListItemDto
This commit is contained in:
parent
7d37ef5561
commit
9b576de069
@ -64,7 +64,7 @@ public class StrategyController : ControllerBase
|
|||||||
/// 此接口用于获取当前登录用户的所有策略列表。
|
/// 此接口用于获取当前登录用户的所有策略列表。
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[HttpGet("strategies")]
|
[HttpGet("strategies")]
|
||||||
public ActionResult<ApiResponse<List<StrategyListItemDto>>> GetStrategies()
|
public ActionResult<ApiResponse<StrategyListResponse>> GetStrategies()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -74,12 +74,12 @@ public class StrategyController : ControllerBase
|
|||||||
var strategies = _strategyService.GetStrategies(userId);
|
var strategies = _strategyService.GetStrategies(userId);
|
||||||
var strategyListItems = strategies.Select(MapToStrategyListItemDTO).ToList();
|
var strategyListItems = strategies.Select(MapToStrategyListItemDTO).ToList();
|
||||||
|
|
||||||
_logger.LogInformation("Strategies retrieved successfully");
|
_logger.LogInformation("Strategies retrieved successfully, count: {Count}", strategyListItems.Count);
|
||||||
|
|
||||||
return Ok(new ApiResponse<List<StrategyListItemDto>>
|
return Ok(new ApiResponse<StrategyListResponse>
|
||||||
{
|
{
|
||||||
code = AssetManager.Models.StatusCodes.Success,
|
code = AssetManager.Models.StatusCodes.Success,
|
||||||
data = strategyListItems,
|
data = new StrategyListResponse { Items = strategyListItems },
|
||||||
message = "Success"
|
message = "Success"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ public class StrategyController : ControllerBase
|
|||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error retrieving strategies");
|
_logger.LogError(ex, "Error retrieving strategies");
|
||||||
|
|
||||||
return StatusCode(AssetManager.Models.StatusCodes.InternalServerError, new ApiResponse<List<StrategyListItemDto>>
|
return StatusCode(AssetManager.Models.StatusCodes.InternalServerError, new ApiResponse<StrategyListResponse>
|
||||||
{
|
{
|
||||||
code = AssetManager.Models.StatusCodes.InternalServerError,
|
code = AssetManager.Models.StatusCodes.InternalServerError,
|
||||||
data = null,
|
data = null,
|
||||||
|
|||||||
@ -5,7 +5,7 @@ namespace AssetManager.Models.DTOs;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class StrategyListResponse
|
public class StrategyListResponse
|
||||||
{
|
{
|
||||||
public List<StrategyItem>? Items { get; set; }
|
public List<StrategyListItemDto>? Items { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -550,27 +550,48 @@ public class PortfolioService : IPortfolioService
|
|||||||
decimal TotalReturn = totalPortfolioValue - totalCost;
|
decimal TotalReturn = totalPortfolioValue - totalCost;
|
||||||
double totalReturnRate = totalCost > 0 ? (double)(TotalReturn / totalCost * 100) : 0;
|
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<Strategy>()
|
||||||
|
.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
|
return new PortfolioDetailResponse
|
||||||
{
|
{
|
||||||
Id = portfolio.Id,
|
Id = portfolio.Id,
|
||||||
Name = portfolio.Name,
|
Name = portfolio.Name,
|
||||||
Currency = targetCurrency,
|
Currency = targetCurrency,
|
||||||
Status = portfolio.Status,
|
Status = portfolio.Status,
|
||||||
Strategy = new StrategyInfo
|
Strategy = strategyInfo,
|
||||||
{
|
|
||||||
Id = portfolio.StrategyId,
|
|
||||||
Name = "策略名称",
|
|
||||||
Description = "策略描述"
|
|
||||||
},
|
|
||||||
PortfolioValue = (double)totalPortfolioValue,
|
PortfolioValue = (double)totalPortfolioValue,
|
||||||
TotalReturn = (double)TotalReturn,
|
TotalReturn = (double)TotalReturn,
|
||||||
TodayProfit = (double)totalTodayProfit,
|
TodayProfit = (double)totalTodayProfit,
|
||||||
HistoricalChange = totalReturnRate,
|
HistoricalChange = totalReturnRate,
|
||||||
DailyVolatility = 0, // 后续实现
|
DailyVolatility = 0,
|
||||||
TodayProfitCurrency = targetCurrency,
|
TodayProfitCurrency = targetCurrency,
|
||||||
LogicModel = "HFEA 风险平价逻辑",
|
LogicModel = logicModel,
|
||||||
LogicModelStatus = "监控中",
|
LogicModelStatus = logicModelStatus,
|
||||||
LogicModelDescription = "目标权重 季度调仓",
|
LogicModelDescription = logicModelDescription,
|
||||||
TotalItems = Positions.Count,
|
TotalItems = Positions.Count,
|
||||||
TotalRatio = 100.0,
|
TotalRatio = 100.0,
|
||||||
Positions = positionItems
|
Positions = positionItems
|
||||||
|
|||||||
7
sql/fix_strategy_id_nullable.sql
Normal file
7
sql/fix_strategy_id_nullable.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
-- 修改 portfolios 表 strategy_id 字段允许 NULL
|
||||||
|
-- 组合可能不使用任何策略,所以应该允许 NULL
|
||||||
|
|
||||||
|
ALTER TABLE portfolios MODIFY COLUMN strategy_id VARCHAR(50) NULL;
|
||||||
|
|
||||||
|
-- 验证
|
||||||
|
DESCRIBE portfolios;
|
||||||
Loading…
Reference in New Issue
Block a user