Signed-off-by: jagger <cossjie@foxmail.com>pull/531/head
| @@ -1480,9 +1480,10 @@ type EditResourceReq { | |||||
| CpuUnit string `json:"cpuUnit,optional"` | CpuUnit string `json:"cpuUnit,optional"` | ||||
| MemoryValue string `json:"memoryValue,optional"` | MemoryValue string `json:"memoryValue,optional"` | ||||
| MemoryUnit string `json:"memoryUnit,optional"` | MemoryUnit string `json:"memoryUnit,optional"` | ||||
| UserId int64 `json:"userId,optional"` | |||||
| } | } | ||||
| type SyncResourceReq { | type SyncResourceReq { | ||||
| Id string `json:"id"` | Id string `json:"id"` | ||||
| UserId int64 `json:"userId"` | |||||
| UserId int64 `json:"userId,optional"` | |||||
| } | } | ||||
| @@ -6,6 +6,7 @@ import ( | |||||
| "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" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" | "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" | |||||
| "net/http" | "net/http" | ||||
| ) | ) | ||||
| @@ -17,6 +18,15 @@ func EditResourceSpecHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||||
| return | 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) | l := core.NewEditResourceSpecLogic(r.Context(), svcCtx) | ||||
| resp, err := l.EditResourceSpec(&req) | resp, err := l.EditResourceSpec(&req) | ||||
| result.HttpResult(r, w, resp, err) | result.HttpResult(r, w, resp, err) | ||||
| @@ -58,7 +58,7 @@ func (l *EditResourceSpecLogic) EditResourceSpec(req *types.EditResourceReq) (re | |||||
| costPerUnit := utils.StringToFloat64(req.CostPerUnit) | costPerUnit := utils.StringToFloat64(req.CostPerUnit) | ||||
| // 4. 更新主资源规格 | // 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 | return nil, err | ||||
| } | } | ||||
| @@ -98,13 +98,14 @@ func validateRequestParams(req *types.EditResourceReq) error { | |||||
| } | } | ||||
| // updateMainResourceSpec 更新主资源规格 | // 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{}). | return tx.Model(&models.TResourceSpec{}). | ||||
| Where("id = ?", id). | Where("id = ?", id). | ||||
| Updates(map[string]interface{}{ | Updates(map[string]interface{}{ | ||||
| "status": status, | "status": status, | ||||
| "cost_type": costType, | "cost_type": costType, | ||||
| "cost_per_unit": costPerUnit, | "cost_per_unit": costPerUnit, | ||||
| "user_id": userId, | |||||
| }). | }). | ||||
| Error | Error | ||||
| } | } | ||||
| @@ -2145,6 +2145,8 @@ type EditResourceReq struct { | |||||
| CpuUnit string `json:"cpuUnit,optional"` | CpuUnit string `json:"cpuUnit,optional"` | ||||
| MemoryValue string `json:"memoryValue,optional"` | MemoryValue string `json:"memoryValue,optional"` | ||||
| MemoryUnit string `json:"memoryUnit,optional"` | MemoryUnit string `json:"memoryUnit,optional"` | ||||
| UserId int64 `json:"userId,optional"` | |||||
| } | } | ||||
| type EndpointsReq struct { | type EndpointsReq struct { | ||||
| @@ -5568,7 +5570,7 @@ type SyncClusterAlertReq struct { | |||||
| type SyncResourceReq struct { | type SyncResourceReq struct { | ||||
| Id string `json:"id"` | Id string `json:"id"` | ||||
| UserId int64 `json:"userId"` | |||||
| UserId int64 `json:"userId,optional"` | |||||
| } | } | ||||
| type Tags struct { | type Tags struct { | ||||