refactor(数据库): 优化数据模型并移除初始化脚本
- 删除 InitDatabase.cs 文件,将数据库初始化逻辑移至其他位置 - 为 Portfolio、Position 和 Transaction 类添加索引 - 添加 AssetType 字段以支持多种资产类型 - 将 Shares 和 Amount 字段类型从 int 改为 decimal(18,8)
This commit is contained in:
parent
455d47f887
commit
09bd91e686
@ -1,46 +0,0 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace AssetManager.Data;
|
||||
|
||||
public class InitDatabase
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var db = SqlSugarConfig.GetSqlSugarClient();
|
||||
|
||||
try
|
||||
{
|
||||
db.CodeFirst.InitTables(
|
||||
typeof(User),
|
||||
typeof(Strategy),
|
||||
typeof(Portfolio)
|
||||
);
|
||||
|
||||
Console.WriteLine("数据库表创建成功!");
|
||||
|
||||
InsertSampleData(db);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"数据库初始化失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void InsertSampleData(ISqlSugarClient db)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
|
||||
db.Insertable(new Strategy
|
||||
{
|
||||
Id = "hfea",
|
||||
UserId = "system",
|
||||
Alias = "HFEA 风险平价策略",
|
||||
Type = "risk_parity",
|
||||
Config = "{\"cycle\": \"quarter\", \"threshold\": 0.05, \"allocation\": {\"UPRO\": 0.6, \"TMF\": 0.4}}\n",
|
||||
CreatedAt = now,
|
||||
UpdatedAt = now
|
||||
}).ExecuteCommand();
|
||||
|
||||
Console.WriteLine("示例数据插入成功!");
|
||||
}
|
||||
}
|
||||
@ -17,13 +17,13 @@ public class Portfolio
|
||||
/// <summary>
|
||||
/// 所属用户ID
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "user_id")]
|
||||
[SugarColumn(ColumnName = "user_id", IndexGroupNameList = new string[] { "idx_user_id" })]
|
||||
public string UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所用策略ID
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "strategy_id")]
|
||||
[SugarColumn(ColumnName = "strategy_id", IndexGroupNameList = new string[] { "idx_strategy_id" })]
|
||||
public string StrategyId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -84,7 +84,7 @@ public class Position
|
||||
/// <summary>
|
||||
/// 所属组合ID
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "portfolio_id")]
|
||||
[SugarColumn(ColumnName = "portfolio_id", IndexGroupNameList = new string[] { "idx_portfolio_id" })]
|
||||
public string PortfolioId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -99,11 +99,17 @@ public class Position
|
||||
[SugarColumn(ColumnName = "stock_name", Length = 200)]
|
||||
public string StockName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资产类型 (Stock/Crypto)
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "asset_type", Length = 20)]
|
||||
public string AssetType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 持有数量
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "shares")]
|
||||
public int Shares { get; set; }
|
||||
[SugarColumn(ColumnName = "shares", ColumnDataType = "decimal(18,8)")]
|
||||
public decimal Shares { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 持仓均价
|
||||
@ -145,7 +151,7 @@ public class Transaction
|
||||
/// <summary>
|
||||
/// 所属组合ID
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "portfolio_id")]
|
||||
[SugarColumn(ColumnName = "portfolio_id", IndexGroupNameList = new string[] { "idx_portfolio_id" })]
|
||||
public string PortfolioId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -160,6 +166,12 @@ public class Transaction
|
||||
[SugarColumn(ColumnName = "stock_code", Length = 50)]
|
||||
public string StockCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资产类型 (Stock/Crypto)
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "asset_type", Length = 20)]
|
||||
public string AssetType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 交易标题 (如: 定期定投)
|
||||
/// </summary>
|
||||
@ -169,8 +181,8 @@ public class Transaction
|
||||
/// <summary>
|
||||
/// 交易数量
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "amount")]
|
||||
public int Amount { get; set; }
|
||||
[SugarColumn(ColumnName = "amount", ColumnDataType = "decimal(18,8)")]
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 成交价格
|
||||
|
||||
Loading…
Reference in New Issue
Block a user