优化结构

This commit is contained in:
Yvan
2026-08-28 00:29:40 +08:00
parent 04ff85116c
commit 03a4131f6e
118 changed files with 758 additions and 834 deletions
+7 -15
View File
@@ -18,17 +18,6 @@ type OperationRecordRequest struct {
DeviceID string
}
type DataAccessRecordRequest struct {
EventType string
Operation string
UserID uint
AuthorityID uint
RequestID string
Method string
Path string
Detail string
}
type DataAccessListRequest struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
@@ -45,10 +34,13 @@ type OperationRecordSearchRequest struct {
}
type LoginLogSearchRequest struct {
Page int `form:"page"`
PageSize int `form:"pageSize"`
Username string `form:"username"`
Status *bool `form:"status"`
Page int `form:"page"`
PageSize int `form:"pageSize"`
Username string `form:"username"`
IP string `form:"ip"`
Status *bool `form:"status"`
StartCreatedAt *time.Time `form:"startCreatedAt" time_format:"2006-01-02 15:04:05"`
EndCreatedAt *time.Time `form:"endCreatedAt" time_format:"2006-01-02 15:04:05"`
}
type AuditIDQuery struct {
-9
View File
@@ -65,15 +65,6 @@ type SwitchAuthorityRequest struct {
AuthorityID uint `json:"authorityId"`
}
type LoginLogRequest struct {
Username string
IP string
Status bool
ErrorMessage string
Agent string
UserID uint
}
type UserResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
-41
View File
@@ -1,12 +1,6 @@
package service
// This package is the transport layer's entry point into the service tier.
// Concrete implementations live under service/system, service/payment,
// service/integration, and service/task; the aliases here give handlers one
// import instead of four, and Wire composes the module provider sets directly.
import (
"kra/internal/service/dto"
integrationservice "kra/internal/service/integration"
paymentservice "kra/internal/service/payment"
systemservice "kra/internal/service/system"
@@ -15,41 +9,6 @@ import (
"github.com/google/wire"
)
type AccessControlService = systemservice.AccessControlService
type AnnouncementService = systemservice.AnnouncementService
type APIService = systemservice.APIService
type AuditService = systemservice.AuditService
type AuditRecorder = systemservice.AuditRecorder
type AuthService = systemservice.AuthService
type AuthorityService = systemservice.AuthorityService
type DepartmentService = systemservice.DepartmentService
type DictionaryService = systemservice.DictionaryService
type EmailService = systemservice.EmailService
type ExportService = systemservice.ExportService
type LogViewerService = systemservice.LogViewerService
type MediaService = systemservice.MediaService
type MenuService = systemservice.MenuService
type ParameterService = systemservice.ParameterService
type PermissionService = systemservice.PermissionService
type PositionService = systemservice.PositionService
type SecurityService = systemservice.SecurityService
type SystemConfigService = systemservice.SystemConfigService
type TokenService = systemservice.TokenService
type VersionService = systemservice.VersionService
type PaymentService = paymentservice.PaymentService
type IntegrationConfigService = integrationservice.IntegrationConfigService
type TaskService = taskservice.TaskService
type UserService = systemservice.UserService
var ErrExportTokenMalformed = systemservice.ErrExportTokenMalformed
var ErrExportTokenType = systemservice.ErrExportTokenType
func IsPasswordPolicyError(err error) bool { return systemservice.IsPasswordPolicyError(err) }
func DefaultPaymentCallbackAck(provider string, success bool) dto.PaymentCallbackAck {
return paymentservice.DefaultPaymentCallbackAck(provider, success)
}
// ProviderSet aggregates all service modules for Wire.
var ProviderSet = wire.NewSet(
systemservice.ProviderSet,
-3
View File
@@ -57,6 +57,3 @@ func (s *TokenService) DisableAPIToken(ctx context.Context, id uint) error {
func (s *TokenService) BlacklistToken(ctx context.Context, token string) error {
return s.uc.BlacklistToken(ctx, token)
}
func (s *TokenService) IsTokenDisabled(ctx context.Context, token string) (bool, error) {
return s.uc.IsTokenDisabled(ctx, token)
}
+5 -8
View File
@@ -53,11 +53,11 @@ func (s *AuditService) DeleteOperations(ctx context.Context, ids []int) error {
return s.uc.DeleteOperations(ctx, ids)
}
func (s *AuditRecorder) RecordLogin(ctx context.Context, v *system.LoginLog) error {
return s.uc.RecordLogin(ctx, v)
}
func (s *AuditService) LoginsFilter(ctx context.Context, page, size int, username string, status *bool) ([]*dto.LoginLogResponse, int64, error) {
return s.Logins(ctx, page, size, &system.LoginLogFilter{Username: username, Status: status})
func (s *AuditService) LoginsFilter(ctx context.Context, request dto.LoginLogSearchRequest) ([]*dto.LoginLogResponse, int64, error) {
return s.Logins(ctx, request.Page, request.PageSize, &system.LoginLogFilter{
Username: request.Username, IP: request.IP, Status: request.Status,
StartCreatedAt: request.StartCreatedAt, EndCreatedAt: request.EndCreatedAt,
})
}
func loginDTO(v *system.LoginLog) *dto.LoginLogResponse {
var user any = map[string]any{}
@@ -88,9 +88,6 @@ func (s *AuditService) DeleteLogins(ctx context.Context, ids []int) error {
return s.uc.DeleteLogins(ctx, ids)
}
func (s *AuditRecorder) RecordDataAccess(ctx context.Context, v *system.DataAccessLog) error {
return s.uc.RecordDataAccess(ctx, v)
}
func (s *AuditService) DataAccessRequest(ctx context.Context, req *dto.DataAccessListRequest) ([]*dto.DataAccessLogResponse, int64, error) {
return s.DataAccess(ctx, req.Page, req.PageSize, &system.DataAccessLog{EventType: req.EventType, TargetTable: req.TargetTable})
}
@@ -8,3 +8,9 @@ func TestExportCellValuePreservesNumericText(t *testing.T) {
t.Fatalf("exportCellValue() = %#v, want string 007", exportCellValue("007"))
}
}
func TestExportCellValuePreservesDriverBytes(t *testing.T) {
if value, ok := exportCellValue([]byte("42")).(string); !ok || value != "42" {
t.Fatalf("driver bytes = %#v", exportCellValue([]byte("42")))
}
}
-8
View File
@@ -11,14 +11,6 @@ type MenuService struct{ uc *system.MenuUsecase }
func NewMenuService(uc *system.MenuUsecase) *MenuService { return &MenuService{uc: uc} }
func (s *MenuService) List(ctx context.Context) ([]*dto.MenuResponse, error) {
items, err := s.uc.List(ctx)
if err != nil {
return nil, err
}
return menuResponses(items), nil
}
func (s *MenuService) Tree(ctx context.Context) ([]*dto.MenuResponse, error) {
items, err := s.uc.Tree(ctx)
if err != nil {
+2 -10
View File
@@ -219,9 +219,6 @@ func (s *VersionService) Export(ctx context.Context, name, code, description str
}
return nil
}
func (s *VersionService) Import(ctx context.Context, bundle *system.VersionBundle) error {
return s.uc.ImportVersionBundle(ctx, bundle)
}
func versionMenuDomain(value dto.VersionMenuRequest) *system.Menu {
menu := &system.Menu{Path: value.Path, Name: value.Name, Hidden: value.Hidden, Component: value.Component, Sort: value.Sort, ActiveName: value.Meta.ActiveName, KeepAlive: value.Meta.KeepAlive, DefaultMenu: value.Meta.DefaultMenu, Title: value.Meta.Title, Icon: value.Meta.Icon, CloseTab: value.Meta.CloseTab, TransitionType: value.Meta.TransitionType}
for _, button := range value.MenuButtons {
@@ -253,20 +250,15 @@ func (s *VersionService) ImportRequest(ctx context.Context, req *dto.ImportVersi
}
bundle.Dictionaries = append(bundle.Dictionaries, item)
}
if err := s.Import(ctx, bundle); err != nil {
return err
}
raw, err := json.Marshal(req)
if err != nil {
return &system.VersionStageError{Stage: system.VersionStageJSON, Err: err}
}
if err = s.uc.CreateVersion(ctx, &system.Version{
audit := &system.Version{
Name: versionPointer(req.Version.Name),
Code: versionPointer(req.Version.Code + "_imported_" + time.Now().Format("20060102150405")),
Description: versionPointer("导入版本: " + req.Version.Description),
Data: versionPointer(string(raw)),
}); err != nil {
return &system.VersionStageError{Stage: system.VersionStageSave, Err: err}
}
return nil
return s.uc.ImportVersionBundle(ctx, bundle, audit)
}
@@ -14,12 +14,8 @@ type versionImportRepo struct {
saveErr error
}
func (r *versionImportRepo) ImportVersionBundle(context.Context, *bizsystem.VersionBundle) error {
return nil
}
func (r *versionImportRepo) CreateVersion(context.Context, *bizsystem.Version) error {
return r.saveErr
func (r *versionImportRepo) ImportVersionBundle(context.Context, *bizsystem.VersionBundle, *bizsystem.Version) error {
return &bizsystem.VersionStageError{Stage: bizsystem.VersionStageSave, Err: r.saveErr}
}
func TestImportRequestReturnsVersionAuditSaveFailure(t *testing.T) {