Browse Source

更新集群新增价格。

pull/436/head
zhangwei 8 months ago
parent
commit
7440da141f
4 changed files with 25 additions and 3 deletions
  1. +1
    -1
      desc/core/pcm-core.api
  2. +1
    -1
      internal/logic/adapters/createclusterlogic.go
  3. +22
    -0
      internal/logic/adapters/updateclusterlogic.go
  4. +1
    -1
      internal/types/types.go

+ 1
- 1
desc/core/pcm-core.api View File

@@ -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"`


+ 1
- 1
internal/logic/adapters/createclusterlogic.go View File

@@ -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,


+ 22
- 0
internal/logic/adapters/updateclusterlogic.go View File

@@ -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
}

+ 1
- 1
internal/types/types.go View File

@@ -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…
Cancel
Save