From 7440da141f50552123b043155ab0c5d3ab8143e6 Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Tue, 11 Mar 2025 10:06:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=9B=86=E7=BE=A4=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BB=B7=E6=A0=BC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- desc/core/pcm-core.api | 2 +- internal/logic/adapters/createclusterlogic.go | 2 +- internal/logic/adapters/updateclusterlogic.go | 22 +++++++++++++++++++ internal/types/types.go | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/desc/core/pcm-core.api b/desc/core/pcm-core.api index 8ddb18e73..55025f482 100644 --- a/desc/core/pcm-core.api +++ b/desc/core/pcm-core.api @@ -1372,7 +1372,7 @@ type ( } ) -type ResourcePrice { +type ResourceCost { ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"` ResourceID int64 `json:"resourceId" gorm:"column:resource_id"` Price int `json:"price" gorm:"column:price"` diff --git a/internal/logic/adapters/createclusterlogic.go b/internal/logic/adapters/createclusterlogic.go index 2832f9337..c97a70bf6 100644 --- a/internal/logic/adapters/createclusterlogic.go +++ b/internal/logic/adapters/createclusterlogic.go @@ -67,7 +67,7 @@ func (l *CreateClusterLogic) CreateCluster(req *types.ClusterCreateReq) (resp *t } // 创建资源价格信息 clusterId, _ := strconv.ParseInt(cluster.Id, 10, 64) - resourcePrice := &types.ResourcePrice{ + resourcePrice := &types.ResourceCost{ ResourceID: clusterId, Price: req.Price, ResourceType: constants.CLUSTER, diff --git a/internal/logic/adapters/updateclusterlogic.go b/internal/logic/adapters/updateclusterlogic.go index 1067a689f..9d0bc69cd 100644 --- a/internal/logic/adapters/updateclusterlogic.go +++ b/internal/logic/adapters/updateclusterlogic.go @@ -3,8 +3,11 @@ package adapters import ( "context" "github.com/pkg/errors" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" "gorm.io/gorm" + "gorm.io/gorm/clause" + "strconv" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" @@ -40,5 +43,24 @@ func (l *UpdateClusterLogic) UpdateCluster(req *types.ClusterCreateReq) (resp *t } cluster.Location = location l.svcCtx.DbEngin.Table("t_cluster").Model(&cluster).Updates(&cluster) + // 更新资源价格表 + clusterId, err := strconv.ParseInt(req.Id, 10, 64) + if err != nil { + return nil, err + } + resourceCost := &types.ResourceCost{ + ResourceID: clusterId, + Price: req.Price, + ResourceType: constants.CLUSTER, + CostType: req.CostType, + } + dbResult := l.svcCtx.DbEngin.Clauses(clause.OnConflict{ + Columns: []clause.Column{{Name: "resource_id"}}, + DoUpdates: clause.AssignmentColumns([]string{"price", "cost_type"}), + }).Create(&resourceCost) + + if dbResult.Error != nil { + panic(dbResult.Error) + } return } diff --git a/internal/types/types.go b/internal/types/types.go index e633fe248..b1b4e762b 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1287,7 +1287,7 @@ type CommonResp struct { Data interface{} `json:"data,omitempty"` } -type ResourcePrice struct { +type ResourceCost struct { ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"` ResourceID int64 `json:"resourceId" gorm:"column:resource_id"` Price int `json:"price" gorm:"column:price"`