126 lines
3.0 KiB
Markdown
126 lines
3.0 KiB
Markdown
# 配置管理
|
||
|
||
> 所属模块:[架构概览](./概览.md)
|
||
|
||
---
|
||
|
||
## 1. 配置文件
|
||
|
||
```json
|
||
{
|
||
"Database": {
|
||
"Type": "sqlite",
|
||
"LocalPath": "./data/database/local.db",
|
||
"ReleasePath": "./data/database/release.db"
|
||
},
|
||
"Parser": {
|
||
"BatchSize": 1000
|
||
},
|
||
"Paths": {
|
||
"LogDir": "./data/logs",
|
||
"OutputDir": "./data/output"
|
||
},
|
||
"Aggregation": {
|
||
"TxPanelMappings": {
|
||
"single-mold": "奇瑞",
|
||
"dual-rapid": "智己"
|
||
},
|
||
"CarModelMappings": {
|
||
"L6": "L6",
|
||
"CM3": "CM3"
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
---
|
||
|
||
## 2. 配置类定义
|
||
|
||
```csharp
|
||
// Infrastructure/Configuration/AppSettings.cs
|
||
namespace Gpulse.WCT.DataAnalyzer.Core.Infrastructure.Configuration;
|
||
|
||
public class AppSettings
|
||
{
|
||
public DatabaseSettings Database { get; set; } = new();
|
||
public ParserSettings Parser { get; set; } = new();
|
||
public PathSettings Paths { get; set; } = new();
|
||
}
|
||
|
||
public class DatabaseSettings
|
||
{
|
||
public string Type { get; set; } = "sqlite";
|
||
public string LocalPath { get; set; } = "./data/database/local.db";
|
||
public string ReleasePath { get; set; } = "./data/database/release.db";
|
||
|
||
// PostgreSQL 配置(可选)
|
||
public string? Host { get; set; }
|
||
public int Port { get; set; } = 5432;
|
||
public string? Name { get; set; }
|
||
public string? User { get; set; }
|
||
public string? Password { get; set; }
|
||
}
|
||
|
||
public class ParserSettings
|
||
{
|
||
public int BatchSize { get; set; } = 1000;
|
||
}
|
||
|
||
public class PathSettings
|
||
{
|
||
public string LogDir { get; set; } = "./data/logs";
|
||
public string OutputDir { get; set; } = "./data/output";
|
||
}
|
||
```
|
||
|
||
---
|
||
|
||
## 3. 数据库配置说明
|
||
|
||
### 双数据库路径
|
||
|
||
| 配置键 | 默认值 | 说明 |
|
||
|--------|--------|------|
|
||
| `Database:LocalPath` | `./data/database/local.db` | 本地解析库 |
|
||
| `Database:ReleasePath` | `./data/database/release.db` | 正式发布库 |
|
||
|
||
两个数据库独立配置,可以位于不同路径,也可以使用不同类型的数据库。
|
||
|
||
### 兼容旧配置
|
||
|
||
`Database:Path` 仍然作为 local 数据库的 fallback 路径,推荐使用 `Database:LocalPath`。
|
||
|
||
### PostgreSQL 支持
|
||
|
||
当 `Database:Type` 设为 `postgresql` 时,local 和 release 都可以使用独立的 PostgreSQL 连接:
|
||
|
||
```json
|
||
{
|
||
"Database": {
|
||
"Type": "postgresql",
|
||
"Host": "localhost",
|
||
"Port": 5432,
|
||
"Name": "wct_local",
|
||
"User": "wct_user",
|
||
"Password": "...",
|
||
"ReleaseHost": "db-server",
|
||
"ReleaseName": "wct_charging_parameters",
|
||
"ReleaseUser": "wct_release",
|
||
"ReleasePassword": "..."
|
||
}
|
||
}
|
||
```
|
||
|
||
Release 数据库的 PostgreSQL 配置前缀为 `Release*`,未设置时回退到 local 的对应配置。
|
||
|
||
---
|
||
|
||
## 4. 聚合配置
|
||
|
||
| 配置键 | 说明 |
|
||
|--------|------|
|
||
| `Aggregation:TxPanelMappings` | TxPanel 名称 → 车厂名称的映射表 |
|
||
| `Aggregation:CarModelMappings` | TxHardware 版本 → 车型名称的映射表 |
|
||
|
||
未配置映射时,直接使用 TxPanel.Name 和 TxHardware.Version 作为最终值。手机品牌/型号从 RxType.Name 自动拆分(分隔符 `/_:`)。 |