feat: 网元配置更新保留变更日志数据
This commit is contained in:
@@ -17,8 +17,9 @@ import (
|
||||
|
||||
// NewPtNeConfigData 网元参数配置服务 实例化控制层
|
||||
var NewPtNeConfigData = &PtNeConfigData{
|
||||
ptNeConfigDataService: service.NewPtNeConfigDataService,
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
ptNeConfigDataService: service.NewPtNeConfigDataService,
|
||||
ptNeConfigDataLogService: service.NewPtNeConfigDataLogService,
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
}
|
||||
|
||||
// 网元参数配置服务
|
||||
@@ -27,6 +28,8 @@ var NewPtNeConfigData = &PtNeConfigData{
|
||||
type PtNeConfigData struct {
|
||||
// 实训教学_网元参数配置服务
|
||||
ptNeConfigDataService service.IPtNeConfigDataService
|
||||
// 实训教学_网元参数配置数据变更日志服务
|
||||
ptNeConfigDataLogService service.IPtNeConfigDataLogService
|
||||
// 网元信息服务
|
||||
neInfoService neService.INeInfo
|
||||
}
|
||||
@@ -55,10 +58,9 @@ func (s *PtNeConfigData) Info(c *gin.Context) {
|
||||
|
||||
// 输出数据内容
|
||||
if info.ParamJson != "" {
|
||||
c.JSON(200, result.Ok(map[string]any{
|
||||
"data": info.ParamData,
|
||||
"paramType": info.ParamType,
|
||||
}))
|
||||
data := info.ParamData
|
||||
data["paramType"] = info.ParamType
|
||||
c.JSON(200, result.Ok(data))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
@@ -115,7 +117,7 @@ func (s *PtNeConfigData) Add(c *gin.Context) {
|
||||
|
||||
// 网元参数配置修改
|
||||
//
|
||||
// PUT /
|
||||
// PUT /?loc=1
|
||||
func (s *PtNeConfigData) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body model.PtNeConfigData
|
||||
@@ -133,8 +135,48 @@ func (s *PtNeConfigData) Edit(c *gin.Context) {
|
||||
ParamName: body.ParamName,
|
||||
}
|
||||
info := s.ptNeConfigDataService.SelectByStubType(param)
|
||||
loc, locOk := c.GetQuery("loc")
|
||||
if info.ParamType == "array" && !locOk {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
changeLog := model.PtNeConfigDataLog{
|
||||
CreateBy: currentUserName,
|
||||
StubType: info.StubType,
|
||||
NeType: info.NeType,
|
||||
ParamName: info.ParamName,
|
||||
ParamDisplay: info.ParamDisplay,
|
||||
ParamType: info.ParamType,
|
||||
}
|
||||
|
||||
// 要修改的属性
|
||||
if infoDataArr, ok := info.ParamData["data"]; ok {
|
||||
arr := infoDataArr.([]any)
|
||||
// 单层
|
||||
if info.ParamType == "list" && len(arr) == 1 {
|
||||
for k, v := range body.ParamData {
|
||||
item := arr[0].(map[string]any)
|
||||
if _, ok := item[k]; ok {
|
||||
item[k] = v
|
||||
arr[0] = item
|
||||
}
|
||||
}
|
||||
}
|
||||
// 多层
|
||||
if info.ParamType == "array" {
|
||||
if len(arr) == 0 {
|
||||
arr = []any{body.ParamData}
|
||||
} else {
|
||||
idx := parse.Number(loc)
|
||||
if idx < 0 || int(idx) >= len(arr) {
|
||||
c.JSON(400, result.CodeMsg(400, "loc over data step"))
|
||||
return
|
||||
}
|
||||
arr[idx] = body.ParamData
|
||||
}
|
||||
}
|
||||
info.ParamData["data"] = arr
|
||||
}
|
||||
|
||||
// 将json数据转字符串存储
|
||||
paramDataByte, err := json.Marshal(info.ParamData)
|
||||
@@ -142,9 +184,11 @@ func (s *PtNeConfigData) Edit(c *gin.Context) {
|
||||
c.JSON(400, result.CodeMsg(400, err.Error()))
|
||||
return
|
||||
}
|
||||
changeLog.ParamJsonOld = info.ParamJson
|
||||
info.ParamJson = string(paramDataByte)
|
||||
changeLog.ParamJsonNew = info.ParamJson
|
||||
|
||||
// 个人没数据要新增
|
||||
// 个人有数据就更新
|
||||
if info.StubType == "2" {
|
||||
info.UpdateBy = currentUserName
|
||||
s.ptNeConfigDataService.Update(info)
|
||||
@@ -155,9 +199,12 @@ func (s *PtNeConfigData) Edit(c *gin.Context) {
|
||||
StubType: "2",
|
||||
ParamName: info.ParamName,
|
||||
ParamDisplay: info.ParamDisplay,
|
||||
ParamType: info.ParamType,
|
||||
ParamJson: info.ParamJson,
|
||||
})
|
||||
}
|
||||
// 保留变更日志
|
||||
s.ptNeConfigDataLogService.Insert(changeLog)
|
||||
|
||||
c.JSON(204, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user