优化结构

This commit is contained in:
Yvan
2026-08-21 19:11:14 +08:00
parent 690a2d71ca
commit a2ce3ae218
22 changed files with 1292 additions and 734 deletions
+24 -3
View File
@@ -8,6 +8,7 @@ import (
"time"
"kra/internal/biz"
"kra/internal/integrationruntime"
"gorm.io/gorm"
)
@@ -65,7 +66,11 @@ func (r *integrationConfigRepo) SaveIntegrationConfig(ctx context.Context, confi
}
}
encoded, _ := json.Marshal(values)
return db.Create(&integrationConfigPO{Kind: config.Kind, Provider: config.Provider, Enabled: config.Enabled, Config: string(encoded)}).Error
if err := db.Create(&integrationConfigPO{Kind: config.Kind, Provider: config.Provider, Enabled: config.Enabled, Config: string(encoded)}).Error; err != nil {
return err
}
r.publish(config.Kind, config.Provider, config.Enabled, encoded)
return nil
}
if err != nil {
return err
@@ -77,11 +82,27 @@ func (r *integrationConfigRepo) SaveIntegrationConfig(ctx context.Context, confi
}
}
encoded, _ := json.Marshal(values)
return db.Model(&row).Updates(map[string]any{"enabled": config.Enabled, "config": string(encoded)}).Error
if err := db.Model(&row).Updates(map[string]any{"enabled": config.Enabled, "config": string(encoded)}).Error; err != nil {
return err
}
r.publish(config.Kind, config.Provider, config.Enabled, encoded)
return nil
}
func (r *integrationConfigRepo) DeleteIntegrationConfig(ctx context.Context, kind, provider string) error {
return r.data.DB().WithContext(ctx).Where("kind = ? AND provider = ?", kind, provider).Delete(&integrationConfigPO{}).Error
if err := r.data.DB().WithContext(ctx).Where("kind = ? AND provider = ?", kind, provider).Delete(&integrationConfigPO{}).Error; err != nil {
return err
}
if runtime := r.data.IntegrationRuntime(); runtime != nil {
runtime.Delete(kind, provider)
}
return nil
}
func (r *integrationConfigRepo) publish(kind, provider string, enabled bool, values []byte) {
if runtime := r.data.IntegrationRuntime(); runtime != nil {
runtime.Set(integrationruntime.Config{Kind: kind, Provider: provider, Enabled: enabled, Values: values})
}
}
func integrationConfigFromPO(row integrationConfigPO) *biz.IntegrationConfig {
+2
View File
@@ -2,6 +2,7 @@ package system
import (
"kra/internal/conf"
"kra/internal/integrationruntime"
"gorm.io/gorm"
)
@@ -13,4 +14,5 @@ type Provider interface {
Database(name string) (*gorm.DB, error)
DatabaseReady() bool
Runtime() *conf.Runtime
IntegrationRuntime() *integrationruntime.Store
}