优化
This commit is contained in:
@@ -20,7 +20,7 @@ func dictionaryDomain(value *dto.DictionaryRequest) *biz.Dictionary {
|
||||
}
|
||||
return &biz.Dictionary{ID: value.ID, Name: value.Name, Type: value.Type, Status: status, Desc: value.Description, ParentID: value.ParentID}
|
||||
}
|
||||
func (s *DictionaryService) CreateDictionaryRequest(ctx context.Context, req *dto.DictionaryRequest) (map[string]any, error) {
|
||||
func (s *DictionaryService) CreateDictionaryRequest(ctx context.Context, req *dto.DictionaryRequest) (*dto.DictionaryResponse, error) {
|
||||
value := dictionaryDomain(req)
|
||||
if err := s.CreateDictionary(ctx, value); err != nil {
|
||||
return nil, err
|
||||
@@ -30,41 +30,51 @@ func (s *DictionaryService) CreateDictionaryRequest(ctx context.Context, req *dt
|
||||
func (s *DictionaryService) UpdateDictionaryRequest(ctx context.Context, req *dto.DictionaryRequest) error {
|
||||
return s.UpdateDictionary(ctx, dictionaryDomain(req))
|
||||
}
|
||||
func dictionaryDTO(v *biz.Dictionary) map[string]any {
|
||||
children := make([]map[string]any, 0, len(v.Children))
|
||||
func dictionaryDTO(v *biz.Dictionary) *dto.DictionaryResponse {
|
||||
children := make([]*dto.DictionaryResponse, 0, len(v.Children))
|
||||
for _, x := range v.Children {
|
||||
children = append(children, dictionaryDTO(x))
|
||||
}
|
||||
details := make([]map[string]any, 0, len(v.Details))
|
||||
details := make([]*dto.DictionaryDetailResponse, 0, len(v.Details))
|
||||
for _, x := range v.Details {
|
||||
details = append(details, detailDTO(x))
|
||||
}
|
||||
return map[string]any{"ID": v.ID, "CreatedAt": v.CreatedAt, "UpdatedAt": v.UpdatedAt, "DeletedAt": nil, "name": v.Name, "type": v.Type, "status": v.Status, "desc": v.Desc, "parentID": v.ParentID, "children": children, "sysDictionaryDetails": details}
|
||||
return &dto.DictionaryResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Type: v.Type, Status: v.Status, Desc: v.Desc, ParentID: v.ParentID, Children: children, SysDictionaryDetails: details}
|
||||
}
|
||||
func (s *DictionaryService) Dictionaries(ctx context.Context, page, size int, name, typ string, details bool) ([]map[string]any, int64, error) {
|
||||
func (s *DictionaryService) Dictionaries(ctx context.Context, page, size int, name, typ string, details bool) ([]*dto.DictionaryResponse, int64, error) {
|
||||
items, total, err := s.uc.ListDictionaries(ctx, page, size, name, typ, details)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
out := make([]*dto.DictionaryResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, dictionaryDTO(v))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *DictionaryService) Dictionary(ctx context.Context, id uint, typ string, status *bool, details bool) (map[string]any, error) {
|
||||
func (s *DictionaryService) Dictionary(ctx context.Context, id uint, typ string, status *bool, details bool) (*dto.DictionaryResponse, error) {
|
||||
v, err := s.uc.FindDictionary(ctx, id, typ, status, details)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dictionaryDTO(v), nil
|
||||
}
|
||||
func (s *DictionaryService) ExportDictionary(ctx context.Context, id uint) (map[string]any, error) {
|
||||
func (s *DictionaryService) ExportDictionary(ctx context.Context, id uint) (*dto.DictionaryExportResponse, error) {
|
||||
v, err := s.uc.ExportDictionary(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dictionaryDTO(v), nil
|
||||
details := make([]*dto.DictionaryDetailExportResponse, 0, len(v.Details))
|
||||
for _, detail := range v.Details {
|
||||
details = append(details, &dto.DictionaryDetailExportResponse{
|
||||
Label: detail.Label, Value: detail.Value, Extend: detail.Extend,
|
||||
Status: detail.Status, Sort: detail.Sort, Level: detail.Level, Path: detail.Path,
|
||||
})
|
||||
}
|
||||
return &dto.DictionaryExportResponse{
|
||||
Name: v.Name, Type: v.Type, Status: v.Status, Desc: v.Desc,
|
||||
SysDictionaryDetails: details,
|
||||
}, nil
|
||||
}
|
||||
func (s *DictionaryService) CreateDictionary(ctx context.Context, v *biz.Dictionary) error {
|
||||
return s.uc.CreateDictionary(ctx, v)
|
||||
@@ -89,37 +99,37 @@ func (s *DictionaryService) CreateDictionaryDetailRequest(ctx context.Context, r
|
||||
func (s *DictionaryService) UpdateDictionaryDetailRequest(ctx context.Context, req *dto.DictionaryDetailRequest) error {
|
||||
return s.UpdateDictionaryDetail(ctx, detailDomain(req))
|
||||
}
|
||||
func detailDTO(v *biz.DictionaryDetail) map[string]any {
|
||||
children := make([]map[string]any, 0, len(v.Children))
|
||||
func detailDTO(v *biz.DictionaryDetail) *dto.DictionaryDetailResponse {
|
||||
children := make([]*dto.DictionaryDetailResponse, 0, len(v.Children))
|
||||
for _, x := range v.Children {
|
||||
children = append(children, detailDTO(x))
|
||||
}
|
||||
return map[string]any{"ID": v.ID, "CreatedAt": v.CreatedAt, "UpdatedAt": v.UpdatedAt, "DeletedAt": nil, "label": v.Label, "value": v.Value, "extend": v.Extend, "status": v.Status, "sort": v.Sort, "sysDictionaryID": v.DictionaryID, "parentID": v.ParentID, "level": v.Level, "path": v.Path, "disabled": !v.Status, "children": children}
|
||||
return &dto.DictionaryDetailResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Label: v.Label, Value: v.Value, Extend: v.Extend, Status: v.Status, Sort: v.Sort, DictionaryID: v.DictionaryID, ParentID: v.ParentID, Level: v.Level, Path: v.Path, Disabled: !v.Status, Children: children}
|
||||
}
|
||||
func (s *DictionaryService) DictionaryDetails(ctx context.Context, page, size int, filter biz.DictionaryDetailFilter) ([]map[string]any, int64, error) {
|
||||
func (s *DictionaryService) DictionaryDetails(ctx context.Context, page, size int, filter biz.DictionaryDetailFilter) ([]*dto.DictionaryDetailResponse, int64, error) {
|
||||
items, total, err := s.uc.ListDictionaryDetails(ctx, page, size, filter)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
out := make([]*dto.DictionaryDetailResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, detailDTO(v))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *DictionaryService) DictionaryDetail(ctx context.Context, id uint) (map[string]any, error) {
|
||||
func (s *DictionaryService) DictionaryDetail(ctx context.Context, id uint) (*dto.DictionaryDetailResponse, error) {
|
||||
v, err := s.uc.FindDictionaryDetail(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return detailDTO(v), nil
|
||||
}
|
||||
func (s *DictionaryService) DictionaryTree(ctx context.Context, id uint, typ string) ([]map[string]any, error) {
|
||||
func (s *DictionaryService) DictionaryTree(ctx context.Context, id uint, typ string) ([]*dto.DictionaryDetailResponse, error) {
|
||||
items, err := s.uc.DictionaryDetailTree(ctx, id, typ)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
out := make([]*dto.DictionaryDetailResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, detailDTO(v))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user