Skip to content

Commit

Permalink
555
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq committed Nov 1, 2024
1 parent 4bc354f commit 14b2741
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (c *MachineResourceHandler) BatchUpdate(r *rf.Context) {

// do update
err = model.DB.Self.Table(model.TbRpDetailName()).Select("dedicated_biz", "rs_type", "storage_device", "rack_id",
"label").
"labels").
Where("bk_host_id in (?)", input.BkHostIds).Updates(updateMap).Error
if err != nil {
c.SendResponse(r, err, err.Error())
Expand All @@ -167,7 +167,7 @@ type MachineResourceInputParam struct {
// MachineResource 主机参数
type MachineResource struct {
BkHostID int `json:"bk_host_id" binding:"required"`
Labels map[string]string `json:"labels"`
Labels []string `json:"labels"`
ForBiz int `json:"for_biz"`
RsType string `json:"resource_type"`
StorageDevice map[string]bk.DiskDetail `json:"storage_device"`
Expand All @@ -185,11 +185,13 @@ func (c *MachineResourceHandler) Update(r *rf.Context) {
for _, v := range input.Data {
updateMap := make(map[string]interface{})
if len(v.Labels) > 0 {
l, err := cmutil.ConverMapToJsonStr(v.Labels)
lableJson, err := json.Marshal(v.Labels)
if err != nil {
logger.Error(fmt.Sprintf("ConverMapToJsonStr Failed %s", err.Error()))
logger.Error(fmt.Sprintf("ConverLableToJsonStr Failed,Error:%s", err.Error()))
c.SendResponse(r, err, err.Error())
return
}
updateMap["lable"] = l
updateMap["labels"] = lableJson
}
if v.ForBiz > 0 {
updateMap["dedicated_biz"] = v.ForBiz
Expand All @@ -207,7 +209,7 @@ func (c *MachineResourceHandler) Update(r *rf.Context) {
updateMap["storage_device"] = storageJson
}
err := tx.Model(&model.TbRpDetail{}).Table(model.TbRpDetailName()).Select("dedicated_biz", "rs_type",
"label").Where("bk_host_id=?", v.BkHostID).Updates(updateMap).Error
"labels").Where("bk_host_id=?", v.BkHostID).Updates(updateMap).Error
if err != nil {
tx.Rollback()
logger.Error(fmt.Sprintf("conver resource types Failed,Error:%s", err.Error()))
Expand Down

0 comments on commit 14b2741

Please sign in to comment.