更新集群新增价格。

This commit is contained in:
zhangwei 2025-03-11 10:06:50 +08:00
parent 5073ab3752
commit 7440da141f
4 changed files with 25 additions and 3 deletions

View File

@ -1372,7 +1372,7 @@ type (
} }
) )
type ResourcePrice { type ResourceCost {
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"` ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
ResourceID int64 `json:"resourceId" gorm:"column:resource_id"` ResourceID int64 `json:"resourceId" gorm:"column:resource_id"`
Price int `json:"price" gorm:"column:price"` Price int `json:"price" gorm:"column:price"`

View File

@ -67,7 +67,7 @@ func (l *CreateClusterLogic) CreateCluster(req *types.ClusterCreateReq) (resp *t
} }
// 创建资源价格信息 // 创建资源价格信息
clusterId, _ := strconv.ParseInt(cluster.Id, 10, 64) clusterId, _ := strconv.ParseInt(cluster.Id, 10, 64)
resourcePrice := &types.ResourcePrice{ resourcePrice := &types.ResourceCost{
ResourceID: clusterId, ResourceID: clusterId,
Price: req.Price, Price: req.Price,
ResourceType: constants.CLUSTER, ResourceType: constants.CLUSTER,

View File

@ -3,8 +3,11 @@ package adapters
import ( import (
"context" "context"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/clause"
"strconv"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
@ -40,5 +43,24 @@ func (l *UpdateClusterLogic) UpdateCluster(req *types.ClusterCreateReq) (resp *t
} }
cluster.Location = location cluster.Location = location
l.svcCtx.DbEngin.Table("t_cluster").Model(&cluster).Updates(&cluster) 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 return
} }

View File

@ -1287,7 +1287,7 @@ type CommonResp struct {
Data interface{} `json:"data,omitempty"` Data interface{} `json:"data,omitempty"`
} }
type ResourcePrice struct { type ResourceCost struct {
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"` ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
ResourceID int64 `json:"resourceId" gorm:"column:resource_id"` ResourceID int64 `json:"resourceId" gorm:"column:resource_id"`
Price int `json:"price" gorm:"column:price"` Price int `json:"price" gorm:"column:price"`