Complete Web-side Object Creation Process (Reference for Mini-Program Porting)
Document Date: 2026-06-24
Purpose: Clarify the Web-side object creation process and define the porting plan for the mini-program side
I. Overall Architecture
用户输入 SCSAI
│ │
├─[Web端 useCreate.js]─┐ │
│ (vue composable) │ │
│ 7步流程镜像服务端 │ │
│ │ │
├─[小程序 SCSAI-create] │ │
│ (vue页面) │ │
│ ▼ ▼
│ POST /api/unified/create ──> SCSAIClient.sendAML()
│ POST /api/unified/generate-props
│ POST /api/unified/apply-aml
│ ▲ ▲
│ │ │
│ ┌──────┴──────┐ │
│ │ SQLite DB │ │
│ │ sciot_import.db │
│ │ (模板/规则/提示词) │
│ └─────────────┘ │
└─────────────────────────────────────────────┘
二、数据库表结构(SQLite: sciot_import.db)
2.1 核心表
| 表名 | 用途 | 关键字段 |
|------|------|---------|
| sciot_item_types | Type Definition | name, label, keyed_name |
| sciot_properties | Property Definition | item_type_name, name, label, data_type, is_required, list_values, default_value |
| sciot_relationships | Relationship Definition | source_item_type, relationship_name, related_item_type |
| sciot_templates | Generation Template | item_type_name, llm_fields, auto_fields, generation_rules |
| sciot_list_values | List Values | list_name, value, label |
| sciot_lifecycle_maps | Lifecycle | item_type_name, name |
| sciot_sequences | Numbering Sequences | name, value |
| sciot_prompts | Pre-stored Prompts | prompt_type, system_prompt, user_prompt_template |
2.2 Template (sciot_templates) Content Example
Each record corresponds to a business object type (e.g., Part, Document, ECR), containing:
{
"item_type_name": "Part",
"llm_fields": ["name", "description", "material", "weight", "unit_cost"],
"auto_fields": ["item_number"],
"generation_rules": {
"default_permission": "标准 PLM 对象",
"default_properties": { "classification": "Part" },
"item_properties": {
"ownership_id": { "target_type": "Identity", "is_mandatory": false }
},
"child_objects": [
{
"relationship_name": "Part BOM",
"target_type": "Part",
"is_mandatory": false,
"llm_fields": ["name", "quantity", "unit"]
}
]
}
}
三、完整创建流程(7步)
Step 1: 获取元数据
function fetchTypeTemplateFromDb(itemType) {
// 1. 查询 sciot_item_types
const type = db.get('SELECT * FROM sciot_item_types WHERE name = ?', itemType)
// 2. 查询 sciot_properties(含 list_values)
const props = db.all('SELECT * FROM sciot_properties WHERE item_type_name = ?', itemType)
// 3. 查询 sciot_relationships(含关联对象的属性)
const rels = db.all('SELECT * FROM sciot_relationships WHERE source_item_type = ?', itemType)
// 4. 查询生命周期、序列
// 5. 查询 sciot_templates(llm_fields, auto_fields, generation_rules)
const template = db.get('SELECT * FROM sciot_templates WHERE item_type_name = ?', itemType)
return { item_type, properties, relationships, lifecycle, sequence, llm_fields, auto_fields, generation_rules }
}
Step 2: 属性过滤与补全(filterAndSanitize)
- 过滤系统管理字段(SYSTEM_MANAGED_FIELDS,如 id, created_on, keyed_name 等)
- 过滤计算字段(rollup_前缀、spi/cpi/rpn 等)
- 过滤 item/foreign 类型字段(后续预创建处理)
- 类型转换(boolean→'1'/'0', integer→整数, date→ISO, float→数字)
- 补充默认值(default_value + generation_rules.default_properties)
- 确保 keyed_field 有值(如 item_number 为空时自动生成
AUTO-xxx)
Step 3: Sequence 编号
- 对 data_type=sequence 或 genRules.sequence_field 的 keyed 字段
- 调用 SCSAI
getNextSequence(线程安全) - 回退方案:直接 get + edit(兼容旧版)
Step 4: 引用字段预创建(precreateItem)
- 对 item/foreign 类型的属性
- 如果有 genRules.item_properties 配置且 is_mandatory
- 先创建引用的子对象(通过 SCSAI ApplyItem)
- 或直接引用已有对象(action='get')
Step 5: 构建 AML
function buildItemAML(data, propDefsMap) {
// 输入: { item_type, action, properties, item_properties, default_permission }
// 输出: AML XML 字符串
// 示例:
// <Item type="Part" action="add">
// <name>M8螺栓</name>
// <item_number>M8-001</item_number>
// <description>304不锈钢材质</description>
// <ownership_id><Item type="Identity" id="xxx" action="get"/></ownership_id>
// </Item>
}
关键规则:
- action="add" without id → SCSAI automatically generates a GUID
- Relationships nested within
→ SCSAI automatically handles source_id - Same-name relationships (relationship_type === related_item_type) → Place attributes directly on the relationship Item
- Different-name relationships → Wrap the related object with
Step 6: Submit to SCSAI
const mainAml = '<AML>' + buildItemAML(data, propDefsMap) + '</AML>'
const result = await SCSAIClient.sendAML(mainAml)
const createdId = extractItemId(result.items?.[0])
- 失败重试:名称重复时自动加后缀去重
- 权限错误 → World 权限重试
Step 7: 关系递归创建
- 支持 Type A:关系类型 ≠ 关联对象类型(如 Part Document → Document)
- 支持 Type B:关系类型 = 关联对象类型(如 Part BOM → Part)
- 支持多级嵌套 BOM
四、LLM 提示词生成(handleGenerateProps)
4.1 提示词来源
提示词并非每次动态构建,而是从 sciot_prompts 表读取预生成的模板(带 {{name}}、{{label}}、{{prop_count}} 等占位符),并实时填入当前类型的实际数据(字段列表、列表值、关系定义)。
4.2 Prompt Structure
你是 SCSAI PLM 系统的对象创建专家。
用户想要创建一个 "Part" 对象。
用户需求:创建一个名为M8螺栓的零件
== 主对象可用字段 ==
- name (string)(必填): 名称
- item_number (string)(必填): 物料号
- description (text): 描述
- material (list)(必填) [可选值: 不锈钢, 碳钢, 铝合金, 塑料]: 材料
- weight (decimal): 重量
引用类型字段:
- ownership_id → 引用类型: Identity
可用关系类型:
- Part BOM → 关联对象类型: Part
关联对象字段: name*(string), quantity*(integer), unit(string)
请根据用户需求,生成创建该对象所需的属性值和关系配置。
返回 JSON 格式:
{
"properties": { "字段名": "值" },
"relationships": [
{
"relationship_type": "Part BOM",
"related_item_type": "Part",
"related_items": [ { "properties": { "name": "值" } } ]
}
]
}
4.3 LLM 响应提取
多重回退解析:
- Directly JSON.parse()
- markdown code block extraction: /`(?:json)?\s([\s\S]?)`/
- curly brace extraction: /\{[\s\S]*\}/
return: { properties: {...}, relationships: [...] }
V. Complete Request Chain
Option A: LLM generates properties + creation (two-step, recommended)
请求1: POST /api/unified/generate-props
body: { itemType: "Part", description: "创建一个M8螺栓,304不锈钢" }
→ 服务端: fetchTypeTemplateFromDb → 构建提示词 → LLM → JSON解析
→ 返回: { properties: {name:"M8螺栓", material:"不锈钢", ...}, relationships: [...] }
请求2: POST /api/unified/create
body: { itemType: "Part", properties: {...}, relationships: [...] }
→ 服务端: 7步流程(过滤→序列→预创建→构建AML→SubmitSCSAI→关系创建)
→ 返回: { id: "xxx", itemType: "Part", properties: {...}, steps: [...] }
方案 B:本地 AML 构建 + 轻量提交(替代方案)
请求1: POST /api/unified/generate-props(同上)
请求2: 本地 AmlBuilder.buildAML() → POST /api/unified/apply-aml
body: { aml: "<AML>...</AML>", itemType: "Part" }
→ 服务端: 仅 SCSAIClient.sendAML(aml) — 跳过 7 步流程
→ 返回: { id: "xxx", itemType: "Part" }
六、小程序端移植方案
6.1 直接复用服务端 API(最小改动,当前状态)
小程序端继续保持:
- POST /api/unified/generate-props to obtain LLM-generated properties
- POST /api/unified/create to execute the full 7-step creation
- AmlBuilder.js + amlHelper.js have been copied to src/utils/
6.2 Localizing SCSAI Calls (Ideal Solution)
Work required:
| Module | Status | Description |
|------|------|------|
| src/utils/AmlBuilder.js | ✅ Copied | JSON → AML XML |
| src/utils/amlHelper.js | ✅ Copied | System field filtering, validation |
| src/api/unified-create.js | ✅ Updated | Includes createLocal() method |
| Server-side apply-aml endpoint | ✅ Added | POST /api/unified/apply-aml |
| Local serial number acquisition | ❌ To be added | HTTP proxy for SCSAI getNextSequence |
| Local item/foreign pre-creation | ❌ To be added | Create reference objects first, then submit the main object |
| Local relationship recursive creation | ❌ To be added | Local buildRelationshipsAML |
| Rule template reading | ❌ To add API proxy | Mini-program needs GET to read sciot_templates |
6.3 Frontend + Server-side Hybrid Solution (Recommended Transition)
小程序端: generate-props → LLM 生成属性
小程序端: 本地 AmlBuilder + 本地预处理(序列号API / 预创建API)
小程序端: 本地 buildRelationshipsAML
小程序端: apply-aml → 服务端仅转发到 SCSAI
这个方案让小程序端承担了步骤 1、2、3、5、7 的 JSON 处理逻辑,服务端只做:
- generate-props — Template→Prompt→LLM (Must be server-side, as LLM is on the server)
- apply-aml — Forward AML to SCSAI
- Serial number acquisition — Proxy SCSAI getNextSequence
- Pre-create reference objects — Proxy SCSAI ApplyItem (Create new reference objects)
BossAgents