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

@@ -2,19 +2,18 @@ package controller
import (
"fmt"
"strings"
"time"
"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_data/model"
neDataService "be.ems/src/modules/network_data/service"
neFetchlink "be.ems/src/modules/network_element/fetch_link"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 MMEController 结构体
@@ -49,60 +48,63 @@ type MMEController struct {
// @Description UE Session List
// @Router /neData/mme/ue/list [get]
func (s *MMEController) UEList(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys model.UEEventMMEQuery
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
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("MME", querys.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID("MME", 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
}
querys.RmUID = neInfo.RmUID
// 查询数据
rows, total := s.ueEventService.SelectPage(querys)
c.JSON(200, result.Ok(map[string]any{"rows": rows, "total": total}))
rows, total := s.ueEventService.FindByPage(querys)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// UE会话删除
//
// DELETE /ue/:ueIds
// DELETE /ue/:id
//
// @Tags network_data/mme
// @Accept json
// @Produce json
// @Param ueIds path string true "list data id, multiple separated by a , sign"
// @Success 200 {object} object "Response Results"
// @Param id path string true "list data id, multiple separated by a , sign"
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary UE Session Deletion
// @Description UE Session Deletion
// @Router /neData/mme/ue/{ueIds} [delete]
// @Router /neData/mme/ue/{id} [delete]
func (s *MMEController) UERemove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
ueIds := c.Param("ueIds")
if ueIds == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
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(ueIds, ",")
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.ueEventService.DeleteByIds(uniqueIDs)
rows, err := s.ueEventService.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))
}
// UE会话列表导出
@@ -119,11 +121,12 @@ func (s *MMEController) UERemove(c *gin.Context) {
// @Description UE Session List Export
// @Router /neData/mme/ue/export [post]
func (s *MMEController) UEExport(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
var querys model.UEEventMMEQuery
if err := c.ShouldBindBodyWith(&querys, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindBodyWithJSON(&querys); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 限制导出数据集
@@ -131,16 +134,16 @@ func (s *MMEController) UEExport(c *gin.Context) {
querys.PageSize = 10000
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("MME", querys.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID("MME", 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
}
querys.RmUID = neInfo.RmUID
rows, total := s.ueEventService.SelectPage(querys)
rows, total := s.ueEventService.FindByPage(querys)
if total == 0 {
// 导出数据记录为空
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
@@ -149,7 +152,7 @@ func (s *MMEController) UEExport(c *gin.Context) {
// 导出数据表格
saveFilePath, err := s.ueEventService.ExportXlsx(rows, fileName, language)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -171,20 +174,21 @@ func (s *MMEController) UEExport(c *gin.Context) {
// @Description Access Base Station Information List
// @Router /neData/mme/nb/list [get]
func (s *MMEController) NbInfoList(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var query struct {
NeId string `form:"neId" binding:"required"`
NbId string `form:"id"`
}
if err := c.ShouldBindQuery(&query); 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("MME", query.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("MME", query.NeId)
if neInfo.NeId != query.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
}
@@ -193,11 +197,11 @@ func (s *MMEController) NbInfoList(c *gin.Context) {
"id": query.NbId,
})
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))
}
// 接入基站状态信息列表
@@ -214,28 +218,26 @@ func (s *MMEController) NbInfoList(c *gin.Context) {
// @Description Access to the base station status information list
// @Router /neData/mme/nb/list-cfg [get]
func (s *MMEController) NbStateList(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var query struct {
NeId string `form:"neId" binding:"required"`
}
if err := c.ShouldBindQuery(&query); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
language := reqctx.AcceptLanguage(c)
neId := c.Query("neId")
if neId == "" {
c.JSON(400, resp.CodeMsg(40010, "bind err: neId is empty"))
return
}
// 查询网元信息
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("MME", query.NeId)
if neInfo.NeId != query.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
neInfo := s.neInfoService.FindByNeTypeAndNeID("MME", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 网元直连
data, err := neFetchlink.MMEEnbStateList(neInfo)
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))
}