优化结构

This commit is contained in:
Yvan
2026-08-22 12:13:16 +08:00
parent d987244d0e
commit b27a66e9d3
200 changed files with 1794 additions and 1715 deletions
+19 -20
View File
@@ -3,15 +3,14 @@ package service
import (
"context"
"encoding/json"
"kra/internal/biz/system"
"kra/internal/service/dto"
"time"
"kra/internal/biz"
)
type VersionService struct{ uc *biz.VersionUsecase }
type VersionService struct{ uc *system.VersionUsecase }
func NewVersionService(uc *biz.VersionUsecase) *VersionService { return &VersionService{uc: uc} }
func NewVersionService(uc *system.VersionUsecase) *VersionService { return &VersionService{uc: uc} }
type versionExportInfo struct {
Name string `json:"name"`
@@ -103,7 +102,7 @@ type versionExportDocument struct {
Dictionaries []versionExportDictionary `json:"dictionaries"`
}
func exportMenu(value *biz.Menu) *versionExportMenu {
func exportMenu(value *system.Menu) *versionExportMenu {
menu := &versionExportMenu{
Path: value.Path, Name: value.Name, Hidden: value.Hidden, Component: value.Component, Sort: value.Sort,
Meta: dto.VersionMenuMetaRequest{ActiveName: value.ActiveName, KeepAlive: value.KeepAlive, DefaultMenu: value.DefaultMenu, Title: value.Title, Icon: value.Icon, CloseTab: value.CloseTab, TransitionType: value.TransitionType},
@@ -129,7 +128,7 @@ func exportMenu(value *biz.Menu) *versionExportMenu {
return menu
}
func versionDTO(v *biz.Version) *dto.VersionResponse {
func versionDTO(v *system.Version) *dto.VersionResponse {
return &dto.VersionResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, VersionName: v.Name, VersionCode: v.Code, Description: v.Description, VersionData: v.Data}
}
@@ -213,23 +212,23 @@ func (s *VersionService) Export(ctx context.Context, name, code, description str
payload := versionExportDocument{Version: versionExportInfo{Name: name, Code: code, Description: description, ExportTime: bundle.ExportTime}, Menus: menus, APIs: apis, Dictionaries: dictionaries}
raw, err := json.MarshalIndent(payload, "", " ")
if err != nil {
return &biz.VersionStageError{Stage: biz.VersionStageJSON, Err: err}
return &system.VersionStageError{Stage: system.VersionStageJSON, Err: err}
}
if err = s.uc.CreateVersion(ctx, &biz.Version{Name: versionPointer(name), Code: versionPointer(code), Description: versionPointer(description), Data: versionPointer(string(raw))}); err != nil {
return &biz.VersionStageError{Stage: biz.VersionStageSave, Err: err}
if err = s.uc.CreateVersion(ctx, &system.Version{Name: versionPointer(name), Code: versionPointer(code), Description: versionPointer(description), Data: versionPointer(string(raw))}); err != nil {
return &system.VersionStageError{Stage: system.VersionStageSave, Err: err}
}
return nil
}
func (s *VersionService) Import(ctx context.Context, bundle *biz.VersionBundle) error {
func (s *VersionService) Import(ctx context.Context, bundle *system.VersionBundle) error {
return s.uc.ImportVersionBundle(ctx, bundle)
}
func versionMenuDomain(value dto.VersionMenuRequest) *biz.Menu {
menu := &biz.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}
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 {
menu.Buttons = append(menu.Buttons, &biz.MenuButton{Name: button.Name, Description: button.Description})
menu.Buttons = append(menu.Buttons, &system.MenuButton{Name: button.Name, Description: button.Description})
}
for _, parameter := range value.Parameters {
menu.Parameters = append(menu.Parameters, &biz.MenuParameter{Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
menu.Parameters = append(menu.Parameters, &system.MenuParameter{Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
}
for _, child := range value.Children {
menu.Children = append(menu.Children, versionMenuDomain(child))
@@ -238,19 +237,19 @@ func versionMenuDomain(value dto.VersionMenuRequest) *biz.Menu {
}
func (s *VersionService) ImportRequest(ctx context.Context, req *dto.ImportVersionRequest) error {
if req.Version.Name == "" || req.Version.Code == "" {
return biz.ErrInvalidVersion
return system.ErrInvalidVersion
}
bundle := &biz.VersionBundle{Name: req.Version.Name, Code: req.Version.Code, Description: req.Version.Description, ExportTime: req.Version.ExportTime}
bundle := &system.VersionBundle{Name: req.Version.Name, Code: req.Version.Code, Description: req.Version.Description, ExportTime: req.Version.ExportTime}
for _, menu := range req.Menus {
bundle.Menus = append(bundle.Menus, versionMenuDomain(menu))
}
for _, api := range req.APIs {
bundle.APIs = append(bundle.APIs, &biz.API{Path: api.Path, Description: api.Description, APIGroup: api.APIGroup, Method: api.Method})
bundle.APIs = append(bundle.APIs, &system.API{Path: api.Path, Description: api.Description, APIGroup: api.APIGroup, Method: api.Method})
}
for _, dictionary := range req.Dictionaries {
item := &biz.Dictionary{Name: dictionary.Name, Type: dictionary.Type, Status: dictionary.Status, Desc: dictionary.Description}
item := &system.Dictionary{Name: dictionary.Name, Type: dictionary.Type, Status: dictionary.Status, Desc: dictionary.Description}
for _, detail := range dictionary.Details {
item.Details = append(item.Details, &biz.DictionaryDetail{Label: detail.Label, Value: detail.Value, Extend: detail.Extend, Status: detail.Status, Sort: detail.Sort, ParentID: detail.ParentID, Level: detail.Level, Path: detail.Path})
item.Details = append(item.Details, &system.DictionaryDetail{Label: detail.Label, Value: detail.Value, Extend: detail.Extend, Status: detail.Status, Sort: detail.Sort, ParentID: detail.ParentID, Level: detail.Level, Path: detail.Path})
}
bundle.Dictionaries = append(bundle.Dictionaries, item)
}
@@ -258,7 +257,7 @@ func (s *VersionService) ImportRequest(ctx context.Context, req *dto.ImportVersi
return err
}
raw, _ := json.Marshal(req)
_ = s.uc.CreateVersion(ctx, &biz.Version{
_ = s.uc.CreateVersion(ctx, &system.Version{
Name: versionPointer(req.Version.Name),
Code: versionPointer(req.Version.Code + "_imported_" + time.Now().Format("20060102150405")),
Description: versionPointer("导入版本: " + req.Version.Description),