41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"kra/internal/biz"
|
|
"kra/internal/service/dto"
|
|
)
|
|
|
|
func (s *SettingsService) ImportDictionaryJSON(ctx context.Context, raw string) error {
|
|
var payload struct {
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
Status *bool `json:"status"`
|
|
Description string `json:"desc"`
|
|
Details []dto.DictionaryDetailRequest `json:"sysDictionaryDetails"`
|
|
}
|
|
if json.Unmarshal([]byte(raw), &payload) != nil || payload.Name == "" || payload.Type == "" {
|
|
return errors.New("JSON 格式错误")
|
|
}
|
|
dictionary := dictionaryDomain(&dto.DictionaryRequest{Name: payload.Name, Type: payload.Type, Status: payload.Status, Description: payload.Description})
|
|
details := make([]*biz.DictionaryDetail, 0, len(payload.Details))
|
|
for i := range payload.Details {
|
|
details = append(details, detailDomain(&payload.Details[i]))
|
|
}
|
|
return s.uc.ImportDictionary(ctx, dictionary, details)
|
|
}
|
|
func (s *SettingsService) DictionaryDetailsByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]map[string]any, error) {
|
|
items, err := s.uc.DictionaryDetailsByParent(ctx, dictionaryID, parentID, includeChildren)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := make([]map[string]any, 0, len(items))
|
|
for _, item := range items {
|
|
out = append(out, detailDTO(item))
|
|
}
|
|
return out, nil
|
|
}
|