fix: 参数示例数据的存储规则
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
"be.ems/src/modules/practical_training/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -19,7 +18,6 @@ import (
|
||||
var NewPtNeConfigData = &PtNeConfigDataController{
|
||||
ptNeConfigDataService: service.NewPtNeConfigDataService,
|
||||
ptNeConfigDataLogService: service.NewPtNeConfigDataLogService,
|
||||
neInfoService: neService.NewNeInfoImpl,
|
||||
}
|
||||
|
||||
// 网元参数配置服务
|
||||
@@ -30,11 +28,9 @@ type PtNeConfigDataController struct {
|
||||
ptNeConfigDataService service.IPtNeConfigDataService
|
||||
// 实训教学_网元参数配置数据变更日志服务
|
||||
ptNeConfigDataLogService service.IPtNeConfigDataLogService
|
||||
// 网元信息服务
|
||||
neInfoService neService.INeInfo
|
||||
}
|
||||
|
||||
// 保存为示例配置 (仅管理员/教师操作)
|
||||
// 保存为示例配置 (仅管理员操作)
|
||||
//
|
||||
// POST /saveAsDefault
|
||||
func (s *PtNeConfigDataController) SaveAsDefault(c *gin.Context) {
|
||||
@@ -48,24 +44,12 @@ func (s *PtNeConfigDataController) SaveAsDefault(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP获取网元状态
|
||||
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
|
||||
}
|
||||
|
||||
stubType := "" // 存根数据类型 0系统 1班级 2个人
|
||||
loginUser, _ := ctx.LoginUser(c)
|
||||
for _, v := range loginUser.User.Roles {
|
||||
if v.RoleKey == "admin" {
|
||||
stubType = "0"
|
||||
} else if v.RoleKey == "teacher" {
|
||||
stubType = "1"
|
||||
s.ptNeConfigDataService.SaveAsDefault(body.NeType, body.NeId)
|
||||
}
|
||||
}
|
||||
operaUserName := loginUser.User.NickName
|
||||
s.ptNeConfigDataService.SaveAsDefaultByType(neInfo, stubType, operaUserName)
|
||||
|
||||
c.JSON(200, result.Ok(nil))
|
||||
}
|
||||
@@ -83,9 +67,17 @@ func (s *PtNeConfigDataController) ResetAsDefault(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
stubType := "2" // 存根数据类型 0系统 1班级 2个人
|
||||
operaUserName := ctx.LoginUserToUserName(c)
|
||||
s.ptNeConfigDataService.ResetAsDefaultByType(body.NeType, stubType, operaUserName)
|
||||
loginUser, _ := ctx.LoginUser(c)
|
||||
operaUserName := loginUser.User.UserName
|
||||
deptId := loginUser.User.DeptID
|
||||
for _, v := range loginUser.User.Roles {
|
||||
if v.RoleKey == "teacher" {
|
||||
s.ptNeConfigDataService.ResetAsDefault(operaUserName, "1", body.NeType, deptId)
|
||||
}
|
||||
if v.RoleKey == "student" {
|
||||
s.ptNeConfigDataService.ResetAsDefault(operaUserName, "2", body.NeType, deptId)
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(200, result.Ok(nil))
|
||||
}
|
||||
@@ -104,20 +96,36 @@ func (s *PtNeConfigDataController) Info(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
loginUser, _ := ctx.LoginUser(c)
|
||||
currentUserName := loginUser.User.UserName
|
||||
deptId := loginUser.User.DeptID
|
||||
stubType := "2" // 存根数据类型 0系统 1班级 2个人
|
||||
for _, v := range loginUser.User.Roles {
|
||||
if v.RoleKey == "admin" {
|
||||
stubType = "0"
|
||||
}
|
||||
if v.RoleKey == "teacher" {
|
||||
stubType = "1"
|
||||
}
|
||||
if v.RoleKey == "student" {
|
||||
stubType = "2"
|
||||
}
|
||||
}
|
||||
// 优先查询个人的数据,没有就向系统取
|
||||
param := model.PtNeConfigData{
|
||||
CreateBy: ctx.LoginUserToUserName(c),
|
||||
CreateBy: currentUserName,
|
||||
NeType: querys.NeType,
|
||||
StubType: "2",
|
||||
StubType: stubType,
|
||||
ParamName: querys.ParamName,
|
||||
DeptId: deptId,
|
||||
}
|
||||
info := s.ptNeConfigDataService.SelectByStubType(param)
|
||||
|
||||
// 输出数据内容
|
||||
if info.ParamJson != "" {
|
||||
c.JSON(200, result.Ok(map[string]any{
|
||||
"paramType": info.ParamType,
|
||||
"paramData": info.ParamData,
|
||||
"type": info.ParamType,
|
||||
"data": info.ParamData,
|
||||
}))
|
||||
return
|
||||
}
|
||||
@@ -140,13 +148,28 @@ func (s *PtNeConfigDataController) Edit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
currentUserName := ctx.LoginUserToUserName(c)
|
||||
loginUser, _ := ctx.LoginUser(c)
|
||||
currentUserName := loginUser.User.UserName
|
||||
deptId := loginUser.User.DeptID
|
||||
stubType := "2" // 存根数据类型 0系统 1班级 2个人
|
||||
for _, v := range loginUser.User.Roles {
|
||||
if v.RoleKey == "admin" {
|
||||
stubType = "0"
|
||||
}
|
||||
if v.RoleKey == "teacher" {
|
||||
stubType = "1"
|
||||
}
|
||||
if v.RoleKey == "student" {
|
||||
stubType = "2"
|
||||
}
|
||||
}
|
||||
// 优先查询个人的数据,没有就向系统取
|
||||
param := model.PtNeConfigData{
|
||||
CreateBy: currentUserName,
|
||||
NeType: body.NeType,
|
||||
StubType: "2",
|
||||
StubType: stubType,
|
||||
ParamName: body.ParamName,
|
||||
DeptId: deptId,
|
||||
}
|
||||
info := s.ptNeConfigDataService.SelectByStubType(param)
|
||||
changeLog := model.PtNeConfigDataLog{
|
||||
@@ -219,18 +242,19 @@ func (s *PtNeConfigDataController) Edit(c *gin.Context) {
|
||||
changeLog.ParamJsonNew = info.ParamJson
|
||||
|
||||
// 个人有数据就更新
|
||||
if info.StubType == "2" {
|
||||
if info.StubType == stubType {
|
||||
info.UpdateBy = currentUserName
|
||||
s.ptNeConfigDataService.Update(info)
|
||||
} else {
|
||||
s.ptNeConfigDataService.Insert(model.PtNeConfigData{
|
||||
CreateBy: currentUserName,
|
||||
NeType: info.NeType,
|
||||
StubType: "2",
|
||||
StubType: stubType,
|
||||
ParamName: info.ParamName,
|
||||
ParamDisplay: info.ParamDisplay,
|
||||
ParamType: info.ParamType,
|
||||
ParamJson: info.ParamJson,
|
||||
DeptId: deptId,
|
||||
})
|
||||
}
|
||||
// 保留变更日志
|
||||
@@ -255,13 +279,28 @@ func (s *PtNeConfigDataController) Add(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
currentUserName := ctx.LoginUserToUserName(c)
|
||||
loginUser, _ := ctx.LoginUser(c)
|
||||
currentUserName := loginUser.User.UserName
|
||||
deptId := loginUser.User.DeptID
|
||||
stubType := "2" // 存根数据类型 0系统 1班级 2个人
|
||||
for _, v := range loginUser.User.Roles {
|
||||
if v.RoleKey == "admin" {
|
||||
stubType = "0"
|
||||
}
|
||||
if v.RoleKey == "teacher" {
|
||||
stubType = "1"
|
||||
}
|
||||
if v.RoleKey == "student" {
|
||||
stubType = "2"
|
||||
}
|
||||
}
|
||||
// 优先查询个人的数据,没有就向系统取
|
||||
param := model.PtNeConfigData{
|
||||
CreateBy: currentUserName,
|
||||
NeType: body.NeType,
|
||||
StubType: "2",
|
||||
StubType: stubType,
|
||||
ParamName: body.ParamName,
|
||||
DeptId: deptId,
|
||||
}
|
||||
info := s.ptNeConfigDataService.SelectByStubType(param)
|
||||
if info.ParamType != "array" || body.Loc == "" {
|
||||
@@ -317,18 +356,19 @@ func (s *PtNeConfigDataController) Add(c *gin.Context) {
|
||||
changeLog.ParamJsonNew = info.ParamJson
|
||||
|
||||
// 个人有数据就更新
|
||||
if info.StubType == "2" {
|
||||
if info.StubType == stubType {
|
||||
info.UpdateBy = currentUserName
|
||||
s.ptNeConfigDataService.Update(info)
|
||||
} else {
|
||||
s.ptNeConfigDataService.Insert(model.PtNeConfigData{
|
||||
CreateBy: currentUserName,
|
||||
NeType: info.NeType,
|
||||
StubType: "2",
|
||||
StubType: stubType,
|
||||
ParamName: info.ParamName,
|
||||
ParamDisplay: info.ParamDisplay,
|
||||
ParamType: info.ParamType,
|
||||
ParamJson: info.ParamJson,
|
||||
DeptId: deptId,
|
||||
})
|
||||
}
|
||||
// 保留变更日志
|
||||
@@ -352,13 +392,28 @@ func (s *PtNeConfigDataController) Remove(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
currentUserName := ctx.LoginUserToUserName(c)
|
||||
loginUser, _ := ctx.LoginUser(c)
|
||||
currentUserName := loginUser.User.UserName
|
||||
deptId := loginUser.User.DeptID
|
||||
stubType := "2" // 存根数据类型 0系统 1班级 2个人
|
||||
for _, v := range loginUser.User.Roles {
|
||||
if v.RoleKey == "admin" {
|
||||
stubType = "0"
|
||||
}
|
||||
if v.RoleKey == "teacher" {
|
||||
stubType = "1"
|
||||
}
|
||||
if v.RoleKey == "student" {
|
||||
stubType = "2"
|
||||
}
|
||||
}
|
||||
// 优先查询个人的数据,没有就向系统取
|
||||
param := model.PtNeConfigData{
|
||||
CreateBy: currentUserName,
|
||||
NeType: query.NeType,
|
||||
StubType: "2",
|
||||
StubType: stubType,
|
||||
ParamName: query.ParamName,
|
||||
DeptId: deptId,
|
||||
}
|
||||
info := s.ptNeConfigDataService.SelectByStubType(param)
|
||||
if info.ParamType != "array" || query.Loc == "" {
|
||||
@@ -434,18 +489,19 @@ func (s *PtNeConfigDataController) Remove(c *gin.Context) {
|
||||
info.ParamJson = string(paramDataByte)
|
||||
|
||||
// 个人有数据就更新
|
||||
if info.StubType == "2" {
|
||||
if info.StubType == stubType {
|
||||
info.UpdateBy = currentUserName
|
||||
s.ptNeConfigDataService.Update(info)
|
||||
} else {
|
||||
s.ptNeConfigDataService.Insert(model.PtNeConfigData{
|
||||
CreateBy: currentUserName,
|
||||
NeType: info.NeType,
|
||||
StubType: "2",
|
||||
StubType: stubType,
|
||||
ParamName: info.ParamName,
|
||||
ParamDisplay: info.ParamDisplay,
|
||||
ParamType: info.ParamType,
|
||||
ParamJson: info.ParamJson,
|
||||
DeptId: deptId,
|
||||
})
|
||||
}
|
||||
// 保留变更日志
|
||||
|
||||
@@ -14,6 +14,7 @@ type PtNeConfigData struct {
|
||||
ParamDisplay string `json:"paramDisplay" gorm:"param_display"` // 参数显示名
|
||||
ParamType string `json:"paramType" gorm:"param_type"` // 参数类型 list列表单层 array数组多层
|
||||
ParamJson string `json:"paramJson" gorm:"param_json"` // 参数数据
|
||||
DeptId string `json:"deptId" gorm:"dept_id"` // 部门班级ID 100系统
|
||||
|
||||
// ====== 非数据库字段属性 ======
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
// NewPtNeConfigDataRepository 实例化数据层
|
||||
var NewPtNeConfigDataRepository = &PtNeConfigDataRepository{
|
||||
selectSql: `select
|
||||
id, create_by, create_time, update_by, update_time, remark, stub_type, ne_type, param_name, param_display, param_type, param_json
|
||||
id, create_by, create_time, update_by, update_time, remark, stub_type, ne_type, param_name, param_display, param_type, param_json, dept_id
|
||||
from pt_ne_config_data`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
@@ -30,6 +30,7 @@ var NewPtNeConfigDataRepository = &PtNeConfigDataRepository{
|
||||
"param_display": "ParamDisplay",
|
||||
"param_type": "ParamType",
|
||||
"param_json": "ParamJson",
|
||||
"dept_id": "DeptId",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -143,6 +144,10 @@ func (r *PtNeConfigDataRepository) SelectList(param model.PtNeConfigData) []mode
|
||||
conditions = append(conditions, "param_type = ?")
|
||||
params = append(params, param.ParamType)
|
||||
}
|
||||
if param.DeptId != "" {
|
||||
conditions = append(conditions, "dept_id = ?")
|
||||
params = append(params, param.DeptId)
|
||||
}
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
@@ -202,6 +207,9 @@ func (r *PtNeConfigDataRepository) Insert(param model.PtNeConfigData) string {
|
||||
if param.ParamJson != "" {
|
||||
params["param_json"] = param.ParamJson
|
||||
}
|
||||
if param.DeptId != "" {
|
||||
params["dept_id"] = param.DeptId
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||
@@ -257,6 +265,9 @@ func (r *PtNeConfigDataRepository) Update(param model.PtNeConfigData) int64 {
|
||||
if param.ParamJson != "" {
|
||||
params["param_json"] = param.ParamJson
|
||||
}
|
||||
if param.DeptId != "" {
|
||||
params["dept_id"] = param.DeptId
|
||||
}
|
||||
|
||||
// 构建执行语句
|
||||
keys, values := repo.KeyValueByUpdate(params)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
neModel "be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
)
|
||||
|
||||
@@ -25,11 +24,12 @@ type IPtNeConfigDataService interface {
|
||||
// DeleteByIds 批量删除信息
|
||||
DeleteByIds(paramIds []string) (int64, error)
|
||||
|
||||
// SaveAsDefaultByType 保存为默认示例
|
||||
SaveAsDefaultByType(neInfo neModel.NeInfo, stubType, operaUserName string)
|
||||
// SaveAsDefault 系统网元配置保存为系统示例
|
||||
SaveAsDefault(neType, neId string)
|
||||
|
||||
// ResetAsDefaultByType 重置为默认示例
|
||||
ResetAsDefaultByType(neType, stubType, operaUserName string)
|
||||
// ResetAsDefault 重置配置示例
|
||||
// stubType:2个人为班级示例 1班级为系统示例
|
||||
ResetAsDefault(operaUserName, stubType, neType, deptId string)
|
||||
|
||||
// SelectByStubType 通过存根类型查询
|
||||
SelectByStubType(param model.PtNeConfigData) model.PtNeConfigData
|
||||
|
||||
@@ -78,8 +78,17 @@ func (r *PtNeConfigDataService) DeleteByIds(paramIds []string) (int64, error) {
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// SaveAsDefaultByType 保存为默认示例
|
||||
func (r *PtNeConfigDataService) SaveAsDefaultByType(neInfo neModel.NeInfo, stubType, operaUserName string) {
|
||||
// SaveAsDefault 系统网元配置保存为系统示例
|
||||
func (r *PtNeConfigDataService) SaveAsDefault(neType, neId string) {
|
||||
// 查询网元获取IP获取网元状态
|
||||
neInfo := r.neInfoService.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId || neInfo.IP == "" {
|
||||
return
|
||||
}
|
||||
|
||||
stubType := "0"
|
||||
operaUserName := "admin"
|
||||
deptId := "100"
|
||||
confs := r.neConfigService.SelectList(neModel.NeConfig{NeType: neInfo.NeType})
|
||||
for _, v := range confs {
|
||||
// 查询是否存在记录
|
||||
@@ -113,6 +122,7 @@ func (r *PtNeConfigDataService) SaveAsDefaultByType(neInfo neModel.NeInfo, stubT
|
||||
ParamDisplay: v.ParamDisplay,
|
||||
ParamType: v.ParamType,
|
||||
ParamJson: string(paramDataByte),
|
||||
DeptId: deptId,
|
||||
})
|
||||
}
|
||||
// 更新
|
||||
@@ -121,14 +131,24 @@ func (r *PtNeConfigDataService) SaveAsDefaultByType(neInfo neModel.NeInfo, stubT
|
||||
item.UpdateBy = operaUserName
|
||||
item.ParamDisplay = v.ParamDisplay
|
||||
item.ParamJson = string(paramDataByte)
|
||||
item.DeptId = deptId
|
||||
r.Update(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ResetAsDefaultByType 重置为默认示例
|
||||
func (r *PtNeConfigDataService) ResetAsDefaultByType(neType, stubType, operaUserName string) {
|
||||
ptConfs := r.SelectList(model.PtNeConfigData{StubType: "0", NeType: neType})
|
||||
// ResetAsDefault 重置配置示例
|
||||
// stubType:2个人为班级示例 1班级为系统示例
|
||||
func (r *PtNeConfigDataService) ResetAsDefault(operaUserName, stubType, neType, deptId string) {
|
||||
rootStubType := "1"
|
||||
if stubType == "1" {
|
||||
rootStubType = "0"
|
||||
}
|
||||
if stubType == "2" {
|
||||
rootStubType = "1"
|
||||
}
|
||||
ptConfs := r.SelectList(model.PtNeConfigData{StubType: rootStubType, NeType: neType})
|
||||
|
||||
for _, v := range ptConfs {
|
||||
// 查询是否存在记录
|
||||
hasItems := r.SelectList(model.PtNeConfigData{
|
||||
@@ -149,6 +169,7 @@ func (r *PtNeConfigDataService) ResetAsDefaultByType(neType, stubType, operaUser
|
||||
ParamDisplay: v.ParamDisplay,
|
||||
ParamType: v.ParamType,
|
||||
ParamJson: v.ParamJson,
|
||||
DeptId: deptId,
|
||||
})
|
||||
}
|
||||
// 更新
|
||||
@@ -157,6 +178,7 @@ func (r *PtNeConfigDataService) ResetAsDefaultByType(neType, stubType, operaUser
|
||||
item.UpdateBy = operaUserName
|
||||
item.ParamDisplay = v.ParamDisplay
|
||||
item.ParamJson = v.ParamJson
|
||||
item.DeptId = deptId
|
||||
r.Update(item)
|
||||
}
|
||||
}
|
||||
@@ -173,6 +195,7 @@ func (r *PtNeConfigDataService) SelectByStubType(param model.PtNeConfigData) mod
|
||||
if len(list) == 0 && param.StubType != "0" {
|
||||
param.CreateBy = ""
|
||||
param.StubType = "0"
|
||||
param.DeptId = "100"
|
||||
list = r.SelectList(param)
|
||||
}
|
||||
var paraData model.PtNeConfigData
|
||||
@@ -192,7 +215,7 @@ func (r *PtNeConfigDataService) ApplyToNe(paramUser, neType string) error {
|
||||
return fmt.Errorf("NeConfigData Not Found")
|
||||
}
|
||||
|
||||
// 找网元,只有一套就固定001
|
||||
// 找网元,只有一套就固定neId:001
|
||||
neInfo := r.neInfoService.SelectNeInfoByNeTypeAndNeID(neType, "001")
|
||||
if neInfo.NeType != neType || neInfo.ID == "" {
|
||||
return fmt.Errorf("NeInfo Not Found")
|
||||
|
||||
Reference in New Issue
Block a user