Files
TakeoutSaaS.Docs/Document/13_AppSeed说明.md
2026-01-29 01:58:15 +00:00

63 lines
2.3 KiB
Markdown
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.
# App 数据种子使用说明App:Seed
> 作用:在启动时自动创建默认租户与基础字典,便于本地/测试环境快速落地必备数据。由 `AppDataSeeder` 执行,支持幂等多次运行。
## 配置入口
- 文件位置:`appsettings.Seed.{Environment}.json`AdminApi 下新增独立种子文件,示例已写入 Development
- 配置节:`App:Seed`
示例(已写入 `src/Api/TakeoutSaaS.AdminApi/appsettings.Seed.Development.json`
```json
{
"App": {
"Seed": {
"Enabled": true,
"DefaultTenant": {
"TenantId": 1000000000001,
"Code": "demo",
"Name": "Demo租户",
"ShortName": "Demo",
"ContactName": "DemoAdmin",
"ContactPhone": "13800000000"
},
"DictionaryGroups": [
{
"Code": "order_status",
"Name": "订单状态",
"Scope": "Business",
"Items": [
{ "Key": "pending", "Value": "待支付", "SortOrder": 10 },
{ "Key": "paid", "Value": "已支付", "SortOrder": 20 },
{ "Key": "finished", "Value": "已完成", "SortOrder": 30 }
]
},
{
"Code": "store_tags",
"Name": "门店标签",
"Scope": "Business",
"Items": [
{ "Key": "hot", "Value": "热门", "SortOrder": 10 },
{ "Key": "new", "Value": "新店", "SortOrder": 20 }
]
}
]
}
}
}
```
## 字段说明
- `Enabled`: 是否启用种子
- `DefaultTenant`: 默认租户(使用雪花 long ID0 表示让雪花生成)
- `DictionaryGroups`: 基础字典,`Scope` 可选 `System`/`Business``Items` 支持幂等运行更新
## 运行方式
1. 确保 Admin API 已调用 `AddAppInfrastructure`Program.cs 已注册,会启用 `AppDataSeeder`)。
2. 修改 `appsettings.Seed.{Environment}.json``App:Seed` 后,启动 Admin API即会自动执行种子逻辑幂等
3. 查看日志:`AppSeed` 前缀会输出创建/更新结果。
## 注意事项
- ID 必须用 long雪花不要再使用 Guid/自增。
- 系统租户使用 `TenantId = 0`;业务租户请填写实际雪花 ID。
- 字典分组编码需唯一;重复运行会按编码合并更新。
- 生产环境请按需开启 `Enabled`,避免误写入。