From 4a7e646e0e38817855c69845dac25c73559979ed Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Fri, 8 Mar 2024 17:28:50 +0800 Subject: [PATCH 1/2] ClusterList Former-commit-id: 839fd4761ea712bfc0dfccce4c4ad3be2b5784dd --- api/desc/core/pcm-core.api | 4 ++-- api/internal/logic/adapters/clusterlistlogic.go | 4 ++++ api/internal/types/types.go | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index 463f2137..5f6be796 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -726,8 +726,8 @@ type ( ) type ClusterReq { - Id string `json:"id,optional"` - AdapterId string `json:"adapterId,optional"` + Id string `form:"id,optional"` + AdapterId string `form:"adapterId,optional"` Name string `json:"name,optional"` Nickname string `json:"nickname,optional"` Description string `json:"description,optional"` diff --git a/api/internal/logic/adapters/clusterlistlogic.go b/api/internal/logic/adapters/clusterlistlogic.go index 5bf7a5bc..a2806a1e 100644 --- a/api/internal/logic/adapters/clusterlistlogic.go +++ b/api/internal/logic/adapters/clusterlistlogic.go @@ -26,7 +26,11 @@ func NewClusterListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Clust func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.ClusterListResp, err error) { resp = &types.ClusterListResp{} + sql := fmt.Sprintf(`select c.* from t_cluster c left join t_adapter a on c.adapter_id = a.id where c.deleted_at is null`) + if req.AdapterId != "" { + sql = fmt.Sprintf(`select * from t_cluster where adapter_id = %s and deleted_at is null `, req.AdapterId) + } if req.Type != "" { sql = fmt.Sprintf(`select c.* from t_cluster c left join t_adapter a on c.adapter_id = a.id where c.deleted_at is null and a.type = %s`, req.Type) } diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 002edab4..a38dfb33 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -694,8 +694,8 @@ type AdapterRelation struct { } type ClusterReq struct { - Id string `json:"id,optional"` - AdapterId string `json:"adapterId,optional"` + Id string `form:"id,optional"` + AdapterId string `form:"adapterId,optional"` Name string `json:"name,optional"` Nickname string `json:"nickname,optional"` Description string `json:"description,optional"` From 074c9175cb495c9c1c9a2bb55bb0dd0d74801922 Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Mon, 11 Mar 2024 16:52:09 +0800 Subject: [PATCH 2/2] centerResources Former-commit-id: efde0d5a96faf3ee0a05a614671079f05d222a1e --- api/desc/core/pcm-core.api | 1 + .../logic/core/centerresourceslogic.go | 27 ++++++++++--------- api/internal/types/types.go | 9 ++++--- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index 5f6be796..df879ab2 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -163,6 +163,7 @@ type ( cpu float32 `json:"cpu"` memory float32 `json:"memory"` storage float32 `json:"storage"` + centerType string `json:"centerType"` } ) type ( diff --git a/api/internal/logic/core/centerresourceslogic.go b/api/internal/logic/core/centerresourceslogic.go index a5276474..be3f6da5 100644 --- a/api/internal/logic/core/centerresourceslogic.go +++ b/api/internal/logic/core/centerresourceslogic.go @@ -26,22 +26,25 @@ func NewCenterResourcesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C func (l *CenterResourcesLogic) CenterResources() (resp *types.CenterResourcesResp, err error) { // todo: add your logic here and delete this line centerIndex1 := types.CenterIndex{ - Name: "阿里云", - Cpu: float32(12.33), - Memory: float32(64.55), - Storage: float32(33.90), + Name: "阿里云", + Cpu: float32(12.33), + Memory: float32(64.55), + Storage: float32(33.90), + CenterType: "cloud", } centerIndex2 := types.CenterIndex{ - Name: "A超算中心", - Cpu: float32(42.36), - Memory: float32(66.55), - Storage: float32(23.231), + Name: "A超算中心", + Cpu: float32(42.36), + Memory: float32(66.55), + Storage: float32(23.231), + CenterType: "hpc", } centerIndex3 := types.CenterIndex{ - Name: "智算中心", - Cpu: float32(78.33), - Memory: float32(36.55), - Storage: float32(88.93), + Name: "智算中心", + Cpu: float32(78.33), + Memory: float32(36.55), + Storage: float32(88.93), + CenterType: "ai", } resp = &types.CenterResourcesResp{} resp.CentersIndex = append(resp.CentersIndex, centerIndex1) diff --git a/api/internal/types/types.go b/api/internal/types/types.go index a38dfb33..bcc6c69c 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -143,10 +143,11 @@ type CenterResourcesResp struct { } type CenterIndex struct { - Name string `json:"name"` - Cpu float32 `json:"cpu"` - Memory float32 `json:"memory"` - Storage float32 `json:"storage"` + Name string `json:"name"` + Cpu float32 `json:"cpu"` + Memory float32 `json:"memory"` + Storage float32 `json:"storage"` + CenterType string `json:"centerType"` } type GetClusterListReq struct {