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

@@ -6,9 +6,9 @@ import (
"sync"
"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"
neFetchlink "be.ems/src/modules/network_element/fetch_link"
"be.ems/src/modules/network_element/model"
neService "be.ems/src/modules/network_element/service"
@@ -43,27 +43,28 @@ var mutex sync.Mutex
// @Tags network_element/info
// @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 neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Network element information state
// @Description Network element information state
// @Router /ne/info/state [get]
func (s *NeInfoController) State(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) State(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeId string `form:"neId" binding:"required"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeId)
if neInfo.NeId != querys.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
neKey := fmt.Sprintf("%s_%s", neInfo.NeType, neInfo.NeId)
@@ -87,7 +88,7 @@ func (s *NeInfoController) State(c *gin.Context) {
}
neStateCacheMap.Store(neKey, resDataCache)
mutex.Unlock()
c.JSON(200, result.OkData(resDataCache))
c.JSON(200, resp.OkData(resDataCache))
return
}
@@ -96,7 +97,7 @@ func (s *NeInfoController) State(c *gin.Context) {
mutex.Lock()
neStateCacheMap.Store(neKey, resData)
mutex.Unlock()
c.JSON(200, result.OkData(resData))
c.JSON(200, resp.OkData(resData))
}
// 网元neType和neID查询
@@ -106,30 +107,31 @@ func (s *NeInfoController) State(c *gin.Context) {
// @Tags network_element/info
// @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 neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Network element neType and neID queries
// @Description Network element neType and neID queries
// @Router /ne/info/byTypeAndID [get]
func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) NeTypeAndID(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
c.JSON(200, result.OkData(neInfo))
c.JSON(200, resp.OkData(neInfo))
}
// 网元信息列表全部无分页
@@ -148,8 +150,8 @@ func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
// @Summary The list of network element information is all unpaginated
// @Description The list of network element information is all unpaginated
// @Router /ne/info/listAll [get]
func (s *NeInfoController) ListAll(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) ListAll(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType"`
NeId string `form:"neId"`
@@ -157,7 +159,8 @@ func (s *NeInfoController) ListAll(c *gin.Context) {
BandHost bool `form:"bandHost"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
@@ -169,75 +172,75 @@ func (s *NeInfoController) ListAll(c *gin.Context) {
if querys.NeId != "" {
ne.NeId = querys.NeId
}
neList := s.neInfoService.SelectList(ne, querys.BandStatus, querys.BandHost)
neList := s.neInfoService.Find(ne, querys.BandStatus, querys.BandHost)
if len(neList) == 0 {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
c.JSON(200, result.OkData(neList))
c.JSON(200, resp.OkData(neList))
}
// 网元端Para5G配置文件读取
//
// GET /para5GFile
func (s *NeInfoController) Para5GFileRead(c *gin.Context) {
func (s NeInfoController) Para5GFileRead(c *gin.Context) {
data, err := s.neInfoService.NeConfPara5GRead()
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// 网元端Para5G配置文件写入
//
// PUT /para5GFile
func (s *NeInfoController) Para5GFileWrite(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) Para5GFileWrite(c *gin.Context) {
var body struct {
Content map[string]any `json:"content" binding:"required"` // 内容
SyncNE []string `json:"syncNe"` // 同步到网元
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
err := s.neInfoService.NeConfPara5GWirte(body.Content, body.SyncNE)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
}
// 网元端OAM配置文件读取
//
// GET /oamFile
func (s *NeInfoController) OAMFileRead(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) OAMFileRead(c *gin.Context) {
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
data, err := s.neInfoService.NeConfOAMReadSync(querys.NeType, querys.NeID)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// 网元端OAM配置文件写入
//
// PUT /oamFile
func (s *NeInfoController) OAMFileWrite(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) OAMFileWrite(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct {
NeType string `json:"neType" binding:"required"`
NeID string `json:"neId" binding:"required"`
@@ -245,23 +248,24 @@ func (s *NeInfoController) OAMFileWrite(c *gin.Context) {
Sync bool `json:"sync"` // 同步到网元
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeID)
if neInfo.NeId != body.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
err := s.neInfoService.NeConfOAMWirteSync(neInfo, body.Content, body.Sync)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.Ok(nil))
c.JSON(200, resp.Ok(nil))
}
// 网元信息列表
@@ -281,19 +285,19 @@ func (s *NeInfoController) OAMFileWrite(c *gin.Context) {
// @Summary Network element information list
// @Description Network element information list
// @Router /ne/info/list [get]
func (s *NeInfoController) List(c *gin.Context) {
query := ctx.QueryMapString(c)
func (s NeInfoController) List(c *gin.Context) {
query := reqctx.QueryMap(c)
bandStatus := false
if v, ok := query["bandStatus"]; ok {
bandStatus = parse.Boolean(v)
}
rows, total := s.neInfoService.SelectPage(query, bandStatus)
c.JSON(200, result.Ok(map[string]any{"rows": rows, "total": total}))
rows, total := s.neInfoService.FindByPage(query, bandStatus)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// 网元信息
//
// GET /:infoId
// GET /:id
//
// @Tags network_element/info
// @Accept json
@@ -304,22 +308,22 @@ func (s *NeInfoController) List(c *gin.Context) {
// @Summary Network element information
// @Description Network element information
// @Router /ne/info/{value} [get]
func (s *NeInfoController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
infoId := c.Param("infoId")
if infoId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
func (s NeInfoController) 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
}
neHost := s.neInfoService.SelectById(infoId, true)
if neHost.ID != infoId {
neHost := s.neInfoService.FindById(id, true)
if neHost.ID != id {
// 没有可访问网元信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neInfo.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neInfo.noData")))
return
}
c.JSON(200, result.OkData(neHost))
c.JSON(200, resp.OkData(neHost))
}
// 网元信息新增
@@ -335,41 +339,46 @@ func (s *NeInfoController) Info(c *gin.Context) {
// @Summary Network element information addition
// @Description Network element information addition
// @Router /ne/info [post]
func (s *NeInfoController) Add(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) Add(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeInfo
err := c.ShouldBindBodyWithJSON(&body)
if err != nil || body.ID != "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if body.ID != 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id not is empty"))
return
}
// 检查属性值唯一
uniqueInfo := s.neInfoService.CheckUniqueNeTypeAndNeId(body.NeType, body.NeId, "")
uniqueInfo := s.neInfoService.CheckUniqueNeTypeAndNeId(body.NeType, body.NeId, 0)
if !uniqueInfo {
// 网元信息操作【%s】失败同类型下标识已存在
msg := i18n.TTemplate(language, "neInfo.errKeyExists", map[string]any{"key": body.NeId})
c.JSON(200, result.ErrMsg(msg))
c.JSON(200, resp.ErrMsg(msg))
return
}
// 获取网元状态是否正常
body.ServerState, err = neFetchlink.NeState(body)
if err != nil {
body.Status = "0"
body.Status = 0
} else {
// 网元状态设置为在线
body.Status = "1"
body.Status = 1
if parse.Boolean(body.ServerState["standby"]) {
body.Status = "3"
body.Status = 3
}
// 下发网管配置信息给网元
if _, err = neFetchlink.NeConfigOMC(body); err != nil {
body.Status = "2"
body.Status = 2
}
}
loginUserName := ctx.LoginUserToUserName(c)
loginUserName := reqctx.LoginUserToUserName(c)
// 新增Version信息
neVersion := model.NeVersion{
NeType: body.NeType,
@@ -403,11 +412,11 @@ func (s *NeInfoController) Add(c *gin.Context) {
s.neLicenseService.Insert(neLicense)
body.CreateBy = loginUserName
insertId := s.neInfoService.Insert(body)
if insertId != "" {
c.JSON(200, result.OkData(insertId))
if insertId > 0 {
c.JSON(200, resp.OkData(insertId))
return
}
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
}
// 网元信息修改
@@ -423,12 +432,17 @@ func (s *NeInfoController) Add(c *gin.Context) {
// @Summary Network element information modification
// @Description Network element information modification
// @Router /ne/info [put]
func (s *NeInfoController) Edit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s NeInfoController) Edit(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body model.NeInfo
err := c.ShouldBindBodyWithJSON(&body)
if err != nil || body.ID == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
if body.ID <= 0 {
c.JSON(400, resp.CodeMsg(40010, "bind err: id is empty"))
return
}
@@ -437,44 +451,44 @@ func (s *NeInfoController) Edit(c *gin.Context) {
if !uniqueInfo {
// 网元信息操作【%s】失败同类型下标识已存在
msg := i18n.TTemplate(language, "neInfo.errKeyExists", map[string]any{"key": body.NeId})
c.JSON(200, result.ErrMsg(msg))
c.JSON(200, resp.ErrMsg(msg))
return
}
// 检查是否存在
neInfo := s.neInfoService.SelectById(body.ID, false)
neInfo := s.neInfoService.FindById(body.ID, false)
if neInfo.ID != body.ID {
// 没有可访问网元信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neInfo.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neInfo.noData")))
return
}
// 赋予主机ID
if neInfo.HostIDs != "" && len(body.Hosts) > 0 {
hostIDs := strings.Split(neInfo.HostIDs, ",")
for index, id := range hostIDs {
body.Hosts[index].HostID = id
body.Hosts[index].ID = parse.Number(id)
}
}
// 获取网元状态是否正常
body.ServerState, err = neFetchlink.NeState(body)
body.ServerState, err = neFetchlink.NeState(neInfo)
if err != nil {
body.Status = "0"
body.Status = 0
} else {
// 网元状态设置为在线
body.Status = "1"
body.Status = 1
if parse.Boolean(body.ServerState["standby"]) {
body.Status = "3"
body.Status = 3
}
// 下发网管配置信息给网元
if _, err = neFetchlink.NeConfigOMC(body); err != nil {
body.Status = "2"
body.Status = 2
}
}
loginUserName := ctx.LoginUserToUserName(c)
neLicense := s.neLicenseService.SelectByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
neVersion := s.neVersionService.SelectByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
loginUserName := reqctx.LoginUserToUserName(c)
neLicense := s.neLicenseService.FindByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
neVersion := s.neVersionService.FindByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
// 已有网元可获取的信息
if body.ServerState != nil {
@@ -494,14 +508,14 @@ func (s *NeInfoController) Edit(c *gin.Context) {
}
}
if neVersion.ID != "" {
if neVersion.ID <= 0 {
if neVersion.NeType != body.NeType || neVersion.NeId != body.NeId {
neVersion.NeType = body.NeType
neVersion.NeId = body.NeId
}
s.neVersionService.Update(neVersion)
}
if neLicense.ID != "" {
if neLicense.ID <= 0 {
if neLicense.NeType != body.NeType || neLicense.NeId != body.NeId {
neLicense.NeType = body.NeType
neLicense.NeId = body.NeId
@@ -512,44 +526,46 @@ func (s *NeInfoController) Edit(c *gin.Context) {
body.UpdateBy = loginUserName
rows := s.neInfoService.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 /:infoIds
// DELETE /:id
//
// @Tags network_element/info
// @Accept json
// @Produce json
// @Param value path string true "Row ID, multiple separated by a , sign"
// @Param value path string true "Row ID"
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Network element information deletion
// @Description Network element information deletion
// @Router /ne/info/{value} [delete]
func (s *NeInfoController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
infoIds := c.Param("infoIds")
if infoIds == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
// @Router /ne/info [delete]
func (s NeInfoController) 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(infoIds, ",")
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.neInfoService.DeleteByIds(uniqueIDs)
rows, err := s.neInfoService.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))
}