feat: 网元_参数配置可用属性值缓存并支持数据修改的功能接口
This commit is contained in:
@@ -60,7 +60,7 @@ func (s *NeConfigController) Info(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 将字符串转json数据
|
||||
if err := json.Unmarshal([]byte(data.ParamJSONStr), &data.ParamData); err != nil {
|
||||
if err := json.Unmarshal([]byte(data.ParamJson), &data.ParamData); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, err.Error()))
|
||||
return
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func (s *NeConfigController) Add(c *gin.Context) {
|
||||
c.JSON(400, result.CodeMsg(400, err.Error()))
|
||||
return
|
||||
}
|
||||
body.ParamJSONStr = string(paramDataByte)
|
||||
body.ParamJson = string(paramDataByte)
|
||||
|
||||
insertId := s.neConfigService.Insert(body)
|
||||
if insertId != "" {
|
||||
@@ -120,7 +120,7 @@ func (s *NeConfigController) Edit(c *gin.Context) {
|
||||
c.JSON(400, result.CodeMsg(400, err.Error()))
|
||||
return
|
||||
}
|
||||
body.ParamJSONStr = string(paramDataByte)
|
||||
body.ParamJson = string(paramDataByte)
|
||||
|
||||
rows := s.neConfigService.Update(body)
|
||||
if rows > 0 {
|
||||
@@ -132,16 +132,16 @@ func (s *NeConfigController) Edit(c *gin.Context) {
|
||||
|
||||
// 网元参数配置可用属性值删除
|
||||
//
|
||||
// DELETE /:ids
|
||||
// DELETE /
|
||||
func (s *NeConfigController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
ids := c.Param("ids")
|
||||
if ids == "" {
|
||||
id, okId := c.GetQuery("id")
|
||||
if id == "" || !okId {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
idsArr := strings.Split(ids, ",")
|
||||
idsArr := strings.Split(id, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(idsArr)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
@@ -173,26 +173,26 @@ func (s *NeConfigController) ListByNeType(c *gin.Context) {
|
||||
// 网元参数配置数据信息
|
||||
//
|
||||
// GET /data
|
||||
func (s *NeConfigController) Data(c *gin.Context) {
|
||||
func (s *NeConfigController) DataInfo(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
NeType string `form:"neType" binding:"required"` // 网元类型
|
||||
NeId string `form:"neId" binding:"required"` // 网元ID
|
||||
TopTag string `form:"topTag" binding:"required"` // 可用属性
|
||||
var query struct {
|
||||
NeType string `form:"neType" binding:"required"` // 网元类型
|
||||
NeId string `form:"neId" binding:"required"` // 网元ID
|
||||
ParamName string `form:"paramName" binding:"required"` // 可用属性
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeId)
|
||||
if neInfo.NeId != querys.NeId || neInfo.IP == "" {
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(query.NeType, query.NeId)
|
||||
if neInfo.NeId != query.NeId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 网元直连
|
||||
resData, err := neFetchlink.NeConfigInfo(neInfo, querys.TopTag)
|
||||
resData, err := neFetchlink.NeConfigInfo(neInfo, query.ParamName)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
@@ -200,3 +200,118 @@ func (s *NeConfigController) Data(c *gin.Context) {
|
||||
|
||||
c.JSON(200, result.Ok(resData))
|
||||
}
|
||||
|
||||
// 网元参数配置数据修改
|
||||
//
|
||||
// PUT /data
|
||||
func (s *NeConfigController) DataEdit(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"`
|
||||
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")))
|
||||
return
|
||||
}
|
||||
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
if neInfo.NeId != body.NeId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 网元直连
|
||||
resData, err := neFetchlink.NeConfigUpdate(neInfo, body.ParamName, body.Loc, body.ParamData)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(resData))
|
||||
}
|
||||
|
||||
// 网元参数配置数据新增(array)
|
||||
//
|
||||
// POST /data
|
||||
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"` // 数据对象
|
||||
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")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否array
|
||||
info := s.neConfigService.SelectNeConfigByNeTypeAndParamName(body.NeType, body.ParamName)
|
||||
if info.ParamType != "array" {
|
||||
c.JSON(400, result.CodeMsg(400, "this attribute does not support adding"))
|
||||
return
|
||||
}
|
||||
// 必须含有index
|
||||
_, idxOk := body.ParamData["index"]
|
||||
if info.ParamType == "array" && !idxOk {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
if neInfo.NeId != body.NeId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 网元直连
|
||||
resData, err := neFetchlink.NeConfigInstall(neInfo, body.ParamName, body.Loc, body.ParamData)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(resData))
|
||||
}
|
||||
|
||||
// 网元参数配置数据删除(array)
|
||||
//
|
||||
// DELETE /data
|
||||
func (s *NeConfigController) DataRemove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var query struct {
|
||||
NeType string `form:"neType" binding:"required"` // 网元类型
|
||||
NeId string `form:"neId" binding:"required"` // 网元ID
|
||||
ParamName string `form:"paramName" 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")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否array
|
||||
info := s.neConfigService.SelectNeConfigByNeTypeAndParamName(query.NeType, query.ParamName)
|
||||
if info.ParamType != "array" {
|
||||
c.JSON(400, result.CodeMsg(400, "this attribute does not support adding"))
|
||||
return
|
||||
}
|
||||
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(query.NeType, query.NeId)
|
||||
if neInfo.NeId != query.NeId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
// 网元直连
|
||||
resData, err := neFetchlink.NeConfigDelete(neInfo, query.ParamName, query.Loc)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(resData))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user