You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

80 lines
6.2 KiB

package console
// 第三方服务配置(svcconfig) 与 通话翻译配置(calltranslate) 的本地数据模型。
//
// yunyan-sas 的 pb 没有这些定义且禁止改 proto,故在 console 模块用本地 Go struct + gorm/json tag 定义。
// 字段移植自 deep_server 的 db.proto(DBThirdSvcConfig / ThirdSvcFieldItem / DBThirdSvcRegionOverride /
// DBCallTranslatePair),并与 admin 前端(serviceconfig.vue / calltranslate.vue) 的 JSON 契约精确对齐。
//
// 嵌套字段([]SvcField / map[string]string)借助 gorm `serializer:json` tag 存为 jsonb 列,
// gorm v1.26 AutoMigrate + 读写自动 Marshal/Unmarshal,无需手动处理。
// region / mode 直接用 int32(与前端 JSON 一致),不依赖 pb 的 Region/TranslateMode 枚举。
// SvcField 第三方服务的自定义字段项(内嵌于 ThirdSvcConfig.fields jsonb 列,也复用于模板/区域专属字段)。
// 加密字段:DefValue 存 AES-GCM 密文;API 对加密字段只返回 "[encrypted]" 占位,
// 更新时若传空串/占位符则保留原密文不变。
type SvcField struct {
Key string `json:"key"` // 字段名,同服务内唯一,如 secret_key
Description string `json:"description"` // 字段用途描述,前端展示
Type string `json:"type"` // 字段类型:空/text 普通文本;langs 支持语言多选(值=逗号分隔 BCP-47);lang 单选默认语言。旧数据为空即 text,向后兼容
Encrypted bool `json:"encrypted"` // 是否加密存储
DefValue string `json:"def_value"` // 默认值(全区域共用;加密字段存 AES-GCM 密文;langs 存 "zh-CN,en-US",lang 存单个码)
Sort int32 `json:"sort"` // 展示排序,越小越靠前
}
// ThirdSvcConfig 第三方服务配置(表:svc_config,按应用分离)。每行 = 某应用作用域下的一个第三方服务(如火山引擎/阿里云)。
// categories 存逗号分隔的 ServiceCategory 枚举值,如 "1,2,3"。
// Provider 记录该服务由哪个服务商模板创建(如 azure/openai),仅供前端展示/分组,可为空。
//
// 按应用分离:AppName=''为全局默认、'X'为应用X的覆盖;解析时应用有则用应用的、无则回退全局。
// 业务字符串 Id 不再全局唯一,改用代理主键 RowId + 唯一索引(app_name,id),同一 id 可在全局与各应用并存。
type ThirdSvcConfig struct {
RowId uint64 `gorm:"primaryKey;autoIncrement;column:row_id" json:"row_id"`
AppName string `gorm:"column:app_name;size:64;uniqueIndex:uidx_svc_config,priority:1" json:"app_name"` // ''=全局默认
Id string `gorm:"column:id;size:64;uniqueIndex:uidx_svc_config,priority:2" json:"id"`
Name string `gorm:"column:name;size:64" json:"name"`
Provider string `gorm:"column:provider;size:64" json:"provider"`
Categories string `gorm:"column:categories;size:64" json:"categories"`
Description string `gorm:"column:description" json:"description"`
Enable bool `gorm:"column:enable" json:"enable"`
Fields []SvcField `gorm:"column:fields;type:jsonb;serializer:json" json:"fields"`
Createtime int64 `gorm:"column:createtime" json:"createtime"`
Updatetime int64 `gorm:"column:updatetime" json:"updatetime"`
}
// SvcRegionOverride 第三方服务区域字段覆盖(表:third_svc_region_override)。
// 每行 = 一个服务 × 一个区域的分叉集合,支持三种差异(均向后兼容:旧行新字段为 nil,行为不变):
// - Overrides:默认字段的“值覆盖”。某字段 key 不在其中则继承 ThirdSvcConfig.fields 对应字段的 DefValue。
// - ExtraFields:本区域“专属新增字段”(默认字段集里没有的),DefValue 存该区域的值(加密字段存 AES-GCM 密文)。
// - DisabledKeys:本区域“不适用”的默认字段 key(如阿里国内/国外、微软不同区域节点字段不一致)。
// 按应用分离:AppName 进唯一索引首位,(app_name,svc_id,region) 唯一;svc_id 引用同作用域下的 ThirdSvcConfig.Id。
type SvcRegionOverride struct {
Id uint64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
AppName string `gorm:"column:app_name;size:64;uniqueIndex:uidx_svc_region,priority:1" json:"app_name"` // ''=全局默认
SvcId string `gorm:"column:svc_id;size:64;uniqueIndex:uidx_svc_region,priority:2" json:"svc_id"`
Region int32 `gorm:"column:region;uniqueIndex:uidx_svc_region,priority:3" json:"region"`
Overrides map[string]string `gorm:"column:overrides;type:jsonb;serializer:json" json:"overrides"`
ExtraFields []SvcField `gorm:"column:extra_fields;type:jsonb;serializer:json" json:"extra_fields"`
DisabledKeys []string `gorm:"column:disabled_keys;type:jsonb;serializer:json" json:"disabled_keys"`
Updatetime int64 `gorm:"column:updatetime" json:"updatetime"`
}
// CallTranslatePair 通话翻译语言对配置(表:call_translate_pair)。
// 每条记录定义一个区域下"源语言→目标语言"的翻译服务编排。
// mode=0 走三段式(asr/mt/tts_svc_id 有效);mode=1 走端到端(ast_svc_id 有效)。
// bidir=true 时业务侧自动映射反向(dst→src),复用同一套服务。
type CallTranslatePair struct {
Id uint64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
Region int32 `gorm:"column:region;uniqueIndex:uidx_region_lang" json:"region"`
SrcLang string `gorm:"column:src_lang;size:16;uniqueIndex:uidx_region_lang" json:"src_lang"`
DstLang string `gorm:"column:dst_lang;size:16;uniqueIndex:uidx_region_lang" json:"dst_lang"`
Bidir bool `gorm:"column:bidir" json:"bidir"`
Mode int32 `gorm:"column:mode" json:"mode"`
AsrSvcId string `gorm:"column:asr_svc_id;size:64" json:"asr_svc_id"`
MtSvcId string `gorm:"column:mt_svc_id;size:64" json:"mt_svc_id"`
TtsSvcId string `gorm:"column:tts_svc_id;size:64" json:"tts_svc_id"`
AstSvcId string `gorm:"column:ast_svc_id;size:64" json:"ast_svc_id"`
Enable bool `gorm:"column:enable" json:"enable"`
Createtime int64 `gorm:"column:createtime" json:"createtime"`
Updatetime int64 `gorm:"column:updatetime" json:"updatetime"`
}