feat: 参数操作历史还原到操作前后的功能接口
This commit is contained in:
@@ -7,12 +7,15 @@ import (
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/modules/practical_training/model"
|
||||
"be.ems/src/modules/practical_training/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// NewPtNeConfigDataLog 实例化控制层
|
||||
var NewPtNeConfigDataLog = &PtNeConfigDataLog{
|
||||
ptNeConfigDataService: service.NewPtNeConfigDataService,
|
||||
ptNeConfigDataLogService: service.NewPtNeConfigDataLogService,
|
||||
}
|
||||
|
||||
@@ -20,22 +23,104 @@ var NewPtNeConfigDataLog = &PtNeConfigDataLog{
|
||||
//
|
||||
// PATH /neConfigDataLog
|
||||
type PtNeConfigDataLog struct {
|
||||
// 实训教学_网元参数配置服务
|
||||
ptNeConfigDataService service.IPtNeConfigDataService
|
||||
// 实训教学_网元参数配置数据变更日志服务
|
||||
ptNeConfigDataLogService service.IPtNeConfigDataLogService
|
||||
}
|
||||
|
||||
// 网元参数配置数据变更日志信息
|
||||
// 网元参数配置数据变更日志列表
|
||||
//
|
||||
// GET /
|
||||
func (s *PtNeConfigDataLog) Info(c *gin.Context) {
|
||||
query := ctx.QueryMap(c)
|
||||
// 指定查询个人的数据
|
||||
query["stubType"] = "2"
|
||||
loginUser, _ := ctx.LoginUser(c)
|
||||
currentUserName := loginUser.User.UserName
|
||||
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, ok := query["student"]; ok && v != "" {
|
||||
currentUserName = v.(string)
|
||||
stubType = "2"
|
||||
}
|
||||
}
|
||||
if v.RoleKey == "student" {
|
||||
stubType = "2"
|
||||
}
|
||||
}
|
||||
query["stubType"] = stubType
|
||||
query["createBy"] = currentUserName
|
||||
data := s.ptNeConfigDataLogService.SelectPage(query)
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// 网元参数配置数据变更日志还原到数据
|
||||
//
|
||||
// PUT /restore
|
||||
func (s *PtNeConfigDataLog) Restore(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
ID string `json:"id" binding:"required"` // 变更日志ID
|
||||
Value string `json:"value" binding:"required,oneof=old new"` // 还原属性 old旧信息 new新信息
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
loginUser, _ := ctx.LoginUser(c)
|
||||
currentUserName := loginUser.User.UserName
|
||||
deptId := loginUser.User.DeptID
|
||||
stubType := "2" // 存根数据类型 0系统 1班级 2个人
|
||||
|
||||
// 变更日志
|
||||
logInfo := s.ptNeConfigDataLogService.SelectById(body.ID)
|
||||
if logInfo.ID != body.ID && logInfo.CreateBy != currentUserName {
|
||||
// 变更日志信息不正确!
|
||||
c.JSON(200, result.ErrMsg("Change log information is incorrect!"))
|
||||
return
|
||||
}
|
||||
|
||||
// 优先查询个人的数据,没有就向系统取
|
||||
param := model.PtNeConfigData{
|
||||
CreateBy: currentUserName,
|
||||
NeType: logInfo.NeType,
|
||||
StubType: stubType,
|
||||
ParamName: logInfo.ParamName,
|
||||
DeptId: deptId,
|
||||
}
|
||||
info := s.ptNeConfigDataService.SelectByStubType(param)
|
||||
// 变更日志
|
||||
changeLog := model.PtNeConfigDataLog{
|
||||
CreateBy: currentUserName,
|
||||
StubType: info.StubType,
|
||||
NeType: info.NeType,
|
||||
ParamName: info.ParamName,
|
||||
ParamDisplay: info.ParamDisplay,
|
||||
ParamType: info.ParamType,
|
||||
OperaType: 0,
|
||||
ParamJsonOld: info.ParamJson,
|
||||
}
|
||||
|
||||
if body.Value == "old" {
|
||||
info.ParamJson = logInfo.ParamJsonOld
|
||||
} else {
|
||||
info.ParamJson = logInfo.ParamJsonNew
|
||||
}
|
||||
changeLog.ParamJsonNew = info.ParamJson
|
||||
info.UpdateBy = currentUserName
|
||||
s.ptNeConfigDataService.Update(info)
|
||||
// 保留变更日志
|
||||
s.ptNeConfigDataLogService.Insert(changeLog)
|
||||
c.JSON(200, result.Ok(nil))
|
||||
}
|
||||
|
||||
// 网元参数配置数据变更日志删除
|
||||
//
|
||||
// DELETE /
|
||||
|
||||
@@ -56,6 +56,10 @@ func Setup(router *gin.Engine) {
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewPtNeConfigDataLog.Info,
|
||||
)
|
||||
neConfigDataLogGroup.PUT("/restore",
|
||||
middleware.PreAuthorize(nil),
|
||||
controller.NewPtNeConfigDataLog.Restore,
|
||||
)
|
||||
neConfigDataLogGroup.DELETE("",
|
||||
middleware.PreAuthorize(map[string][]string{"hasRoles": {"admin"}}),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neConfigDataLog", collectlogs.BUSINESS_TYPE_DELETE)),
|
||||
|
||||
@@ -93,7 +93,7 @@ func (r *PtNeConfigApplyRepository) SelectPage(query map[string]any) map[string]
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " limit ?,? "
|
||||
pageSql := " ORDER BY id desc limit ?,? "
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
|
||||
@@ -60,6 +60,10 @@ func (r *PtNeConfigDataLogRepository) SelectPage(query map[string]any) map[strin
|
||||
// 查询条件拼接
|
||||
var conditions []string
|
||||
var params []any
|
||||
if v, ok := query["createBy"]; ok && v != "" {
|
||||
conditions = append(conditions, "create_by = ?")
|
||||
params = append(params, v)
|
||||
}
|
||||
if v, ok := query["neType"]; ok && v != "" {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, v)
|
||||
@@ -108,7 +112,7 @@ func (r *PtNeConfigDataLogRepository) SelectPage(query map[string]any) map[strin
|
||||
|
||||
// 分页
|
||||
pageNum, pageSize := repo.PageNumSize(query["pageNum"], query["pageSize"])
|
||||
pageSql := " limit ?,? "
|
||||
pageSql := " ORDER BY create_time desc limit ?,? "
|
||||
params = append(params, pageNum*pageSize)
|
||||
params = append(params, pageSize)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user