ref: v3变更,,同步v2.2508.4
This commit is contained in:
@@ -10,10 +10,8 @@ import (
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/utils/file"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/modules/ne/model"
|
||||
neService "be.ems/src/modules/ne/service"
|
||||
systemService "be.ems/src/modules/system/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -22,7 +20,6 @@ import (
|
||||
var NewNeConfigBackup = &NeConfigBackupController{
|
||||
neConfigBackupService: neService.NewNeConfigBackup,
|
||||
neInfoService: neService.NewNeInfo,
|
||||
sysConfigService: systemService.NewSysConfig,
|
||||
}
|
||||
|
||||
// 网元配置文件备份记录
|
||||
@@ -31,7 +28,6 @@ var NewNeConfigBackup = &NeConfigBackupController{
|
||||
type NeConfigBackupController struct {
|
||||
neConfigBackupService *neService.NeConfigBackup // 网元配置文件备份记录服务
|
||||
neInfoService *neService.NeInfo // 网元信息服务
|
||||
sysConfigService *systemService.SysConfig // 参数配置服务
|
||||
}
|
||||
|
||||
// 网元配置文件备份记录列表
|
||||
@@ -39,6 +35,11 @@ type NeConfigBackupController struct {
|
||||
// GET /list
|
||||
func (s NeConfigBackupController) List(c *gin.Context) {
|
||||
query := reqctx.QueryMap(c)
|
||||
coreUid, coreUidOk := query["coreUid"]
|
||||
if !coreUidOk || coreUid == "" {
|
||||
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: coreUid is empty"))
|
||||
return
|
||||
}
|
||||
rows, total := s.neConfigBackupService.FindByPage(query)
|
||||
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
|
||||
}
|
||||
@@ -48,19 +49,29 @@ func (s NeConfigBackupController) List(c *gin.Context) {
|
||||
// GET /download?id=xx
|
||||
func (s NeConfigBackupController) Download(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
id := parse.Number(c.Query("id"))
|
||||
if id <= 0 {
|
||||
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: id is empty"))
|
||||
var query struct {
|
||||
CoreUID string `form:"coreUid" binding:"required"` // 核心网唯一标识
|
||||
NeUID string `form:"neUid" binding:"required"` // 网元唯一标识
|
||||
ID int64 `form:"id" binding:"required"` // 记录ID
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
item := s.neConfigBackupService.FindById(id)
|
||||
if item.ID != id {
|
||||
// 没有可访问主机命令数据!
|
||||
// 检查是否存在
|
||||
rows := s.neConfigBackupService.Find(model.NeConfigBackup{
|
||||
CoreUID: query.CoreUID,
|
||||
NeUID: query.NeUID,
|
||||
ID: query.ID,
|
||||
})
|
||||
if len(rows) <= 0 {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neConfigBackup.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
item := rows[0]
|
||||
if _, err := os.Stat(item.Path); err != nil {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neConfigBackup.notFoundFile")))
|
||||
return
|
||||
@@ -74,9 +85,11 @@ func (s NeConfigBackupController) Download(c *gin.Context) {
|
||||
func (s NeConfigBackupController) Edit(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
ID int64 `json:"id" binding:"required"` // 记录ID
|
||||
Name string `json:"name" binding:"required"` // 名称
|
||||
Remark string `json:"remark" binding:"required"` // 备注
|
||||
CoreUID string `json:"coreUid" binding:"required"` // 核心网唯一标识
|
||||
NeUID string `json:"neUid" binding:"required"` // 网元唯一标识
|
||||
ID int64 `json:"id" binding:"required"` // 记录ID
|
||||
Name string `json:"name" binding:"required"` // 名称
|
||||
Remark string `json:"remark" binding:"required"` // 备注
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
@@ -85,18 +98,21 @@ func (s NeConfigBackupController) Edit(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
data := s.neConfigBackupService.FindById(body.ID)
|
||||
if data.ID != body.ID {
|
||||
// 没有可访问主机命令数据!
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neConfig.noData")))
|
||||
rows := s.neConfigBackupService.Find(model.NeConfigBackup{
|
||||
CoreUID: body.CoreUID,
|
||||
NeUID: body.NeUID,
|
||||
ID: body.ID,
|
||||
})
|
||||
if len(rows) <= 0 {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neConfigBackup.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
data := rows[0]
|
||||
data.Name = body.Name
|
||||
data.Remark = body.Remark
|
||||
data.UpdateBy = reqctx.LoginUserToUserName(c)
|
||||
rows := s.neConfigBackupService.Update(data)
|
||||
if rows > 0 {
|
||||
ups := s.neConfigBackupService.Update(data)
|
||||
if ups > 0 {
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
}
|
||||
@@ -108,21 +124,18 @@ func (s NeConfigBackupController) Edit(c *gin.Context) {
|
||||
// DELETE /?id=xx
|
||||
func (s NeConfigBackupController) Remove(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
id := c.Query("id")
|
||||
if id == "" {
|
||||
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: id is empty"))
|
||||
var query struct {
|
||||
CoreUID string `form:"coreUid" binding:"required"` // 核心网唯一标识
|
||||
NeUID string `form:"neUid" binding:"required"` // 网元唯一标识
|
||||
ID int64 `form:"id" binding:"required"` // 记录ID
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符转id数组后去重
|
||||
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
|
||||
// 转换成int64数组类型
|
||||
ids := make([]int64, 0)
|
||||
for _, v := range uniqueIDs {
|
||||
ids = append(ids, parse.Number(v))
|
||||
}
|
||||
|
||||
rows, err := s.neConfigBackupService.DeleteByIds(ids)
|
||||
rows, err := s.neConfigBackupService.DeleteByIds(query.ID, query.CoreUID, query.NeUID)
|
||||
if err != nil {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
@@ -137,10 +150,10 @@ func (s NeConfigBackupController) Remove(c *gin.Context) {
|
||||
func (s NeConfigBackupController) Import(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"`
|
||||
NeId string `json:"neId" binding:"required"`
|
||||
Type string `json:"type" binding:"required,oneof=backup upload"` // 导入类型
|
||||
Path string `json:"path" binding:"required"` // 文件路径
|
||||
CoreUID string `json:"coreUid" binding:"required"` // 核心网唯一标识
|
||||
NeUID string `json:"neUid" binding:"required"` // 网元唯一标识
|
||||
Type string `json:"type" binding:"required,oneof=backup upload"` // 导入类型 backup upload
|
||||
Path string `json:"path" binding:"required"` // 备份文件zip文件路径
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
@@ -153,8 +166,8 @@ func (s NeConfigBackupController) Import(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 查网元
|
||||
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
if neInfo.NeId != body.NeId || neInfo.IP == "" {
|
||||
neInfo := s.neInfoService.FindByCoreUidAndNeUid(body.CoreUID, body.NeUID)
|
||||
if neInfo.CoreUID != body.CoreUID || neInfo.NeUID != body.NeUID {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
@@ -176,8 +189,8 @@ func (s NeConfigBackupController) Import(c *gin.Context) {
|
||||
func (s NeConfigBackupController) Export(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"`
|
||||
NeId string `json:"neId" binding:"required"`
|
||||
CoreUID string `json:"coreUid" binding:"required"` // 核心网唯一标识
|
||||
NeUID string `json:"neUid" binding:"required"` // 网元唯一标识
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
@@ -185,8 +198,8 @@ func (s NeConfigBackupController) Export(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
// 查网元
|
||||
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
if neInfo.NeId != body.NeId || neInfo.IP == "" {
|
||||
neInfo := s.neInfoService.FindByCoreUidAndNeUid(body.CoreUID, body.NeUID)
|
||||
if neInfo.CoreUID != body.CoreUID || neInfo.NeUID != body.NeUID {
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
@@ -198,8 +211,9 @@ func (s NeConfigBackupController) Export(c *gin.Context) {
|
||||
}
|
||||
// 新增备份记录
|
||||
item := model.NeConfigBackup{
|
||||
CoreUID: neInfo.CoreUID,
|
||||
NeUID: neInfo.NeUID,
|
||||
NeType: neInfo.NeType,
|
||||
NeId: neInfo.NeId,
|
||||
Name: filepath.Base(zipFilePath),
|
||||
Path: zipFilePath,
|
||||
CreateBy: reqctx.LoginUserToUserName(c),
|
||||
|
||||
Reference in New Issue
Block a user