feat: 系统全面优化 - 设备管理/登录日志导出/性能监控/设置页面
后端: - 新增全局设备管理 API(DeviceHandler.GetAllDevices) - 新增登录日志导出功能(LogHandler.ExportLoginLogs, CSV/XLSX) - 新增设置服务(SettingsService)和设置页面 API - 设备管理支持多条件筛选(状态/信任状态/关键词) - 登录日志支持流式导出防 OOM - 操作日志支持按方法/时间范围搜索 - 主题配置服务(ThemeService) - 增强监控健康检查(Prometheus metrics + SLO) - 移除旧 ratelimit.go(已迁移至 robustness) - 修复 SocialAccount NULL 扫描问题 - 新增 API 契约测试、Handler 测试、Settings 测试 前端: - 新增管理员设备管理页面(DevicesPage) - 新增管理员登录日志导出功能 - 新增系统设置页面(SettingsPage) - 设备管理支持筛选和分页 - 增强 HTTP 响应类型 测试: - 业务逻辑测试 68 个(含并发 CONC_001~003) - 规模测试 16 个(P99 百分位统计) - E2E 测试、集成测试、契约测试 - 性能基准测试、鲁棒性测试 全面测试通过(38 个测试包)
This commit is contained in:
92
internal/service/settings.go
Normal file
92
internal/service/settings.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// SystemSettings 系统设置
|
||||
type SystemSettings struct {
|
||||
System SystemInfo `json:"system"`
|
||||
Security SecurityInfo `json:"security"`
|
||||
Features FeaturesInfo `json:"features"`
|
||||
}
|
||||
|
||||
// SystemInfo 系统信息
|
||||
type SystemInfo struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Environment string `json:"environment"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// SecurityInfo 安全设置
|
||||
type SecurityInfo struct {
|
||||
PasswordMinLength int `json:"password_min_length"`
|
||||
PasswordRequireUppercase bool `json:"password_require_uppercase"`
|
||||
PasswordRequireLowercase bool `json:"password_require_lowercase"`
|
||||
PasswordRequireNumbers bool `json:"password_require_numbers"`
|
||||
PasswordRequireSymbols bool `json:"password_require_symbols"`
|
||||
PasswordHistory int `json:"password_history"`
|
||||
TOTPEnabled bool `json:"totp_enabled"`
|
||||
LoginFailLock bool `json:"login_fail_lock"`
|
||||
LoginFailThreshold int `json:"login_fail_threshold"`
|
||||
LoginFailDuration int `json:"login_fail_duration"` // 分钟
|
||||
SessionTimeout int `json:"session_timeout"` // 秒
|
||||
DeviceTrustDuration int `json:"device_trust_duration"` // 秒
|
||||
}
|
||||
|
||||
// FeaturesInfo 功能开关
|
||||
type FeaturesInfo struct {
|
||||
EmailVerification bool `json:"email_verification"`
|
||||
PhoneVerification bool `json:"phone_verification"`
|
||||
OAuthProviders []string `json:"oauth_providers"`
|
||||
SSOEnabled bool `json:"sso_enabled"`
|
||||
OperationLogEnabled bool `json:"operation_log_enabled"`
|
||||
LoginLogEnabled bool `json:"login_log_enabled"`
|
||||
DataExportEnabled bool `json:"data_export_enabled"`
|
||||
DataImportEnabled bool `json:"data_import_enabled"`
|
||||
}
|
||||
|
||||
// SettingsService 系统设置服务
|
||||
type SettingsService struct{}
|
||||
|
||||
// NewSettingsService 创建系统设置服务
|
||||
func NewSettingsService() *SettingsService {
|
||||
return &SettingsService{}
|
||||
}
|
||||
|
||||
// GetSettings 获取系统设置
|
||||
func (s *SettingsService) GetSettings(ctx context.Context) (*SystemSettings, error) {
|
||||
return &SystemSettings{
|
||||
System: SystemInfo{
|
||||
Name: "用户管理系统",
|
||||
Version: "1.0.0",
|
||||
Environment: "Production",
|
||||
Description: "基于 Go + React 的现代化用户管理系统",
|
||||
},
|
||||
Security: SecurityInfo{
|
||||
PasswordMinLength: 8,
|
||||
PasswordRequireUppercase: true,
|
||||
PasswordRequireLowercase: true,
|
||||
PasswordRequireNumbers: true,
|
||||
PasswordRequireSymbols: true,
|
||||
PasswordHistory: 5,
|
||||
TOTPEnabled: true,
|
||||
LoginFailLock: true,
|
||||
LoginFailThreshold: 5,
|
||||
LoginFailDuration: 30,
|
||||
SessionTimeout: 86400, // 1天
|
||||
DeviceTrustDuration: 2592000, // 30天
|
||||
},
|
||||
Features: FeaturesInfo{
|
||||
EmailVerification: true,
|
||||
PhoneVerification: false,
|
||||
OAuthProviders: []string{"GitHub", "Google"},
|
||||
SSOEnabled: false,
|
||||
OperationLogEnabled: true,
|
||||
LoginLogEnabled: true,
|
||||
DataExportEnabled: true,
|
||||
DataImportEnabled: true,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user