forked from JointCloud/pcm-coordinator
更新集群新增价格。
This commit is contained in:
parent
5073ab3752
commit
7440da141f
|
@ -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"`
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"`
|
||||
|
|
Loading…
Reference in New Issue