fix: 参数配置array多层loc属性控制
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user