| 549 | } |
| 550 | |
| 551 | func (i *imlCatalogueModule) Search(ctx context.Context, keyword string) ([]*catalogue_dto.Item, error) { |
| 552 | all, err := i.catalogueService.List(ctx) |
| 553 | if err != nil { |
| 554 | return nil, err |
| 555 | } |
| 556 | if keyword == "" { |
| 557 | parentMap := make(map[string][]*catalogue.Catalogue) |
| 558 | nodeMap := make(map[string]*catalogue.Catalogue) |
| 559 | for _, v := range all { |
| 560 | if _, ok := parentMap[v.Parent]; !ok { |
| 561 | parentMap[v.Parent] = make([]*catalogue.Catalogue, 0) |
| 562 | } |
| 563 | parentMap[v.Parent] = append(parentMap[v.Parent], v) |
| 564 | nodeMap[v.Id] = v |
| 565 | } |
| 566 | return treeItems("", parentMap), nil |
| 567 | } |
| 568 | |
| 569 | catalogues, err := i.catalogueService.Search(ctx, keyword, nil) |
| 570 | if err != nil { |
| 571 | return nil, err |
| 572 | } |
| 573 | if i.root == nil { |
| 574 | // 初始化 |
| 575 | i.root = NewRoot(all) |
| 576 | } |
| 577 | items := make([]*catalogue_dto.Item, 0, len(catalogues)) |
| 578 | |
| 579 | return items, nil |
| 580 | } |
| 581 | |
| 582 | func (i *imlCatalogueModule) Create(ctx context.Context, input *catalogue_dto.CreateCatalogue) error { |
| 583 | parent := "" |