fix: 参数配置array多层loc属性控制

This commit is contained in:
TsMask
2024-07-04 20:36:39 +08:00
parent 4aae6f4496
commit 9d700a5c7e
2 changed files with 19 additions and 22 deletions

View File

@@ -211,6 +211,7 @@ func (s *NeConfigController) DataEdit(c *gin.Context) {
NeId string `json:"neId" binding:"required"` // 网元ID NeId string `json:"neId" binding:"required"` // 网元ID
ParamName string `json:"paramName" binding:"required"` ParamName string `json:"paramName" binding:"required"`
ParamData map[string]any `json:"paramData" 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 { if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) 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 { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, result.ErrMsg(err.Error()))
return return
} }
c.JSON(200, result.Ok(resData)) c.JSON(200, result.OkData(resData))
} }
// 网元参数配置数据新增array // 网元参数配置数据新增array
@@ -238,10 +239,11 @@ func (s *NeConfigController) DataEdit(c *gin.Context) {
func (s *NeConfigController) DataAdd(c *gin.Context) { func (s *NeConfigController) DataAdd(c *gin.Context) {
language := ctx.AcceptLanguage(c) language := ctx.AcceptLanguage(c)
var body struct { var body struct {
NeType string `json:"neType" binding:"required"` // 网元类型 NeType string `json:"neType" binding:"required"` // 网元类型
NeId string `json:"neId" binding:"required"` // 网元ID NeId string `json:"neId" binding:"required"` // 网元ID
ParamName string `json:"paramName" binding:"required"` ParamName string `json:"paramName" binding:"required"` // 根据配置可选值
ParamData map[string]any `json:"paramData" 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 { if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) 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 { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, result.ErrMsg(err.Error()))
return return
} }
c.JSON(200, result.Ok(resData)) c.JSON(200, result.OkData(resData))
} }
// 网元参数配置数据删除array // 网元参数配置数据删除array
@@ -285,7 +287,7 @@ func (s *NeConfigController) DataRemove(c *gin.Context) {
NeType string `form:"neType" binding:"required"` // 网元类型 NeType string `form:"neType" binding:"required"` // 网元类型
NeId string `form:"neId" binding:"required"` // 网元ID NeId string `form:"neId" binding:"required"` // 网元ID
ParamName string `form:"paramName" binding:"required"` 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 { if err := c.ShouldBindQuery(&query); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) 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 { if err != nil {
c.JSON(200, result.ErrMsg(err.Error())) c.JSON(200, result.ErrMsg(err.Error()))
return return
} }
c.JSON(200, result.Ok(resData)) c.JSON(200, result.OkData(resData))
} }

View File

@@ -70,11 +70,10 @@ func NeConfigInfo(neInfo model.NeInfo, paramName string) (map[string]any, error)
} }
// NeConfigInfoEdit 网元配置更新 // 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需要层级 // array需要层级
loc := "" if loc != "" {
if v, ok := data["index"]; ok { loc = fmt.Sprintf("?loc=%v", loc)
loc = fmt.Sprintf("?loc=%v", v)
} }
// 网元参数配置新增array // 网元参数配置新增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) 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 // NeConfigInfoAdd 网元配置新增 array
func NeConfigInfoAdd(neInfo model.NeInfo, paramName string, data map[string]any) (map[string]any, error) { func NeConfigInfoAdd(neInfo model.NeInfo, paramName, loc string, data map[string]any) (map[string]any, error) {
loc, locOk := data["index"] // 层级 index
if !locOk {
return nil, fmt.Errorf("data not index")
}
// 网元参数配置新增array // 网元参数配置新增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) 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) resBytes, err := fetch.PostJSON(neUrl, data, nil)
@@ -137,9 +132,9 @@ func NeConfigInfoAdd(neInfo model.NeInfo, paramName string, data map[string]any)
} }
// NeConfigInfoDel 网元配置删除 array // 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 // 网元参数配置删除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) resBytes, err := fetch.Delete(neUrl, nil)
var resData map[string]any var resData map[string]any
if err != nil { if err != nil {