feat: 更新多个模块以支持新的数据结构和日志格式

This commit is contained in:
TsMask
2025-02-20 10:08:27 +08:00
parent 045a2b6b01
commit f3c33b31ac
272 changed files with 13246 additions and 15885 deletions

View File

@@ -1,16 +1,16 @@
package controller
import (
"strings"
"fmt"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/parse"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/network_element/model"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 NeSoftwareController 结构体
@@ -32,62 +32,76 @@ type NeSoftwareController struct {
// @Tags network_element/software
// @Accept json
// @Produce json
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
// @Param neId query string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Param neType query string false "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param name query string false "Name"
// @Param version query string false "Version"
// @Param pageNum query number true "pageNum" default(1)
// @Param pageSize query number true "pageSize" default(10)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary List of Network Element Software Packages
// @Description List of Network Element Software Packages
// @Router /ne/software/list [get]
func (s *NeSoftwareController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.neSoftwareService.SelectPage(querys)
c.JSON(200, result.Ok(data))
func (s NeSoftwareController) List(c *gin.Context) {
query := reqctx.QueryMap(c)
rows, total := s.neSoftwareService.FindByPage(query)
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
}
// 网元软件包信息
//
// GET /:softwareId
func (s *NeSoftwareController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
softwareId := c.Param("softwareId")
if softwareId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
// GET /:id
func (s NeSoftwareController) Info(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := parse.Number(c.Param("id"))
if id <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
neSoftware := s.neSoftwareService.SelectById(softwareId)
if neSoftware.ID != softwareId {
neSoftware := s.neSoftwareService.FindById(id)
if neSoftware.ID != id {
// 没有可访问网元包信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
return
}
c.JSON(200, result.OkData(neSoftware))
c.JSON(200, resp.OkData(neSoftware))
}
// 网元软件包新增
//
// POST /
func (s *NeSoftwareController) Add(c *gin.Context) {
language := ctx.AcceptLanguage(c)
//
// @Tags network_element/software
// @Accept json
// @Produce json
// @Param data body object true "Request Param"
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Additions to the Net Element package
// @Description Additions to the Net Element package
// @Router /ne/software [post]
func (s NeSoftwareController) Add(c *gin.Context) {
var body model.NeSoftware
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.Path == "" || body.ID != "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if body.Path == "" || body.ID > 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: path is empty or id is not empty"))
return
}
// 找到已存在的删除后重新添加
neSoftwares := s.neSoftwareService.SelectList(model.NeSoftware{
neSoftwares := s.neSoftwareService.Find(model.NeSoftware{
NeType: body.NeType,
Name: body.Name,
Version: body.Version,
})
if len(neSoftwares) > 0 {
neSoftware := neSoftwares[0]
s.neSoftwareService.DeleteByIds([]string{neSoftware.ID})
s.neSoftwareService.DeleteByIds([]int64{neSoftware.ID})
}
// 检查属性值唯一
@@ -95,28 +109,32 @@ func (s *NeSoftwareController) Add(c *gin.Context) {
// if !uniqueSoftware {
// // 网元软件包操作【%s】失败网元类型与文件名版本已存在
// msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.Name})
// c.JSON(200, result.ErrMsg(msg))
// c.JSON(200, resp.ErrMsg(msg))
// return
// }
body.CreateBy = ctx.LoginUserToUserName(c)
body.CreateBy = reqctx.LoginUserToUserName(c)
insertId := s.neSoftwareService.Insert(body)
if insertId != "" {
c.JSON(200, result.Ok(nil))
if insertId > 0 {
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元软件包修改
//
// PUT /
func (s *NeSoftwareController) Edit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeSoftwareController) Edit(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeSoftware
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.Path == "" || body.ID == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if body.Path == "" || body.ID == 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: path or id is empty"))
return
}
@@ -125,51 +143,53 @@ func (s *NeSoftwareController) Edit(c *gin.Context) {
if !uniqueSoftware {
// 网元软件包操作【%s】失败网元类型与文件名版本已存在
msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.Name})
c.JSON(200, result.ErrMsg(msg))
c.JSON(200, resp.ErrMsg(msg))
return
}
// 检查是否存在
neSoftware := s.neSoftwareService.SelectById(body.ID)
neSoftware := s.neSoftwareService.FindById(body.ID)
if neSoftware.ID != body.ID {
// 没有可访问网元包信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neSoftware.noData")))
return
}
body.UpdateBy = ctx.LoginUserToUserName(c)
body.UpdateBy = reqctx.LoginUserToUserName(c)
rows := s.neSoftwareService.Update(body)
if rows > 0 {
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元软件包删除
//
// DELETE /:softwareIds
func (s *NeSoftwareController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
softwareIds := c.Param("softwareIds")
if softwareIds == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
// DELETE /:id
func (s NeSoftwareController) Remove(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
id := c.Param("id")
if id == "" {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
// 处理字符转id数组后去重
ids := strings.Split(softwareIds, ",")
uniqueIDs := parse.RemoveDuplicates(ids)
if len(uniqueIDs) <= 0 {
c.JSON(200, result.Err(nil))
return
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
// 转换成int64数组类型
ids := make([]int64, 0)
for _, v := range uniqueIDs {
ids = append(ids, parse.Number(v))
}
rows, err := s.neSoftwareService.DeleteByIds(uniqueIDs)
rows, err := s.neSoftwareService.DeleteByIds(ids)
if err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
return
}
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
c.JSON(200, resp.OkMsg(msg))
}
// 网元软件包设为网元新版本
@@ -185,17 +205,16 @@ func (s *NeSoftwareController) Remove(c *gin.Context) {
// @Summary Net Element package set to Net Element new version
// @Description Net Element package set to Net Element new version
// @Router /ne/software/newNeVersion [post]
func (s *NeSoftwareController) NewNeVersion(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeSoftwareController) NewNeVersion(c *gin.Context) {
var body model.NeSoftware
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 找到已存在的软件包信息
neSoftwares := s.neSoftwareService.SelectList(model.NeSoftware{
neSoftwares := s.neSoftwareService.Find(model.NeSoftware{
NeType: body.NeType,
Name: body.Name,
Version: body.Version,
@@ -204,10 +223,10 @@ func (s *NeSoftwareController) NewNeVersion(c *gin.Context) {
neSoftware := neSoftwares[0]
s.neSoftwareService.UpdateVersions(neSoftware, model.NeVersion{
NeType: neSoftware.NeType,
UpdateBy: ctx.LoginUserToUserName(c),
UpdateBy: reqctx.LoginUserToUserName(c),
})
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}