AssetManager.API/AssetManager.Data/DatabaseService.cs
OpenClaw Agent 1977dd609d fix: 请求收益曲线时自动回填历史数据
- GetNavHistoryAsync现在会自动检查是否有历史数据
- 无历史数据时自动调用BackfillNavHistoryInternalAsync
- 拆分内部回填方法,避免重复验证权限
2026-03-13 16:21:31 +00:00

52 lines
1.2 KiB
C#
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SqlSugar;
namespace AssetManager.Data;
public class DatabaseService
{
private readonly ISqlSugarClient _db;
public DatabaseService(ISqlSugarClient db)
{
_db = db;
}
public void InitializeDatabase()
{
_db.CodeFirst.InitTables(
typeof(User),
typeof(Strategy),
typeof(Portfolio),
typeof(Position),
typeof(Transaction),
typeof(TiingoTicker),
typeof(MarketPriceCache),
typeof(MarketKlineCache)
);
}
public ISqlSugarClient GetDb()
{
return _db;
}
/// <summary>
/// 根据ID获取投资组合校验用户ID
/// </summary>
public Portfolio? GetPortfolioById(string id, string userId)
{
return _db.Queryable<Portfolio>()
.First(p => p.Id == id && p.UserId == userId);
}
/// <summary>
/// 根据投资组合ID获取持仓列表
/// </summary>
public List<Position> GetPositionsByPortfolioId(string portfolioId)
{
return _db.Queryable<Position>()
.Where(p => p.PortfolioId == portfolioId)
.ToList();
}
}