LinkType Spec
表达对象之间关联类型的定义语义。LinkType 以 name 作为自然键,隶属于源对象(source object),通过 sourceObjectRef / targetObjectRef 引用参与关联的两个对象类型。
资源类型与自然键
| 资源类型 | 自然键 | 说明 |
|---|---|---|
LinkType | name | 关联类型名称,在源对象下唯一 |
LinkTypeSpecDTO
| 字段 | 类型 | 说明 |
|---|---|---|
name | string | 名称,作为自然键 |
displayName | string | 显示名称 |
description | string | 未使用。描述占位字段,当前写入服务不消费。 |
sourceObjectRef | ResourceRefDTO | 源对象引用 |
targetObjectRef | ResourceRefDTO | 目标对象引用 |
cardinality | CardinalityEnum | 关联基数 |
sourceRole | string | 源角色,写入 join_condition_json.sourceRole |
targetRole | string | 目标角色,写入 join_condition_json.targetRole |
isHierarchical | boolean | 是否为层级关系,写入 join_condition_json.hierarchical |
semanticType | string | 语义类型:CAUSAL(因果)/ COMPOSITIONAL(组成)/ REFERENCE(引用记录)/ HIERARCHICAL(层级)。可选;缺失时运行态按 linkName 命名启发式推导 |
maxDepth | integer | 最大深度,写入 join_condition_json.maxDepth |
join | JoinSpecDTO | 连接规格 |
properties | List<PropertySpecDTO> | 关联属性列表,写入 join_condition_json.properties |
关联基数(CardinalityEnum)
| 枚举值 | 说明 |
|---|---|
ONE_TO_ONE | 一对一 |
ONE_TO_MANY | 一对多 |
MANY_TO_MANY | 多对多 |
源/目标对象引用(ResourceRefDTO)
写入服务通过 name 解析对象名称;name 为空时回退使用 apiName。kind 当前不参与解析。
| 字段 | 类型 | 说明 |
|---|---|---|
kind | string | 未使用。资源类型,通常填 ObjectType。 |
name | string | 资源自然键(名称),优先使用 |
apiName | string | API 名称,name 为空时回退使用 |
连接规格(JoinSpecDTO)
| 字段 | 类型 | 说明 |
|---|---|---|
joinType | string | 连接类型:DIRECT(直接关联) / BRIDGE(桥接关联);为空时默认 DIRECT |
conditions | List<JoinConditionDTO> | 连接条件列表;DIRECT 关联时必填 |
bridge | BridgeJoinDTO | 桥接连接配置;BRIDGE 关联时必填 |
连接条件(JoinConditionDTO)
DIRECT 关联时,定义源对象属性与目标对象属性的等值连接条件。
| 字段 | 类型 | 说明 |
|---|---|---|
sourcePropertyApiName | string | 源属性 API 名称 |
operator | string | 操作符,当前消费为等值比较(如 EQUALS) |
targetPropertyApiName | string | 目标属性 API 名称 |
桥接连接(BridgeJoinDTO)
BRIDGE 关联时,定义通过桥接数据集(中间表)实现的多对多关联。
| 字段 | 类型 | 说明 |
|---|---|---|
bridgeDatasetName | string | 桥接数据集名称 |
sourceToBridge | List<BridgeMappingDTO> | 源对象到桥接表的映射 |
bridgeToTarget | List<BridgeMappingDTO> | 桥接表到目标对象的映射 |
桥接映射(BridgeMappingDTO)
| 字段 | 类型 | 说明 |
|---|---|---|
propertyApiName | string | 属性 API 名称 |
bridgeColumnName | string | 桥接表列名 |
关联属性(properties)
properties 为 List<PropertySpecDTO>,表达关联自身的属性(如关系的权重、生效时间等)。字段语义与对象属性一致,详见 Property Spec。
消费位置
foundry-ontology-biz:OntologyDomainProjectionAdapter.LinkTypeProjectionHandler解析sourceObjectRef/targetObjectRef,并调用ontologyApi.upsertLink。foundry-ontology-biz:OntologyDefinitionWriteService.upsertLink将name/displayName/targetObjectRef/cardinality投影到fd_ontology_link。foundry-ontology-biz:OntologyDefinitionWriteService.joinConditionFromSpec将sourceRole/targetRole/isHierarchical/maxDepth/join/properties序列化为join_condition_json。foundry-ontology-biz:TraverseExecutor/DefaultQueryPlanner读取join_condition_json.maxDepth执行层级遍历。foundry-analysis-biz/ 归因与影响类算法:按semanticType选择边;缺失时按 linkName 命名启发式推导。foundry-asset-biz:SpecToLegacyAssembler.assembleLinkCreateReq映射到LinkCreateReqDTO。
示例 YAML
DIRECT 关联
kind: LinkType
name: PlantHasLines
spec:
name: PlantHasLines
displayName: 工厂拥有产线
sourceObjectRef:
kind: ObjectType
name: Plant
targetObjectRef:
kind: ObjectType
name: ProductionLine
cardinality: ONE_TO_MANY
sourceRole: plant
targetRole: lines
isHierarchical: false
join:
joinType: DIRECT
conditions:
- sourcePropertyApiName: plant_id
operator: EQUALS
targetPropertyApiName: plant_idBRIDGE 关联
kind: LinkType
name: LineUsesMaterials
spec:
name: LineUsesMaterials
displayName: 产线使用物料
sourceObjectRef:
kind: ObjectType
name: ProductionLine
targetObjectRef:
kind: ObjectType
name: Material
cardinality: MANY_TO_MANY
sourceRole: productionLine
targetRole: materials
join:
joinType: BRIDGE
bridge:
bridgeDatasetName: line_material_bridge
sourceToBridge:
- propertyApiName: line_id
bridgeColumnName: line_id
bridgeToTarget:
- propertyApiName: material_id
bridgeColumnName: material_id示例 JSON
{
"kind": "LinkType",
"name": "PlantHasLines",
"spec": {
"name": "PlantHasLines",
"displayName": "工厂拥有产线",
"sourceObjectRef": {
"kind": "ObjectType",
"name": "Plant"
},
"targetObjectRef": {
"kind": "ObjectType",
"name": "ProductionLine"
},
"cardinality": "ONE_TO_MANY",
"sourceRole": "plant",
"targetRole": "lines",
"isHierarchical": false,
"join": {
"joinType": "DIRECT",
"conditions": [
{
"sourcePropertyApiName": "plant_id",
"operator": "EQUALS",
"targetPropertyApiName": "plant_id"
}
]
}
}
}