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

125 lines
2.5 KiB
Markdown
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.

# AssetManager 数据库使用说明
## 数据库配置
数据库连接字符串在 `SqlSugarConfig.cs` 中配置:
```csharp
ConnectionString = "server=localhost;Database=assetmanager;Uid=root;Pwd=your_password;CharSet=utf8mb4;"
```
请根据实际情况修改:
- `server`: MySQL服务器地址
- `Database`: 数据库名称
- `Uid`: 用户名
- `Pwd`: 密码
## 数据库实体类
### 用户相关
- `User`: 用户基本信息
- `WechatUser`: 微信用户信息
### 资产相关
- `Asset`: 总资产数据
- `Holding`: 持仓组合数据
### 策略相关
- `Strategy`: 策略模板
- `StrategyTag`: 策略标签
- `StrategyParameter`: 策略参数
- `UserStrategy`: 用户自定义策略
### 投资组合相关
- `Portfolio`: 投资组合
- `Position`: 持仓明细
- `Transaction`: 交易记录
## 使用方法
### 1. 自动初始化(推荐)
`Program.cs` 中已经配置了自动初始化:
```csharp
builder.Services.AddDatabase();
```
应用启动时会自动创建所有数据库表。
### 2. 手动初始化
运行 `InitDatabase.cs` 中的 Main 方法:
```csharp
InitDatabase.Main();
```
这会创建所有表并插入示例数据。
### 3. 在Service中使用
在Service中注入 `DatabaseService``ISqlSugarClient`
```csharp
public class AssetService : IAssetService
{
private readonly ISqlSugarClient _db;
public AssetService(ISqlSugarClient db)
{
_db = db;
}
public List<Holding> GetHoldings()
{
return _db.Queryable<Holding>().ToList();
}
}
```
## Code First 模式
使用 SqlSugar 的 Code First 模式,通过实体类自动创建数据库表:
- 实体类使用 `[SugarTable]` 特性指定表名
- 属性使用 `[SugarColumn]` 特性配置列
- 主键使用 `IsPrimaryKey = true`
- 自增主键使用 `IsIdentity = true`
- 列名映射使用 `ColumnName`
## 数据库表结构
### users 表
- 用户基本信息、统计数据、会员等级等
### wechat_users 表
- 微信用户绑定信息、OpenID、UnionID等
### assets 表
- 总资产数据、今日收益、总收益率等
### holdings 表
- 持仓组合数据、状态、图标样式等
### strategies 表
- 策略模板、风险等级、描述等
### strategy_tags 表
- 策略标签关联
### strategy_parameters 表
- 策略参数配置
### user_strategies 表
- 用户自定义策略配置
### portfolios 表
- 投资组合基本信息
### positions 表
- 持仓明细、盈亏计算等
### transactions 表
- 交易记录、状态跟踪等