entity/skill/SKILL.md

30 lines
1.9 KiB
Markdown
Raw Permalink 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.

---
name: entity
description: entity 模块技能文档——实体管理(实体表 CRUD + 实体导入 entity_import + api/entity_import.dspy通过 load_entity() 挂载。
---
# entity 模块
## 概述
实体管理模块提供实体表entity增删改查与文件导入entity_import 记录表)。依赖 world、scene 模块。
## 数据模型
- `entity`id / world_id→world.id/ scene_id→scene.id/ name / code / entity_typeappcodes entity_type/ statusappcodes entity_status/ attributes_json(text) / created_at / updated_at。唯一索引 code。
- `entity_import`id / world_id / scene_id / file_name / total / success / fail / statusappcodes import_status/ created_at。只读记录。
## 关键接口
- `load_entity()`:注册 create_entity/update_entity/delete_entity/entity_import 到 ServerEnv含复数别名
- `wwwroot/api/entity_import.dspy`:文件导入 → 解析JSON 数组或 CSV 表头)→ 逐条校验 name/code → sor.C('entity') → 统计 → sor.C('entity_import')。返回 `{success,total,success_count,fail,file_name}`
- `wwwroot/api/entity_{create,update,delete}.dspy`:实体 CRUD委托 init.py 函数)。
- `wwwroot/api/get_search_{world_id,scene_id,entity_type,status}.dspy`:下拉数据源。
## 陷阱
- 库名禁止硬编码:.py 用 `ServerEnv().get_module_dbname('entity')`.dspy 用 `get_module_dbname('entity')` / `get_sor_context(request._run_ns, 'entity')`
- dspy 内禁止 import`from sqlor.filter import DBFilter` 例外),业务逻辑放 `entity/init.py` 并通过 `load_entity()` 导出。
- `sor.C()` 不会自动填 created_at必须显式 `ns['created_at'] = curDateString()`
- 实体导入记录entity_import只读不可手工增删改。
## 依赖
- world、scene下拉数据源 world / scene 表)
- 基础sqlor、ahserver、bricks、appbaseappcodes