From bfb6295153918c728ea3f38bf355fea10bf2551e Mon Sep 17 00:00:00 2001 From: Yvan <8574526@qq,com> Date: Fri, 28 Aug 2026 09:46:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/service/system/system.go | 53 ++++++++++++++++++++++++ internal/service/system/system_config.go | 26 ------------ internal/service/system/system_info.go | 23 ---------- internal/service/system/system_init.go | 38 ----------------- 4 files changed, 53 insertions(+), 87 deletions(-) delete mode 100644 internal/service/system/system_config.go delete mode 100644 internal/service/system/system_info.go delete mode 100644 internal/service/system/system_init.go diff --git a/internal/service/system/system.go b/internal/service/system/system.go index 8668a0f..071126f 100644 --- a/internal/service/system/system.go +++ b/internal/service/system/system.go @@ -2,7 +2,11 @@ package system import ( "context" + "encoding/json" "kra/internal/biz/system" + "kra/internal/routecatalog" + "kra/internal/service/dto" + "kra/internal/utils/routepath" ) type SystemConfigService struct { @@ -17,3 +21,52 @@ func NewSystemConfigService(uc *system.SystemConfigUsecase, settings system.Runt func (s *SystemConfigService) IsInitialized(ctx context.Context) (bool, error) { return s.uc.IsInitialized(ctx) } + +func (s *SystemConfigService) PersistConfig(ctx context.Context) error { + return s.uc.PersistConfig(ctx) +} +func (s *SystemConfigService) ReloadConfig(ctx context.Context) error { return s.uc.ReloadConfig(ctx) } +func (s *SystemConfigService) DiskMountPoints() []string { return s.uc.DiskMountPoints() } +func (s *SystemConfigService) SystemConfig() (json.RawMessage, error) { + return s.uc.ConfigurationJSON() +} +func (s *SystemConfigService) SaveSystemConfig(ctx context.Context, req *dto.SetSystemConfigRequest) error { + return s.uc.SaveConfigurationJSON(ctx, req.Config) +} + +func (s *SystemConfigService) Initialize(ctx context.Context, input *dto.DatabaseInitRequest, apis []*system.API) error { + driver, config := input.DBType, "" + switch driver { + case "mysql": + config = "charset=utf8mb4&parseTime=True&loc=Local" + case "pgsql": + config = "sslmode=disable TimeZone=Asia/Shanghai" + case "sqlite", "mssql": + default: + driver = "mysql" + config = "charset=utf8mb4&parseTime=True&loc=Local" + } + return s.uc.Initialize(ctx, &system.DatabaseConfig{Driver: driver, Host: input.Host, Port: input.Port, User: input.UserName, Password: input.Password, Name: input.DBName, Path: input.DBPath, Config: config, Template: input.Template, AdminPassword: input.AdminPassword, APIs: apis}) +} + +func (s *SystemConfigService) InitializeRoutes(ctx context.Context, input *dto.DatabaseInitRequest, routes []dto.Route) error { + apis := make([]*system.API, 0, len(routes)) + for _, route := range routes { + path := routepath.Normalize(route.Path, s.settings.RouterPrefix()) + descriptor := routecatalog.Describe(route.Method, path) + apis = append(apis, &system.API{Path: path, Method: route.Method, APIGroup: descriptor.Group, Description: descriptor.Description}) + } + return s.Initialize(ctx, input, apis) +} + +func (s *SystemConfigService) ServerInfo(ctx context.Context) (*dto.ServerInfoResponse, error) { + value, err := s.uc.ServerInfo(ctx) + if err != nil { + return nil, err + } + diskInfo := make([]dto.ServerDiskResponse, 0, len(value.Disk)) + for _, disk := range value.Disk { + diskInfo = append(diskInfo, dto.ServerDiskResponse{MountPoint: disk.MountPoint, UsedMB: disk.UsedMB, UsedGB: disk.UsedGB, TotalMB: disk.TotalMB, TotalGB: disk.TotalGB, UsedPercent: disk.UsedPercent}) + } + return &dto.ServerInfoResponse{OS: dto.ServerOSResponse{GOOS: value.GOOS, NumCPU: value.NumCPU, Compiler: value.Compiler, GoVersion: value.GoVersion, NumGoroutine: value.NumGoroutine}, CPU: dto.ServerCPUResponse{CPUs: value.CPUs, Cores: value.Cores}, RAM: dto.ServerRAMResponse{UsedMB: value.UsedMB, TotalMB: value.TotalMB, UsedPercent: value.UsedPercent}, Disk: diskInfo}, nil +} diff --git a/internal/service/system/system_config.go b/internal/service/system/system_config.go deleted file mode 100644 index d5ce929..0000000 --- a/internal/service/system/system_config.go +++ /dev/null @@ -1,26 +0,0 @@ -package system - -import ( - "context" - "encoding/json" - - "kra/internal/service/dto" -) - -func (s *SystemConfigService) PersistConfig(ctx context.Context) error { - return s.uc.PersistConfig(ctx) -} - -func (s *SystemConfigService) ReloadConfig(ctx context.Context) error { - return s.uc.ReloadConfig(ctx) -} - -func (s *SystemConfigService) DiskMountPoints() []string { return s.uc.DiskMountPoints() } - -func (s *SystemConfigService) SystemConfig() (json.RawMessage, error) { - return s.uc.ConfigurationJSON() -} - -func (s *SystemConfigService) SaveSystemConfig(ctx context.Context, req *dto.SetSystemConfigRequest) error { - return s.uc.SaveConfigurationJSON(ctx, req.Config) -} diff --git a/internal/service/system/system_info.go b/internal/service/system/system_info.go deleted file mode 100644 index e112445..0000000 --- a/internal/service/system/system_info.go +++ /dev/null @@ -1,23 +0,0 @@ -package system - -import ( - "context" - "kra/internal/service/dto" -) - -func (s *SystemConfigService) ServerInfo(ctx context.Context) (*dto.ServerInfoResponse, error) { - value, err := s.uc.ServerInfo(ctx) - if err != nil { - return nil, err - } - diskInfo := make([]dto.ServerDiskResponse, 0, len(value.Disk)) - for _, disk := range value.Disk { - diskInfo = append(diskInfo, dto.ServerDiskResponse{MountPoint: disk.MountPoint, UsedMB: disk.UsedMB, UsedGB: disk.UsedGB, TotalMB: disk.TotalMB, TotalGB: disk.TotalGB, UsedPercent: disk.UsedPercent}) - } - return &dto.ServerInfoResponse{ - OS: dto.ServerOSResponse{GOOS: value.GOOS, NumCPU: value.NumCPU, Compiler: value.Compiler, GoVersion: value.GoVersion, NumGoroutine: value.NumGoroutine}, - CPU: dto.ServerCPUResponse{CPUs: value.CPUs, Cores: value.Cores}, - RAM: dto.ServerRAMResponse{UsedMB: value.UsedMB, TotalMB: value.TotalMB, UsedPercent: value.UsedPercent}, - Disk: diskInfo, - }, nil -} diff --git a/internal/service/system/system_init.go b/internal/service/system/system_init.go deleted file mode 100644 index b839273..0000000 --- a/internal/service/system/system_init.go +++ /dev/null @@ -1,38 +0,0 @@ -package system - -import ( - "context" - - "kra/internal/biz/system" - "kra/internal/routecatalog" - "kra/internal/service/dto" - "kra/internal/utils/routepath" -) - -func (s *SystemConfigService) Initialize(ctx context.Context, input *dto.DatabaseInitRequest, apis []*system.API) error { - driver, config := input.DBType, "" - switch driver { - case "mysql": - config = "charset=utf8mb4&parseTime=True&loc=Local" - case "pgsql": - config = "sslmode=disable TimeZone=Asia/Shanghai" - case "sqlite", "mssql": - default: - // The compatible initialization flow treats an omitted or unknown dbType as MySQL during - // initialization rather than rejecting it as an unsupported driver. - driver = "mysql" - config = "charset=utf8mb4&parseTime=True&loc=Local" - } - return s.uc.Initialize(ctx, &system.DatabaseConfig{Driver: driver, Host: input.Host, Port: input.Port, User: input.UserName, Password: input.Password, Name: input.DBName, Path: input.DBPath, Config: config, Template: input.Template, AdminPassword: input.AdminPassword, APIs: apis}) -} - -func (s *SystemConfigService) InitializeRoutes(ctx context.Context, input *dto.DatabaseInitRequest, routes []dto.Route) error { - apis := make([]*system.API, 0, len(routes)) - for _, route := range routes { - path := routepath.Normalize(route.Path, s.settings.RouterPrefix()) - descriptor := routecatalog.Describe(route.Method, path) - group, description := descriptor.Group, descriptor.Description - apis = append(apis, &system.API{Path: path, Method: route.Method, APIGroup: group, Description: description}) - } - return s.Initialize(ctx, input, apis) -}