252 lines
7.2 KiB
Go
252 lines
7.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"be.ems/src/framework/i18n"
|
|
"be.ems/src/framework/reqctx"
|
|
"be.ems/src/framework/resp"
|
|
"be.ems/src/framework/utils/parse"
|
|
neService "be.ems/src/modules/ne/service"
|
|
neFetchlink "be.ems/src/modules/ne_data_nf/fetch_link"
|
|
"be.ems/src/modules/ne_data_nf/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// 实例化控制层 MMEController 结构体
|
|
var NewMME = &MMEController{
|
|
neInfoService: neService.NewNeInfo,
|
|
ueEventService: service.NewUEEvent,
|
|
}
|
|
|
|
// 网元MME
|
|
//
|
|
// PATH /mme
|
|
type MMEController struct {
|
|
neInfoService *neService.NeInfo // 网元信息服务
|
|
ueEventService *service.UEEvent // UE会话事件服务
|
|
}
|
|
|
|
// UE会话列表
|
|
//
|
|
// GET /ue/list
|
|
//
|
|
// @Tags ne_data/mme
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param neType query string true "NE Type only MME" Enums(MME)
|
|
// @Param neId query string true "NE ID" default(001)
|
|
// @Param imsi query string false "imsi"
|
|
// @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 UE Session List
|
|
// @Description UE Session List
|
|
// @Router /nf/mme/ue/list [get]
|
|
func (s *MMEController) UEList(c *gin.Context) {
|
|
language := reqctx.AcceptLanguage(c)
|
|
query := reqctx.QueryMap(c)
|
|
// 限制导出数据集
|
|
pageSize := parse.Number(query["pageSize"])
|
|
if pageSize > 10000 {
|
|
query["pageSize"] = "10000"
|
|
}
|
|
coreUid := c.DefaultQuery("coreUid", "")
|
|
neUid := c.DefaultQuery("neUid", "")
|
|
if coreUid == "" || neUid == "" {
|
|
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "coreUid or neUid is empty"))
|
|
return
|
|
}
|
|
|
|
// 查询网元获取IP
|
|
neInfo := s.neInfoService.FindByCoreUidAndNeUid(coreUid, neUid)
|
|
if neInfo.CoreUID != coreUid || neInfo.NeUID != neUid {
|
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
|
return
|
|
}
|
|
rows, total := s.ueEventService.FindByPage(neInfo.NeType, query)
|
|
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
|
|
}
|
|
|
|
// UE会话删除
|
|
//
|
|
// DELETE /ue/:id
|
|
//
|
|
// @Tags ne_data/mme
|
|
// @Accept json
|
|
// @Produce json
|
|
// @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 /nf/mme/ue/{id} [delete]
|
|
func (s *MMEController) UERemove(c *gin.Context) {
|
|
language := reqctx.AcceptLanguage(c)
|
|
id := c.Param("id")
|
|
if id == "" {
|
|
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: id is empty"))
|
|
return
|
|
}
|
|
|
|
// 处理字符转id数组后去重
|
|
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
|
|
// 转换成int64数组类型
|
|
ids := make([]int64, 0)
|
|
for _, v := range uniqueIDs {
|
|
ids = append(ids, parse.Number(v))
|
|
}
|
|
|
|
rows, err := s.ueEventService.DeleteByIds("MME", ids)
|
|
if err != nil {
|
|
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, resp.OkMsg(msg))
|
|
}
|
|
|
|
// UE会话列表导出
|
|
//
|
|
// GET /ue/export
|
|
//
|
|
// @Tags ne_data/mme
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param data body object true "Request Param"
|
|
// @Success 200 {object} object "Response Results"
|
|
// @Security TokenAuth
|
|
// @Summary UE Session List Export
|
|
// @Description UE Session List Export
|
|
// @Router /nf/mme/ue/export [get]
|
|
func (s *MMEController) UEExport(c *gin.Context) {
|
|
language := reqctx.AcceptLanguage(c)
|
|
query := reqctx.QueryMap(c)
|
|
// 限制导出数据集
|
|
pageSize := parse.Number(query["pageSize"])
|
|
if pageSize > 10000 {
|
|
query["pageSize"] = "10000"
|
|
}
|
|
coreUid := c.DefaultQuery("coreUid", "")
|
|
neUid := c.DefaultQuery("neUid", "")
|
|
if coreUid == "" || neUid == "" {
|
|
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "coreUid or neUid is empty"))
|
|
return
|
|
}
|
|
|
|
// 查询网元获取IP
|
|
neInfo := s.neInfoService.FindByCoreUidAndNeUid(coreUid, neUid)
|
|
if neInfo.CoreUID != coreUid || neInfo.NeUID != neUid {
|
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
|
return
|
|
}
|
|
rows, total := s.ueEventService.FindByPage(neInfo.NeType, query)
|
|
if total == 0 {
|
|
// 导出数据记录为空
|
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
|
return
|
|
}
|
|
|
|
// 导出文件名称
|
|
fileName := fmt.Sprintf("mme_ue_event_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
|
|
// 导出数据表格
|
|
saveFilePath, err := s.ueEventService.ExportMME(rows, fileName, language)
|
|
if err != nil {
|
|
c.JSON(200, resp.ErrMsg(err.Error()))
|
|
return
|
|
}
|
|
|
|
c.FileAttachment(saveFilePath, fileName)
|
|
}
|
|
|
|
// 接入基站信息列表
|
|
//
|
|
// GET /nb/list
|
|
//
|
|
// @Tags ne_data/mme
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param neId query string true "NE ID" default(001)
|
|
// @Param id query string false "Base Station ID"
|
|
// @Success 200 {object} object "Response Results"
|
|
// @Security TokenAuth
|
|
// @Summary Access Base Station Information List
|
|
// @Description Access Base Station Information List
|
|
// @Router /nf/mme/nb/list [get]
|
|
func (s *MMEController) NbInfoList(c *gin.Context) {
|
|
language := reqctx.AcceptLanguage(c)
|
|
var query struct {
|
|
CoreUID string `form:"coreUid" binding:"required"` // 核心网唯一标识
|
|
NeUID string `form:"neUid" binding:"required"` // 网元唯一标识
|
|
NbId string `form:"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
|
|
}
|
|
|
|
// 查询网元信息
|
|
neInfo := s.neInfoService.FindByCoreUidAndNeUid(query.CoreUID, query.NeUID)
|
|
if neInfo.CoreUID != query.CoreUID || neInfo.NeUID != query.NeUID {
|
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
|
return
|
|
}
|
|
|
|
// 网元直连
|
|
data, err := neFetchlink.MMENbInfoList(neInfo, map[string]string{
|
|
"id": query.NbId,
|
|
})
|
|
if err != nil {
|
|
c.JSON(200, resp.ErrMsg(err.Error()))
|
|
return
|
|
}
|
|
|
|
c.JSON(200, resp.OkData(data))
|
|
}
|
|
|
|
// 接入基站状态信息列表
|
|
//
|
|
// GET /nb/addrs
|
|
//
|
|
// @Tags ne_data/mme
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param neId query string true "NE ID" default(001)
|
|
// @Success 200 {object} object "Response Results"
|
|
// @Security TokenAuth
|
|
// @Summary Access to the base station status information list
|
|
// @Description Access to the base station status information list
|
|
// @Router /nf/mme/nb/addrs [get]
|
|
func (s *MMEController) NbStateList(c *gin.Context) {
|
|
language := reqctx.AcceptLanguage(c)
|
|
var query struct {
|
|
CoreUID string `form:"coreUid" binding:"required"` // 核心网唯一标识
|
|
NeUID string `form:"neUid" binding:"required"` // 网元唯一标识
|
|
}
|
|
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
|
|
}
|
|
|
|
// 查询网元信息
|
|
neInfo := s.neInfoService.FindByCoreUidAndNeUid(query.CoreUID, query.NeUID)
|
|
if neInfo.CoreUID != query.CoreUID || neInfo.NeUID != query.NeUID {
|
|
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
|
return
|
|
}
|
|
|
|
// 网元直连
|
|
data, err := neFetchlink.MMEEnbStateList(neInfo)
|
|
if err != nil {
|
|
c.JSON(200, resp.ErrMsg(err.Error()))
|
|
return
|
|
}
|
|
|
|
c.JSON(200, resp.OkData(data))
|
|
}
|