## 文档重构(5 个 md + 1 个 html) - README.md: '尚数网本体管理平台' → '本体元数据平台 · Ontology Platform' - docs/README.md: 通用化定位,补全 P0/P1/P2 (Palantir Ontology 对标) + Materialization/BackingSource/Suggestions 全清单 - docs/PLAN.md: 通用化设计目标,改为 'Palantir Ontology 对标' 路线图 - docs/USAGE.md: 用通用占位符(项目/空间/组织)替换尚数网具体业务举例 - docs/IMPORT.md: 把 shangshu 当成 '一个采用方示例' 展示通用模式 - docs/product-intro.html: title/brand/hero/场景/footer 全改通用,沙数只作典型场景之一 ## 代码字符串同步去 shangshu - server/main.go: '[boot] 尚数网本体管理平台监听' → '[boot] 本体平台监听' - server/handlers_connector.go: manifest 'server' 字段 → 'ontology-platform' - server/handlers_mcp.go: tool description + serverInfo → 通用 - server/handlers_functions.go: builtin interface description → 通用 - server/handlers_backing_source.go: 注释去 shangshuwang.cn 具体网址 - server/config.go + server/db.go: 注释/seed 数据改占位 (demo_self / demo_partner_a/b) - server/ai/anthropic.go: fallback systemPrompt → '通用本体平台工程师' - server/ai/heuristic.go: 未识别 summary → '本体概念' - server/ai/prompt.go: 静态 systemPrompt 头部 + JSON 示例去 shangshu ## 前端文案同步 - web/src/App.vue: title 改 '本体元数据平台' - web/src/views/LoginView.vue: 登录页 h1 改通用 - web/src/views/OntologyView.vue: backing source placeholder 改 example.com - web/src/components/ReviewWorkbench.vue + useReviewWorkbench.js: '尚数网' → '本体平台' ## 验证 - go build ./server OK - 剩余 '尚数网' / 'shangshu-ontology' 引用: - 文档 README/README/USAGE/PLAN/IMPORT 仅在 '采用方示例' 上下文出现 - 代码注释 sswOntologySystemPrompt 等 identifier 保持不变(避免改动 API 表面) - skill 名 'ssw-ontology-reviewer' 保持不变(已发布技能) Refs: docs/README.md (1.1 元数据组件表)、docs/PLAN.md (4 当前已完成能力)
142 lines
5.0 KiB
Go
142 lines
5.0 KiB
Go
package main
|
||
|
||
// Backing Sources / Sync Sources(P2-2 2026-08-24)
|
||
//
|
||
// 精简版:仅 metadata + 字段映射定义,不做实际 ETL 执行。
|
||
// 实际 ETL 由 P2-1 materializations 接管(直接读 objects 表)。
|
||
// 这样设计的好处:
|
||
// - 用户先在 backing_sources 里登记外部数据源 + 字段映射
|
||
// - 系统可以基于这份"声明"辅助后续 ETL(未来工作)
|
||
// - 与外部数据源(如 xeo / 其他 mobileApi)接入时,先登记 backing_source,再写迁移脚本
|
||
|
||
import (
|
||
"encoding/json"
|
||
"log"
|
||
"time"
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
type BackingSource struct {
|
||
ID int64 `json:"id"`
|
||
APIName string `json:"api_name"`
|
||
DisplayName string `json:"display_name"`
|
||
Description string `json:"description"`
|
||
SourceKind string `json:"source_kind"`
|
||
ConfigJSON map[string]interface{} `json:"config_json"`
|
||
FieldMapping []map[string]interface{} `json:"field_mapping"`
|
||
MaterializationID *int64 `json:"materialization_id"`
|
||
MaterializationAPIName string `json:"materialization_api_name"`
|
||
IsActive bool `json:"is_active"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
}
|
||
|
||
func scanBackingRow(scan func(...any) error) (BackingSource, error) {
|
||
var bs BackingSource
|
||
var cfg, mapping []byte
|
||
var matID *int64
|
||
var matName *string
|
||
if err := scan(&bs.ID, &bs.APIName, &bs.DisplayName, &bs.Description, &bs.SourceKind,
|
||
&cfg, &mapping, &matID, &matName, &bs.IsActive, &bs.CreatedAt, &bs.UpdatedAt); err != nil {
|
||
return bs, err
|
||
}
|
||
_ = json.Unmarshal(cfg, &bs.ConfigJSON)
|
||
bs.FieldMapping = []map[string]interface{}{}
|
||
_ = json.Unmarshal(mapping, &bs.FieldMapping)
|
||
bs.MaterializationID = matID
|
||
if matName != nil {
|
||
bs.MaterializationAPIName = *matName
|
||
}
|
||
return bs, nil
|
||
}
|
||
|
||
func (a *app) listBackingSources(c *gin.Context) {
|
||
rows, err := a.pool.Query(c,
|
||
`SELECT bs.id, bs.api_name, bs.display_name, bs.description, bs.source_kind,
|
||
bs.config_json, bs.field_mapping, bs.materialization_id, m.api_name,
|
||
bs.is_active, bs.created_at, bs.updated_at
|
||
FROM backing_sources bs
|
||
LEFT JOIN materializations m ON m.id = bs.materialization_id
|
||
ORDER BY bs.id`)
|
||
if err != nil {
|
||
c.JSON(500, gin.H{"error": err.Error()})
|
||
return
|
||
}
|
||
defer rows.Close()
|
||
out := []BackingSource{}
|
||
for rows.Next() {
|
||
bs, err := scanBackingRow(rows.Scan)
|
||
if err == nil {
|
||
out = append(out, bs)
|
||
} else {
|
||
log.Printf("[backing_source scan] %v", err)
|
||
}
|
||
}
|
||
c.JSON(200, gin.H{"backing_sources": out, "count": len(out)})
|
||
}
|
||
|
||
type backingSourceInput struct {
|
||
APIName string `json:"api_name"`
|
||
DisplayName string `json:"display_name"`
|
||
Description string `json:"description"`
|
||
SourceKind string `json:"source_kind"`
|
||
ConfigJSON map[string]interface{} `json:"config_json"`
|
||
FieldMapping []map[string]interface{} `json:"field_mapping"`
|
||
MaterializationID *int64 `json:"materialization_id"`
|
||
IsActive bool `json:"is_active"`
|
||
}
|
||
|
||
func (a *app) createBackingSource(c *gin.Context) {
|
||
var in backingSourceInput
|
||
if err := c.ShouldBindJSON(&in); err != nil {
|
||
c.JSON(400, gin.H{"error": err.Error()})
|
||
return
|
||
}
|
||
if in.APIName == "" || in.DisplayName == "" || in.SourceKind == "" {
|
||
c.JSON(400, gin.H{"error": "api_name/display_name/source_kind 必填"})
|
||
return
|
||
}
|
||
if in.ConfigJSON == nil {
|
||
in.ConfigJSON = map[string]interface{}{}
|
||
}
|
||
if in.FieldMapping == nil {
|
||
in.FieldMapping = []map[string]interface{}{}
|
||
}
|
||
cfgJSON := mustJSON(in.ConfigJSON)
|
||
mapJSON := mustJSON(in.FieldMapping)
|
||
|
||
_, err := a.pool.Exec(c,
|
||
`INSERT INTO backing_sources(api_name,display_name,description,source_kind,
|
||
config_json,field_mapping,materialization_id,is_active)
|
||
VALUES($1,$2,$3,$4,$5::jsonb,$6::jsonb,$7,$8)
|
||
ON CONFLICT(api_name) DO UPDATE SET
|
||
display_name=EXCLUDED.display_name,
|
||
description=EXCLUDED.description,
|
||
source_kind=EXCLUDED.source_kind,
|
||
config_json=EXCLUDED.config_json,
|
||
field_mapping=EXCLUDED.field_mapping,
|
||
materialization_id=EXCLUDED.materialization_id,
|
||
is_active=EXCLUDED.is_active,
|
||
updated_at=now()`,
|
||
in.APIName, in.DisplayName, in.Description, in.SourceKind, cfgJSON, mapJSON,
|
||
in.MaterializationID, in.IsActive)
|
||
if err != nil {
|
||
c.JSON(409, gin.H{"error": "创建失败: " + err.Error()})
|
||
return
|
||
}
|
||
c.JSON(201, gin.H{"ok": true, "api_name": in.APIName})
|
||
}
|
||
|
||
func (a *app) deleteBackingSource(c *gin.Context) {
|
||
name := c.Param("name")
|
||
tag, err := a.pool.Exec(c, `DELETE FROM backing_sources WHERE api_name=$1`, name)
|
||
if err != nil {
|
||
c.JSON(500, gin.H{"error": err.Error()})
|
||
return
|
||
}
|
||
if tag.RowsAffected() == 0 {
|
||
c.JSON(404, gin.H{"error": "backing_source 不存在"})
|
||
return
|
||
}
|
||
c.JSON(200, gin.H{"ok": true})
|
||
} |