diff --git a/desc/core/pcm-core.api b/desc/core/pcm-core.api index e826fdbb..7a4f68d2 100644 --- a/desc/core/pcm-core.api +++ b/desc/core/pcm-core.api @@ -1480,9 +1480,10 @@ type EditResourceReq { CpuUnit string `json:"cpuUnit,optional"` MemoryValue string `json:"memoryValue,optional"` MemoryUnit string `json:"memoryUnit,optional"` + UserId int64 `json:"userId,optional"` } type SyncResourceReq { Id string `json:"id"` - UserId int64 `json:"userId"` + UserId int64 `json:"userId,optional"` } \ No newline at end of file diff --git a/internal/handler/core/editresourcespechandler.go b/internal/handler/core/editresourcespechandler.go index 2f6d55a9..fad11727 100644 --- a/internal/handler/core/editresourcespechandler.go +++ b/internal/handler/core/editresourcespechandler.go @@ -6,6 +6,7 @@ import ( "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" "net/http" ) @@ -17,6 +18,15 @@ func EditResourceSpecHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } + token := r.Header.Get("Authorization") + // 获取用户信息 + jccUserInfo, err := utils.ParseTokenWithoutVerify(token) + if err != nil { + result.ParamErrorResult(r, w, err) + return + } + req.UserId = jccUserInfo.Id + l := core.NewEditResourceSpecLogic(r.Context(), svcCtx) resp, err := l.EditResourceSpec(&req) result.HttpResult(r, w, resp, err) diff --git a/internal/logic/core/editresourcespeclogic.go b/internal/logic/core/editresourcespeclogic.go index e6ef8a5b..c3893def 100644 --- a/internal/logic/core/editresourcespeclogic.go +++ b/internal/logic/core/editresourcespeclogic.go @@ -58,7 +58,7 @@ func (l *EditResourceSpecLogic) EditResourceSpec(req *types.EditResourceReq) (re costPerUnit := utils.StringToFloat64(req.CostPerUnit) // 4. 更新主资源规格 - if err = updateMainResourceSpec(tx, req.Id, statusInt, req.CostType, costPerUnit); err != nil { + if err = updateMainResourceSpec(tx, req.Id, statusInt, req.CostType, costPerUnit, req.UserId); err != nil { return nil, err } @@ -98,13 +98,14 @@ func validateRequestParams(req *types.EditResourceReq) error { } // updateMainResourceSpec 更新主资源规格 -func updateMainResourceSpec(tx *gorm.DB, id int64, status int64, costType string, costPerUnit float64) error { +func updateMainResourceSpec(tx *gorm.DB, id int64, status int64, costType string, costPerUnit float64, userId int64) error { return tx.Model(&models.TResourceSpec{}). Where("id = ?", id). Updates(map[string]interface{}{ "status": status, "cost_type": costType, "cost_per_unit": costPerUnit, + "user_id": userId, }). Error } diff --git a/internal/types/types.go b/internal/types/types.go index 4d106b80..319afae9 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -2145,6 +2145,8 @@ type EditResourceReq struct { CpuUnit string `json:"cpuUnit,optional"` MemoryValue string `json:"memoryValue,optional"` MemoryUnit string `json:"memoryUnit,optional"` + + UserId int64 `json:"userId,optional"` } type EndpointsReq struct { @@ -5568,7 +5570,7 @@ type SyncClusterAlertReq struct { type SyncResourceReq struct { Id string `json:"id"` - UserId int64 `json:"userId"` + UserId int64 `json:"userId,optional"` } type Tags struct {