From 9d700a5c7e69f703ed4c897e18f647ad2e2220ea Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Thu, 4 Jul 2024 20:36:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=82=E6=95=B0=E9=85=8D=E7=BD=AEarra?= =?UTF-8?q?y=E5=A4=9A=E5=B1=82loc=E5=B1=9E=E6=80=A7=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../network_element/controller/ne_config.go | 24 ++++++++++--------- .../network_element/fetch_link/ne_config.go | 17 +++++-------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/modules/network_element/controller/ne_config.go b/src/modules/network_element/controller/ne_config.go index 0b30f62e..d518461a 100644 --- a/src/modules/network_element/controller/ne_config.go +++ b/src/modules/network_element/controller/ne_config.go @@ -211,6 +211,7 @@ func (s *NeConfigController) DataEdit(c *gin.Context) { NeId string `json:"neId" binding:"required"` // 网元ID ParamName string `json:"paramName" binding:"required"` ParamData map[string]any `json:"paramData" binding:"required"` + Loc string `json:"loc"` // 仅array使用与数据对象内index一致,有多层时划分嵌套层(index/subParamName/index) } if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil { c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) @@ -224,12 +225,12 @@ func (s *NeConfigController) DataEdit(c *gin.Context) { } // 网元直连 - resData, err := neFetchlink.NeConfigInfoEdit(neInfo, body.ParamName, body.ParamData) + resData, err := neFetchlink.NeConfigInfoEdit(neInfo, body.ParamName, body.Loc, body.ParamData) if err != nil { c.JSON(200, result.ErrMsg(err.Error())) return } - c.JSON(200, result.Ok(resData)) + c.JSON(200, result.OkData(resData)) } // 网元参数配置数据新增(array) @@ -238,10 +239,11 @@ func (s *NeConfigController) DataEdit(c *gin.Context) { func (s *NeConfigController) DataAdd(c *gin.Context) { language := ctx.AcceptLanguage(c) var body struct { - NeType string `json:"neType" binding:"required"` // 网元类型 - NeId string `json:"neId" binding:"required"` // 网元ID - ParamName string `json:"paramName" binding:"required"` - ParamData map[string]any `json:"paramData" binding:"required"` + NeType string `json:"neType" binding:"required"` // 网元类型 + NeId string `json:"neId" binding:"required"` // 网元ID + ParamName string `json:"paramName" binding:"required"` // 根据配置可选值 + ParamData map[string]any `json:"paramData" binding:"required"` // 数据对象 + Loc string `json:"loc" binding:"required"` // 与数据对象内index一致,有多层时划分嵌套层(index/subParamName/index) } if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil { c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) @@ -268,12 +270,12 @@ func (s *NeConfigController) DataAdd(c *gin.Context) { } // 网元直连 - resData, err := neFetchlink.NeConfigInfoAdd(neInfo, body.ParamName, body.ParamData) + resData, err := neFetchlink.NeConfigInfoAdd(neInfo, body.ParamName, body.Loc, body.ParamData) if err != nil { c.JSON(200, result.ErrMsg(err.Error())) return } - c.JSON(200, result.Ok(resData)) + c.JSON(200, result.OkData(resData)) } // 网元参数配置数据删除(array) @@ -285,7 +287,7 @@ func (s *NeConfigController) DataRemove(c *gin.Context) { NeType string `form:"neType" binding:"required"` // 网元类型 NeId string `form:"neId" binding:"required"` // 网元ID ParamName string `form:"paramName" binding:"required"` - Index string `form:"index" binding:"required"` + Loc string `form:"loc" binding:"required"` // 与数据对象内index一致,有多层时划分嵌套层(index/subParamName/index) } if err := c.ShouldBindQuery(&query); err != nil { c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) @@ -306,10 +308,10 @@ func (s *NeConfigController) DataRemove(c *gin.Context) { } // 网元直连 - resData, err := neFetchlink.NeConfigInfoDel(neInfo, query.ParamName, query.Index) + resData, err := neFetchlink.NeConfigInfoDel(neInfo, query.ParamName, query.Loc) if err != nil { c.JSON(200, result.ErrMsg(err.Error())) return } - c.JSON(200, result.Ok(resData)) + c.JSON(200, result.OkData(resData)) } diff --git a/src/modules/network_element/fetch_link/ne_config.go b/src/modules/network_element/fetch_link/ne_config.go index 09dfb1a7..cf0b46e0 100644 --- a/src/modules/network_element/fetch_link/ne_config.go +++ b/src/modules/network_element/fetch_link/ne_config.go @@ -70,11 +70,10 @@ func NeConfigInfo(neInfo model.NeInfo, paramName string) (map[string]any, error) } // NeConfigInfoEdit 网元配置更新 -func NeConfigInfoEdit(neInfo model.NeInfo, paramName string, data map[string]any) (map[string]any, error) { +func NeConfigInfoEdit(neInfo model.NeInfo, paramName, loc string, data map[string]any) (map[string]any, error) { // array需要层级 - loc := "" - if v, ok := data["index"]; ok { - loc = fmt.Sprintf("?loc=%v", v) + if loc != "" { + loc = fmt.Sprintf("?loc=%v", loc) } // 网元参数配置新增(array) neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s%s", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, loc) @@ -104,11 +103,7 @@ func NeConfigInfoEdit(neInfo model.NeInfo, paramName string, data map[string]any } // NeConfigInfoAdd 网元配置新增 array -func NeConfigInfoAdd(neInfo model.NeInfo, paramName string, data map[string]any) (map[string]any, error) { - loc, locOk := data["index"] // 层级 index - if !locOk { - return nil, fmt.Errorf("data not index") - } +func NeConfigInfoAdd(neInfo model.NeInfo, paramName, loc string, data map[string]any) (map[string]any, error) { // 网元参数配置新增(array) neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s?loc=%v", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, loc) resBytes, err := fetch.PostJSON(neUrl, data, nil) @@ -137,9 +132,9 @@ func NeConfigInfoAdd(neInfo model.NeInfo, paramName string, data map[string]any) } // NeConfigInfoDel 网元配置删除 array -func NeConfigInfoDel(neInfo model.NeInfo, paramName, index string) (map[string]any, error) { +func NeConfigInfoDel(neInfo model.NeInfo, paramName, loc string) (map[string]any, error) { // 网元参数配置删除(array) - neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s?loc=%v", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, index) + neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s?loc=%v", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, loc) resBytes, err := fetch.Delete(neUrl, nil) var resData map[string]any if err != nil {