87 lines
2.5 KiB
Go
87 lines
2.5 KiB
Go
package biz
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type DictionaryDetail struct {
|
|
ID uint
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Label string
|
|
Value string
|
|
Extend string
|
|
Status bool
|
|
Sort int
|
|
DictionaryID uint
|
|
ParentID *uint
|
|
Level int
|
|
Path string
|
|
Children []*DictionaryDetail
|
|
}
|
|
|
|
type DictionaryDetailFilter struct {
|
|
DictionaryID uint
|
|
Label string
|
|
Value string
|
|
Status *bool
|
|
ParentID *uint
|
|
Level *int
|
|
}
|
|
|
|
type DictionaryDetailRepo interface {
|
|
CreateDictionaryDetail(context.Context, *DictionaryDetail) error
|
|
UpdateDictionaryDetail(context.Context, *DictionaryDetail) error
|
|
DeleteDictionaryDetail(context.Context, uint) error
|
|
FindDictionaryDetail(context.Context, uint) (*DictionaryDetail, error)
|
|
ListDictionaryDetails(context.Context, int, int, DictionaryDetailFilter) ([]*DictionaryDetail, int64, error)
|
|
DictionaryDetailTree(context.Context, uint, string) ([]*DictionaryDetail, error)
|
|
}
|
|
|
|
type Dictionary struct {
|
|
ID uint
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Name string
|
|
Type string
|
|
Status bool
|
|
Desc string
|
|
ParentID *uint
|
|
Children []*Dictionary
|
|
Details []*DictionaryDetail
|
|
}
|
|
|
|
type DictionaryRepo interface {
|
|
DictionaryMetadataRepo
|
|
DictionaryDetailRepo
|
|
}
|
|
|
|
type DictionaryMetadataRepo interface {
|
|
CreateDictionary(context.Context, *Dictionary) error
|
|
ImportDictionary(context.Context, *Dictionary, []*DictionaryDetail) error
|
|
UpdateDictionary(context.Context, *Dictionary) error
|
|
DeleteDictionary(context.Context, uint) error
|
|
FindDictionary(context.Context, uint, string, *bool, bool) (*Dictionary, error)
|
|
ExportDictionary(context.Context, uint) (*Dictionary, error)
|
|
ListDictionaries(context.Context, int, int, string, string, bool) ([]*Dictionary, int64, error)
|
|
}
|
|
|
|
func (uc *SettingsUsecase) ImportDictionary(ctx context.Context, dictionary *Dictionary, details []*DictionaryDetail) error {
|
|
return uc.SettingsRepo.ImportDictionary(ctx, dictionary, details)
|
|
}
|
|
|
|
func (uc *SettingsUsecase) DictionaryDetailsByParent(ctx context.Context, dictionaryID, parentID uint) ([]*DictionaryDetail, error) {
|
|
items, _, err := uc.ListDictionaryDetails(ctx, 0, 0, DictionaryDetailFilter{DictionaryID: dictionaryID})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := make([]*DictionaryDetail, 0)
|
|
for _, item := range items {
|
|
if (parentID == 0 && item.ParentID == nil) || (item.ParentID != nil && *item.ParentID == parentID) {
|
|
out = append(out, item)
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|