99 "strings"
1010 "time"
1111
12+ service_overview "github.com/APIParkLab/APIPark/service/service-overview"
13+
1214 mcp_server "github.com/APIParkLab/APIPark/mcp-server"
1315
1416 "github.com/APIParkLab/APIPark/module/monitor/driver"
@@ -58,23 +60,73 @@ var (
5860)
5961
6062type imlCatalogueModule struct {
61- catalogueService catalogue.ICatalogueService `autowired:""`
62- apiService api.IAPIService `autowired:""`
63- apiDocService api_doc.IAPIDocService `autowired:""`
64- serviceService service.IServiceService `autowired:""`
65- serviceTagService service_tag.ITagService `autowired:""`
66- serviceDocService service_doc.IDocService `autowired:""`
67- tagService tag.ITagService `autowired:""`
68- releaseService release.IReleaseService `autowired:""`
69- subscribeService subscribe.ISubscribeService `autowired:""`
70- subscribeApplyService subscribe.ISubscribeApplyService `autowired:""`
71- transaction store.ITransaction `autowired:""`
72- clusterService cluster.IClusterService `autowired:""`
73- settingService setting.ISettingService `autowired:""`
74- monitorService monitor.IMonitorService `autowired:""`
75- root * Root
63+ catalogueService catalogue.ICatalogueService `autowired:""`
64+ apiService api.IAPIService `autowired:""`
65+ apiDocService api_doc.IAPIDocService `autowired:""`
66+ serviceService service.IServiceService `autowired:""`
67+ serviceOverviewService service_overview.IOverviewService `autowired:""`
68+ serviceTagService service_tag.ITagService `autowired:""`
69+ serviceDocService service_doc.IDocService `autowired:""`
70+ tagService tag.ITagService `autowired:""`
71+ releaseService release.IReleaseService `autowired:""`
72+ subscribeService subscribe.ISubscribeService `autowired:""`
73+ subscribeApplyService subscribe.ISubscribeApplyService `autowired:""`
74+ transaction store.ITransaction `autowired:""`
75+ clusterService cluster.IClusterService `autowired:""`
76+ settingService setting.ISettingService `autowired:""`
77+ monitorService monitor.IMonitorService `autowired:""`
78+ root * Root
7679}
7780
81+ //func (i *imlCatalogueModule) OnInit() {
82+ // register.Handle(func(v server.Server) {
83+ // ctx := context.Background()
84+ // list, err := i.releaseService.GetRunningList(ctx)
85+ // if err != nil {
86+ // log.Errorf("onInit: get running list failed:%s", err.Error())
87+ // return
88+ // }
89+ // if len(list) < 1 || list[0].APICount > 0 {
90+ // return
91+ // }
92+ // serviceMap := make(map[string]*release.Release)
93+ // serviceIds := make([]string, 0, len(list))
94+ // for _, v := range list {
95+ // if _, ok := serviceMap[v.Service]; !ok {
96+ // serviceMap[v.Service] = v
97+ // serviceIds = append(serviceIds, v.Service)
98+ // }
99+ // }
100+ // if len(serviceIds) < 1 {
101+ // return
102+ // }
103+ // commitIds, err := i.releaseService.GetRunningApiDocCommits(ctx, serviceIds...)
104+ // if err != nil {
105+ // log.Errorf("onInit: get running api doc commits failed:%s", err.Error())
106+ // return
107+ // }
108+ // if len(commitIds) < 1 {
109+ // return
110+ // }
111+ // listCommits, err := i.apiDocService.ListDocCommit(ctx, commitIds...)
112+ // if err != nil {
113+ // log.Error("onInit: list doc commit failed:", err.Error())
114+ // return
115+ // }
116+ // for _, v := range listCommits {
117+ // m, ok := serviceMap[v.Target]
118+ // if !ok {
119+ // continue
120+ // }
121+ //
122+ // i.releaseService.UpdateRelease(ctx, m.UUID, &release.Update{
123+ // APICount: &v.Data.APICount,
124+ // })
125+ // }
126+ // })
127+ //
128+ //}
129+
78130func (i * imlCatalogueModule ) DefaultCatalogue (ctx context.Context ) (* catalogue_dto.Catalogue , error ) {
79131 catalogues , err := i .catalogueService .List (ctx )
80132 if err != nil {
@@ -447,25 +499,24 @@ func (i *imlCatalogueModule) Services(ctx context.Context, keyword string) ([]*c
447499 if err != nil {
448500 return nil , err
449501 }
450-
451502 serviceIds := utils .SliceToSlice (items , func (i * service.Service ) string {
452503 return i .Id
453- }, func (s * service.Service ) bool {
454- // 未发布的不给展示
455- _ , err = i .releaseService .GetRunning (ctx , s .Id )
456- return err == nil
457504 })
458- if len (serviceIds ) < 1 {
459- return nil , nil
460- }
461-
462- commits , err := i .releaseService .GetRunningApiDocCommits (ctx , serviceIds ... )
505+ overviewMap , err := i .serviceOverviewService .Map (ctx , serviceIds ... )
463506 if err != nil {
464507 return nil , err
465508 }
466- apiCountMap , err := i .apiDocService .LatestAPICountByCommits (ctx , commits ... )
467- if err != nil {
468- return nil , err
509+ serviceIds = utils .SliceToSlice (serviceIds , func (s string ) string {
510+ return s
511+ }, func (s string ) bool {
512+ // 只展示已发布的服务
513+ if info , ok := overviewMap [s ]; ok && info .IsReleased {
514+ return true
515+ }
516+ return false
517+ })
518+ if len (serviceIds ) < 1 {
519+ return nil , nil
469520 }
470521
471522 subscriberCountMap , err := i .subscribeService .CountMapByService (ctx , subscribe .ApplyStatusSubscribe , serviceIds ... )
@@ -479,8 +530,9 @@ func (i *imlCatalogueModule) Services(ctx context.Context, keyword string) ([]*c
479530
480531 result := make ([]* catalogue_dto.ServiceItem , 0 , len (items ))
481532 for _ , v := range items {
482- apiNum , ok := apiCountMap [v .Id ]
483- if ! ok || apiNum < 1 {
533+
534+ ov , ok := overviewMap [v .Id ]
535+ if ! ok || ov .ReleaseApiCount < 1 {
484536 continue
485537 }
486538
@@ -489,8 +541,8 @@ func (i *imlCatalogueModule) Services(ctx context.Context, keyword string) ([]*c
489541 Name : v .Name ,
490542 Tags : auto .List (serviceTagMap [v .Id ]),
491543 Catalogue : auto .UUID (v .Catalogue ),
492- ApiNum : apiNum ,
493544 SubscriberNum : subscriberCountMap [v .Id ],
545+ ApiNum : ov .ReleaseApiCount ,
494546 Description : v .Description ,
495547 Logo : v .Logo ,
496548 EnableMCP : v .EnableMCP ,
0 commit comments