| 628 | } |
| 629 | |
| 630 | func (i *imlCatalogueModule) Delete(ctx context.Context, id string) error { |
| 631 | if id == "" { |
| 632 | return nil |
| 633 | } |
| 634 | list, err := i.catalogueService.Search(ctx, "", map[string]interface{}{ |
| 635 | "parent": id, |
| 636 | }) |
| 637 | if err != nil { |
| 638 | return err |
| 639 | } |
| 640 | if len(list) > 0 { |
| 641 | return fmt.Errorf("该目录下存在子目录") |
| 642 | } |
| 643 | err = i.catalogueService.Delete(ctx, id) |
| 644 | if err != nil { |
| 645 | return err |
| 646 | } |
| 647 | // 重新初始化 |
| 648 | catalogues, err := i.catalogueService.List(ctx) |
| 649 | if err != nil { |
| 650 | return err |
| 651 | } |
| 652 | i.root = NewRoot(catalogues) |
| 653 | return nil |
| 654 | } |
| 655 | |
| 656 | // treeItems 获取子树 |
| 657 | func treeItems(parentId string, parentMap map[string][]*catalogue.Catalogue) []*catalogue_dto.Item { |