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,12 +1,12 @@
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_data/model"
neDataService "be.ems/src/modules/network_data/service"
neService "be.ems/src/modules/network_element/service"
@@ -31,49 +31,63 @@ type AlarmController struct {
// 告警列表
//
// GET /list
//
// @Tags network_data/alarm
// @Accept json
// @Produce json
// @Param neType query string false "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string false "NE ID The actual record is the network element RmUid"
// @Param neName query string false "NE Name"
// @Param pvFlag query string false "PV Flag" Enums(PNF,VNF)
// @Param alarmCode query string false "alarm status code"
// @Param alarmType query string false "Alarm type Communication alarms=1, Equipment alarms=2, Processing faults=3, Environmental alarms=4, Quality of service alarms=5" Enums(1,2,3,4,5)
// @Param alarmStatus query string false "Alarm status 0:clear, 1:active" Enums(0,1)
// @Param origSeverity query string false "Alarm Type 1: Critical, 2: Major, 3: Minor, 4: Warning" Enums(1,2,3,4)
// @Param sortField query string false "Sort fields, fill in result fields" default(event_time)
// @Param sortOrder query string false "Sort by ascending or descending order, asc desc" default(asc)
// @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 Alarm List
// @Description Alarm List
// @Router /neData/alarm/list [get]
func (s *AlarmController) List(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var querys model.AlarmQuery
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
var query model.AlarmQuery
if err := c.ShouldBindQuery(&query); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
querys.RmUID = neInfo.RmUID
// 查询数据
rows, total := s.alarmService.SelectPage(querys)
c.JSON(200, result.Ok(map[string]any{"rows": rows, "total": total}))
rows, total := s.alarmService.FindByPage(query)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// 告警删除
//
// DELETE /:alarmIds
// DELETE /:id
func (s *AlarmController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
alarmIds := c.Param("alarmIds")
if alarmIds == "" {
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(alarmIds, ",")
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.alarmService.DeleteByIds(uniqueIDs)
rows, err := s.alarmService.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))
}

View File

@@ -0,0 +1,93 @@
package controller
import (
"fmt"
"be.ems/src/framework/i18n"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/parse"
"be.ems/src/modules/network_data/model"
neDataService "be.ems/src/modules/network_data/service"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
)
// 实例化控制层 AlarmLogController 结构体
var NewAlarmLog = &AlarmLogController{
neInfoService: neService.NewNeInfo,
alarmLogService: neDataService.NewAlarmLog,
}
// 告警数据
//
// PATH /alarm/log
type AlarmLogController struct {
neInfoService *neService.NeInfo // 网元信息服务
alarmLogService *neDataService.AlarmLog // 告警信息服务
}
// 告警日志列表
//
// GET /list
//
// @Tags network_data/alarm_log
// @Accept json
// @Produce json
// @Param neType query string false "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
// @Param neId query string false "NE ID The actual record is the network element RmUid"
// @Param neName query string false "NE Name"
// @Param pvFlag query string false "PV Flag" Enums(PNF,VNF)
// @Param alarmLogCode query string false "AlarmLog status code"
// @Param alarmLogType query string false "AlarmLog type Communication AlarmLogs=1, Equipment AlarmLogs=2, Processing faults=3, Environmental AlarmLogs=4, Quality of service AlarmLogs=5" Enums(1,2,3,4,5)
// @Param alarmLogStatus query string false "AlarmLog status 0:clear, 1:active" Enums(0,1)
// @Param origSeverity query string false "AlarmLog Type 1: Critical, 2: Major, 3: Minor, 4: Warning" Enums(1,2,3,4)
// @Param sortField query string false "Sort fields, fill in result fields" default(event_time)
// @Param sortOrder query string false "Sort by ascending or descending order, asc desc" default(asc)
// @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 AlarmLog List
// @Description AlarmLog List
// @Router /neData/alarm/log/list [get]
func (s *AlarmLogController) List(c *gin.Context) {
var query model.AlarmLogQuery
if err := c.ShouldBindQuery(&query); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
// 查询数据
rows, total := s.alarmLogService.FindByPage(query)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// 告警删除
//
// DELETE /:id
func (s AlarmLogController) 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数组后去重
uniqueIDs := parse.RemoveDuplicatesToArray(id, ",")
// 转换成int64数组类型
ids := make([]int64, 0)
for _, v := range uniqueIDs {
ids = append(ids, parse.Number(v))
}
rows, err := s.alarmLogService.DeleteByIds(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))
}

View File

@@ -1,27 +1,30 @@
package controller
import (
"fmt"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo/result"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/modules/network_data/model"
neDataService "be.ems/src/modules/network_data/service"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
)
// 实例化控制层 PerfKPIController 结构体
var NewPerfKPI = &PerfKPIController{
neInfoService: neService.NewNeInfo,
perfKPIService: neDataService.NewPerfKPI,
// 实例化控制层 KPIController 结构体
var NewKPI = &KPIController{
neInfoService: neService.NewNeInfo,
kpiReportService: neDataService.NewKpiReport,
}
// 性能统计
//
// PATH /kpi
type PerfKPIController struct {
neInfoService *neService.NeInfo // 网元信息服务
perfKPIService *neDataService.PerfKPI // 统计信息服务
type KPIController struct {
neInfoService *neService.NeInfo // 网元信息服务
kpiReportService *neDataService.KpiReport // 指标统计服务
}
// 获取统计数据
@@ -31,39 +34,36 @@ type PerfKPIController struct {
// @Tags network_data/kpi
// @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) default(AMF)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(AMF)
// @Param neId query string true "NE ID" default(001)
// @Param startTime query number true "Start time (timestamped milliseconds)" default(1729162507596)
// @Param endTime query number true "End time (timestamped milliseconds)" default(1729164187611)
// @Param beginTime query number true "begin time (timestamped milliseconds)" default(1729162507596)
// @Param endTime query number true "end time (timestamped milliseconds)" default(1729164187611)
// @Param interval query number true "interval" Enums(5,10,15,30,60,300,600,900,1800,3600) default(60)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Access to statistical data
// @Description Access to statistical data
// @Router /neData/kpi/data [get]
func (s *PerfKPIController) GoldKPI(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var querys model.GoldKPIQuery
func (s KPIController) KPIData(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var querys model.KPIQuery
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
if querys.Interval < 5 || querys.Interval > 3600 {
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(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
}
querys.RmUID = neInfo.RmUID
// 查询数据
kpiData := s.perfKPIService.SelectGoldKPI(querys)
c.JSON(200, result.OkData(kpiData))
kpiData := s.kpiReportService.FindData(querys)
c.JSON(200, resp.OkData(kpiData))
}
// 获取统计标题
@@ -73,21 +73,18 @@ func (s *PerfKPIController) GoldKPI(c *gin.Context) {
// @Tags network_data/kpi
// @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) default(AMF)
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC) default(AMF)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Get Statistical Headings
// @Description Get Statistical Headings
// @Router /neData/kpi/title [get]
func (s *PerfKPIController) Title(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s KPIController) KPITitle(c *gin.Context) {
neType := c.Query("neType")
if neType == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(40010, "bind err: neType is empty"))
return
}
kpiTitles := s.perfKPIService.SelectGoldKPITitle(neType)
c.JSON(200, result.OkData(kpiTitles))
kpiTitles := s.kpiReportService.FindTitle(neType)
c.JSON(200, resp.OkData(kpiTitles))
}

View File

@@ -7,8 +7,8 @@ import (
"github.com/gin-gonic/gin"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo/result"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/modules/network_data/model"
neDataService "be.ems/src/modules/network_data/service"
neService "be.ems/src/modules/network_element/service"
@@ -35,38 +35,39 @@ type NBStateController struct {
// @Tags network_data/amf,network_data/mme
// @Accept json
// @Produce json
// @Param neType query string true "NE Type only AMF/MME" Enums(AMF,MME) default(AMF)
// @Param neId query string true "NE ID" default(001)
// @Param pageNum query number true "pageNum" default(1)
// @Param pageSize query number true "pageSize" default(10)
// @Param neType query string true "NE Type only AMF/MME" Enums(AMF,MME) default(AMF)
// @Param neId query string true "NE ID" default(001)
// @Param pageNum query number true "pageNum" default(1)
// @Param pageSize query number true "pageSize" default(10)
// @Param startTime query number false "Start time (timestamped milliseconds)" default(1729162507596)
// @Param endTime query number false "End time (timestamped milliseconds)" default(1729164187611)
// @Param sortField query string false "Sort fields, fill in result fields" Enums(id,create_time) default(id)
// @Param sortOrder query string false "Sort by ascending or descending order" Enums(asc,desc) default(asc)
// @Param sortField query string false "Sort fields, fill in result fields" Enums(id,create_time) default(id)
// @Param sortOrder query string false "Sort by ascending or descending order" Enums(asc,desc) default(asc)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary Base Station Status List
// @Description Base Station Status List
// @Router /nb-state/list [get]
func (s NBStateController) List(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var query model.NBStateQuery
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
}
// 查询网元信息 rmUID
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(query.NeType, query.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID(query.NeType, 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
}
query.RmUID = neInfo.RmUID
// 查询数据
rows, total := s.nbStateService.SelectPage(query)
c.JSON(200, result.Ok(map[string]any{"rows": rows, "total": total}))
rows, total := s.nbStateService.FindByPage(query)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// 历史记录列表导出
@@ -83,11 +84,12 @@ func (s NBStateController) List(c *gin.Context) {
// @Description Base Station Status List Export
// @Router /nb-state/export [post]
func (s NBStateController) Export(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
var querys model.NBStateQuery
if err := c.ShouldBindBodyWithJSON(&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
}
// 限制导出数据集
@@ -95,16 +97,16 @@ func (s NBStateController) Export(c *gin.Context) {
querys.PageSize = 10000
}
// 查询网元信息 rmUID
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
}
querys.RmUID = neInfo.RmUID
rows, total := s.nbStateService.SelectPage(querys)
rows, total := s.nbStateService.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
}
@@ -113,7 +115,7 @@ func (s NBStateController) Export(c *gin.Context) {
// 导出数据表格
saveFilePath, err := s.nbStateService.ExportXlsx(rows, fileName, language)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}

View File

@@ -2,13 +2,12 @@ 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"
@@ -49,60 +48,63 @@ type AMFController struct {
// @Description UE Session List
// @Router /neData/amf/ue/list [get]
func (s *AMFController) UEList(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys model.UEEventAMFQuery
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("AMF", querys.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID("AMF", 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/amf
// @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/amf/ue/{ueIds} [delete]
// @Router /neData/amf/ue/{id} [delete]
func (s *AMFController) 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 *AMFController) UERemove(c *gin.Context) {
// @Description UE Session List Export
// @Router /neData/amf/ue/export [post]
func (s *AMFController) UEExport(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
var querys model.UEEventAMFQuery
if err := c.ShouldBindBodyWithJSON(&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
}
// 限制导出数据集
@@ -131,16 +134,16 @@ func (s *AMFController) UEExport(c *gin.Context) {
querys.PageSize = 10000
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("AMF", querys.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID("AMF", 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 *AMFController) 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 *AMFController) UEExport(c *gin.Context) {
// @Description Access Base Station Information List
// @Router /neData/amf/nb/list [get]
func (s *AMFController) 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("AMF", query.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("AMF", 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 *AMFController) 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 *AMFController) NbInfoList(c *gin.Context) {
// @Description Access to the base station status information list
// @Router /neData/amf/nb/list-cfg [get]
func (s *AMFController) 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("AMF", query.NeId)
if neInfo.NeId != query.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
neInfo := s.neInfoService.FindByNeTypeAndNeID("AMF", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 网元直连
data, err := neFetchlink.AMFGnbStateList(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))
}

View File

@@ -2,13 +2,12 @@ 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"
@@ -50,60 +49,63 @@ type IMSController struct {
// @Description CDR Session List
// @Router /neData/ims/cdr/list [get]
func (s *IMSController) CDRList(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys model.CDREventIMSQuery
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
}
// 查询网元信息 rmUID
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
}
querys.RmUID = neInfo.RmUID
// 查询数据
rows, total := s.cdrEventService.SelectPage(querys)
c.JSON(200, result.Ok(map[string]any{"rows": rows, "total": total}))
rows, total := s.cdrEventService.FindByPage(querys)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// CDR会话删除
//
// DELETE /cdr/:cdrIds
// DELETE /cdr/:id
//
// @Tags network_data/ims
// @Accept json
// @Produce json
// @Param cdrIds 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 CDR Session Delete
// @Description CDR Session Delete
// @Router /neData/ims/cdr/{cdrIds} [delete]
// @Router /neData/ims/cdr/{id} [delete]
func (s *IMSController) CDRRemove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
cdrIds := c.Param("cdrIds")
if cdrIds == "" {
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(cdrIds, ",")
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.cdrEventService.DeleteByIds(uniqueIDs)
rows, err := s.cdrEventService.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))
}
// CDR会话列表导出
@@ -120,11 +122,12 @@ func (s *IMSController) CDRRemove(c *gin.Context) {
// @Description CDR Session List Export
// @Router /neData/ims/cdr/export [post]
func (s *IMSController) CDRExport(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
var querys model.CDREventIMSQuery
if err := c.ShouldBindBodyWithJSON(&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
}
// 限制导出数据集
@@ -132,16 +135,16 @@ func (s *IMSController) CDRExport(c *gin.Context) {
querys.PageSize = 10000
}
// 查询网元信息 rmUID
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
}
querys.RmUID = neInfo.RmUID
rows, total := s.cdrEventService.SelectPage(querys)
rows, total := s.cdrEventService.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
}
@@ -150,7 +153,7 @@ func (s *IMSController) CDRExport(c *gin.Context) {
// 导出数据表格
saveFilePath, err := s.cdrEventService.ExportXlsx(rows, fileName, language)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -171,30 +174,28 @@ func (s *IMSController) CDRExport(c *gin.Context) {
// @Description Number of online session users
// @Router /neData/ims/session/num [get]
func (s *IMSController) UeSessionNum(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("IMS", query.NeId)
if neInfo.NeId != query.NeId || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
neInfo := s.neInfoService.FindByNeTypeAndNeID("IMS", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 网元直连
num, err := neFetchlink.IMSUeSessionNum(neInfo)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(num))
c.JSON(200, resp.OkData(num))
}
// 在线会话用户列表信息
@@ -213,21 +214,22 @@ func (s *IMSController) UeSessionNum(c *gin.Context) {
// @Description Online session user list information
// @Router /neData/ims/session/list [get]
func (s *IMSController) UeSessionList(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var query struct {
NeId string `form:"neId" binding:"required"`
IMSI string `form:"imsi"`
MSISDN string `form:"msisdn"`
}
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("IMS", query.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("IMS", 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
}
@@ -237,9 +239,9 @@ func (s *IMSController) UeSessionList(c *gin.Context) {
"msisdn": query.MSISDN,
})
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))
}

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))
}

View File

@@ -2,13 +2,12 @@ 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"
neService "be.ems/src/modules/network_element/service"
@@ -17,18 +16,18 @@ import (
// 实例化控制层 SGWCController 结构体
var NewSGWC = &SGWCController{
neInfoService: neService.NewNeInfo,
cdrEventService: neDataService.NewCDREventSGWC,
udmUserInfoService: neDataService.NewUDMUserInfo,
neInfoService: neService.NewNeInfo,
cdrEventService: neDataService.NewCDREventSGWC,
UDMExtendService: neDataService.NewUDMExtend,
}
// 网元SGWC
//
// PATH /sgwc
type SGWCController struct {
neInfoService *neService.NeInfo // 网元信息服务
cdrEventService *neDataService.CDREventSGWC // CDR会话事件服务
udmUserInfoService *neDataService.UDMUserInfo // UDM用户信息服务
neInfoService *neService.NeInfo // 网元信息服务
cdrEventService *neDataService.CDREventSGWC // CDR会话事件服务
UDMExtendService *neDataService.UDMExtend // UDM用户信息服务
}
// CDR会话列表
@@ -50,60 +49,63 @@ type SGWCController struct {
// @Description CDR Session List
// @Router /neData/sgwc/cdr/list [get]
func (s *SGWCController) CDRList(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys model.CDREventSGWCQuery
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
}
// 查询网元信息 rmUID
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
}
querys.RmUID = neInfo.RmUID
// 查询数据
rows, total := s.cdrEventService.SelectPage(querys)
c.JSON(200, result.Ok(map[string]any{"rows": rows, "total": total}))
rows, total := s.cdrEventService.FindByPage(querys)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// CDR会话删除
//
// DELETE /cdr/:cdrIds
// DELETE /cdr/:id
//
// @Tags network_data/sgwc
// @Accept json
// @Produce json
// @Param cdrIds 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 CDR Session Delete
// @Description CDR Session Delete
// @Router /neData/sgwc/cdr/{cdrIds} [delete]
// @Router /neData/sgwc/cdr/{id} [delete]
func (s *SGWCController) CDRRemove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
cdrIds := c.Param("cdrIds")
if cdrIds == "" {
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(cdrIds, ",")
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.cdrEventService.DeleteByIds(uniqueIDs)
rows, err := s.cdrEventService.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))
}
// CDR会话列表导出
@@ -120,11 +122,12 @@ func (s *SGWCController) CDRRemove(c *gin.Context) {
// @Description CDR Session List Export
// @Router /neData/sgwc/cdr/export [post]
func (s *SGWCController) CDRExport(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
var querys model.CDREventSGWCQuery
if err := c.ShouldBindBodyWithJSON(&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
}
// 限制导出数据集
@@ -132,16 +135,16 @@ func (s *SGWCController) CDRExport(c *gin.Context) {
querys.PageSize = 10000
}
// 查询网元信息 rmUID
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
}
querys.RmUID = neInfo.RmUID
rows, total := s.cdrEventService.SelectPage(querys)
rows, total := s.cdrEventService.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
}
@@ -150,7 +153,7 @@ func (s *SGWCController) CDRExport(c *gin.Context) {
// 导出数据表格
saveFilePath, err := s.cdrEventService.ExportXlsx(rows, fileName)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}

View File

@@ -6,31 +6,31 @@ import (
"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"
)
// 实例化控制层 SMFController 结构体
var NewSMF = &SMFController{
neInfoService: neService.NewNeInfo,
cdrEventService: neDataService.NewCDREventSMF,
udmUserInfoService: neDataService.NewUDMUserInfo,
neInfoService: neService.NewNeInfo,
cdrEventService: neDataService.NewCDREventSMF,
UDMExtendService: neDataService.NewUDMExtend,
}
// 网元SMF
//
// PATH /smf
type SMFController struct {
neInfoService *neService.NeInfo // 网元信息服务
cdrEventService *neDataService.CDREventSMF // CDR会话事件服务
udmUserInfoService *neDataService.UDMUserInfo // UDM用户信息服务
neInfoService *neService.NeInfo // 网元信息服务
cdrEventService *neDataService.CDREventSMF // CDR会话事件服务
UDMExtendService *neDataService.UDMExtend // UDM用户信息服务
}
// CDR会话列表
@@ -51,60 +51,63 @@ type SMFController struct {
// @Description CDR Session List
// @Router /neData/smf/cdr/list [get]
func (s *SMFController) CDRList(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys model.CDREventSMFQuery
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
}
// 查询网元信息 rmUID
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
}
querys.RmUID = neInfo.RmUID
// 查询数据
rows, total := s.cdrEventService.SelectPage(querys)
c.JSON(200, result.Ok(map[string]any{"rows": rows, "total": total}))
rows, total := s.cdrEventService.FindByPage(querys)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// CDR会话删除
//
// DELETE /cdr/:cdrIds
// DELETE /cdr/:id
//
// @Tags network_data/smf
// @Accept json
// @Produce json
// @Param cdrIds 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 CDR Session Delete
// @Description CDR Session Delete
// @Router /neData/smf/cdr/{cdrIds} [delete]
// @Router /neData/smf/cdr/{id} [delete]
func (s *SMFController) CDRRemove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
cdrIds := c.Param("cdrIds")
if cdrIds == "" {
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(cdrIds, ",")
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.cdrEventService.DeleteByIds(uniqueIDs)
rows, err := s.cdrEventService.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))
}
// CDR会话列表导出
@@ -121,11 +124,12 @@ func (s *SMFController) CDRRemove(c *gin.Context) {
// @Description CDR Session List Export
// @Router /neData/smf/cdr/export [post]
func (s *SMFController) CDRExport(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
var querys model.CDREventSMFQuery
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
}
// 限制导出数据集
@@ -133,16 +137,16 @@ func (s *SMFController) CDRExport(c *gin.Context) {
querys.PageSize = 10000
}
// 查询网元信息 rmUID
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
}
querys.RmUID = neInfo.RmUID
rows, total := s.cdrEventService.SelectPage(querys)
rows, total := s.cdrEventService.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
}
@@ -151,7 +155,7 @@ func (s *SMFController) CDRExport(c *gin.Context) {
// 导出数据表格
saveFilePath, err := s.cdrEventService.ExportXlsx(rows, fileName)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -172,30 +176,30 @@ func (s *SMFController) CDRExport(c *gin.Context) {
// @Description Number of online session users
// @Router /neData/smf/sub/num [get]
func (s *SMFController) SubUserNum(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.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")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元信息
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("SMF", query.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("SMF", 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
}
// 网元直连
num, err := neFetchlink.SMFSubNum(neInfo)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(num))
c.JSON(200, resp.OkData(num))
}
// 在线订阅用户列表信息
@@ -216,7 +220,7 @@ func (s *SMFController) SubUserNum(c *gin.Context) {
// @Description Online session user list information
// @Router /neData/smf/session/list [get]
func (s *SMFController) SubUserList(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var query struct {
NeId string `form:"neId" binding:"required"`
IMSI string `form:"imsi"`
@@ -225,14 +229,14 @@ func (s *SMFController) SubUserList(c *gin.Context) {
PageNum string `form:"pageNum"`
}
if err := c.ShouldBindQuery(&query); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元信息
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("SMF", query.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("SMF", 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
}
@@ -244,7 +248,7 @@ func (s *SMFController) SubUserList(c *gin.Context) {
"pageNum": query.PageNum,
})
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -259,7 +263,7 @@ func (s *SMFController) SubUserList(c *gin.Context) {
imsiStr = strings.TrimPrefix(imsiStr, "imsi-")
item["imsi"] = imsiStr
// 查UDM拓展信息
info := s.udmUserInfoService.SelectByIMSIAndNeID(imsiStr, "%")
info := s.UDMExtendService.FindByIMSIAndNeID(imsiStr, "%")
item["remark"] = info.Remark
}
if v, ok := item["msisdn"]; ok && v != nil {
@@ -268,5 +272,5 @@ func (s *SMFController) SubUserList(c *gin.Context) {
}
}
c.JSON(200, result.Ok(data))
c.JSON(200, resp.OkData(data))
}

View File

@@ -2,13 +2,12 @@ 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"
neService "be.ems/src/modules/network_element/service"
@@ -49,60 +48,63 @@ type SMSCController struct {
// @Description CDR Session List
// @Router /neData/smsc/cdr/list [get]
func (s *SMSCController) CDRList(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var querys model.CDREventSMSCQuery
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
}
// 查询网元信息 rmUID
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
}
querys.RmUID = neInfo.RmUID
// 查询数据
rows, total := s.cdrEventService.SelectPage(querys)
c.JSON(200, result.Ok(map[string]any{"rows": rows, "total": total}))
rows, total := s.cdrEventService.FindByPage(querys)
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
}
// CDR会话删除
//
// DELETE /cdr/:cdrIds
// DELETE /cdr/:id
//
// @Tags network_data/smsc
// @Accept json
// @Produce json
// @Param cdrIds 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 CDR Session Delete
// @Description CDR Session Delete
// @Router /neData/smsc/cdr/{cdrIds} [delete]
// @Router /neData/smsc/cdr/{id} [delete]
func (s *SMSCController) CDRRemove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
cdrIds := c.Param("cdrIds")
if cdrIds == "" {
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(cdrIds, ",")
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.cdrEventService.DeleteByIds(uniqueIDs)
rows, err := s.cdrEventService.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))
}
// CDR会话列表导出
@@ -119,11 +121,12 @@ func (s *SMSCController) CDRRemove(c *gin.Context) {
// @Description CDR Session List Export
// @Router /neData/smsc/cdr/export [post]
func (s *SMSCController) CDRExport(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
var querys model.CDREventSMSCQuery
if err := c.ShouldBindBodyWithJSON(&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
}
// 限制导出数据集
@@ -131,16 +134,16 @@ func (s *SMSCController) CDRExport(c *gin.Context) {
querys.PageSize = 10000
}
// 查询网元信息 rmUID
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
}
querys.RmUID = neInfo.RmUID
rows, total := s.cdrEventService.SelectPage(querys)
rows, total := s.cdrEventService.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 *SMSCController) CDRExport(c *gin.Context) {
// 导出数据表格
saveFilePath, err := s.cdrEventService.ExportXlsx(rows, fileName, language)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}

View File

@@ -6,19 +6,19 @@ import (
"strings"
"time"
"be.ems/src/framework/constants/uploadsubpath"
"be.ems/src/framework/constants"
"be.ems/src/framework/i18n"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/telnet"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/file"
"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"
)
// 实例化控制层 UDMAuthController 结构体
@@ -45,19 +45,19 @@ type UDMAuthController struct {
// @Param neId path string true "NE ID" default(001)
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary UDM Authentication User Reload Data
// @Description UDM Authentication User Reload Data
// @Summary UDM Authentication User Data Refresh
// @Description UDM Authenticated User Data List Refresh Synchronization Latest
// @Router /neData/udm/auth/resetData/{neId} [put]
func (s *UDMAuthController) ResetData(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
if neId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
data := s.udmAuthService.ResetData(neId)
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// UDM鉴权用户列表
@@ -77,9 +77,9 @@ func (s *UDMAuthController) ResetData(c *gin.Context) {
// @Description UDM Authentication User List
// @Router /neData/udm/auth/list [get]
func (s *UDMAuthController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
total, rows := s.udmAuthService.SelectPage(querys)
c.JSON(200, result.Ok(map[string]any{"total": total, "rows": rows}))
query := reqctx.QueryMap(c)
total, rows := s.udmAuthService.FindByPage(query)
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
}
// UDM鉴权用户信息
@@ -97,24 +97,24 @@ func (s *UDMAuthController) List(c *gin.Context) {
// @Description UDM Authentication User Information
// @Router /neData/udm/auth/{neId}/{value} [get]
func (s *UDMAuthController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
imsi := c.Param("imsi")
if neId == "" || imsi == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -123,19 +123,19 @@ func (s *UDMAuthController) Info(c *gin.Context) {
cmd := fmt.Sprintf("dsp authdat:imsi=%s", imsi)
data, err := telnet.ConvertToMap(telnetClient, cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
if len(data) == 0 {
c.JSON(200, result.ErrMsg("No Auth Data"))
c.JSON(200, resp.ErrMsg("No Auth Data"))
return
}
// 解析返回的数据
u := s.udmAuthService.ParseInfo(imsi, neId, data)
s.udmAuthService.Insert(neId, u)
c.JSON(200, result.OkData(u))
c.JSON(200, resp.OkData(u))
}
// UDM鉴权用户新增
@@ -153,30 +153,30 @@ func (s *UDMAuthController) Info(c *gin.Context) {
// @Description UDM Authentication User Added
// @Router /neData/udm/auth/{neId} [post]
func (s *UDMAuthController) Add(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
if neId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
var body model.UDMAuthUser
err := c.ShouldBindBodyWith(&body, binding.JSON)
err := c.ShouldBindBodyWithJSON(&body)
if err != nil || body.IMSI == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -186,7 +186,7 @@ func (s *UDMAuthController) Add(c *gin.Context) {
cmd += s.udmAuthService.ParseCommandParams(body)
data, err := telnet.ConvertToStr(telnetClient, cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -194,7 +194,7 @@ func (s *UDMAuthController) Add(c *gin.Context) {
if strings.Contains(data, "ok") {
s.udmAuthService.Insert(neId, body)
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// UDM鉴权用户批量新增
@@ -213,31 +213,31 @@ func (s *UDMAuthController) Add(c *gin.Context) {
// @Description UDM Authentication User Batch Add
// @Router /neData/udm/auth/{neId}/{value} [post]
func (s *UDMAuthController) Adds(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
num := c.Param("num")
if neId == "" || num == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
var body model.UDMAuthUser
err := c.ShouldBindBodyWith(&body, binding.JSON)
err := c.ShouldBindBodyWithJSON(&body)
if err != nil || body.IMSI == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -247,7 +247,7 @@ func (s *UDMAuthController) Adds(c *gin.Context) {
cmd += s.udmAuthService.ParseCommandParams(body)
data, err := telnet.ConvertToStr(telnetClient, cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -255,7 +255,7 @@ func (s *UDMAuthController) Adds(c *gin.Context) {
if strings.Contains(data, "ok") {
s.udmAuthService.LoadData(neId, body.IMSI, num)
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// UDM鉴权用户修改
@@ -273,30 +273,30 @@ func (s *UDMAuthController) Adds(c *gin.Context) {
// @Description UDM Authenticated User Modification
// @Router /neData/udm/auth/{neId} [put]
func (s *UDMAuthController) Edit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
if neId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
var body model.UDMAuthUser
err := c.ShouldBindBodyWith(&body, binding.JSON)
err := c.ShouldBindBodyWithJSON(&body)
if err != nil || body.IMSI == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -306,7 +306,7 @@ func (s *UDMAuthController) Edit(c *gin.Context) {
cmd += s.udmAuthService.ParseCommandParams(body)
data, err := telnet.ConvertToStr(telnetClient, cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -314,7 +314,7 @@ func (s *UDMAuthController) Edit(c *gin.Context) {
if strings.Contains(data, "ok") {
s.udmAuthService.Insert(neId, body)
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// UDM鉴权用户删除
@@ -332,11 +332,11 @@ func (s *UDMAuthController) Edit(c *gin.Context) {
// @Description UDM Authenticated User Deletion
// @Router /neData/udm/auth/{neId}/{value} [delete]
func (s *UDMAuthController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
imsi := c.Param("imsi")
if neId == "" || imsi == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -344,20 +344,20 @@ func (s *UDMAuthController) Remove(c *gin.Context) {
imsiArr := strings.Split(imsi, ",")
uniqueIDs := parse.RemoveDuplicates(imsiArr)
if len(uniqueIDs) <= 0 {
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -378,7 +378,7 @@ func (s *UDMAuthController) Remove(c *gin.Context) {
resultData[imsi] = data
}
c.JSON(200, result.OkData(resultData))
c.JSON(200, resp.OkData(resultData))
}
// UDM鉴权用户批量删除
@@ -397,25 +397,25 @@ func (s *UDMAuthController) Remove(c *gin.Context) {
// @Description UDM Authentication User Batch Deletion
// @Router /neData/udm/auth/{neId}/{imsi}/{num} [delete]
func (s *UDMAuthController) Removes(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
imsi := c.Param("imsi")
num := c.Param("num")
if neId == "" || imsi == "" || num == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -424,7 +424,7 @@ func (s *UDMAuthController) Removes(c *gin.Context) {
cmd := fmt.Sprintf("bde authdat:start_imsi=%s,sub_num=%s", imsi, num)
data, err := telnet.ConvertToStr(telnetClient, cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -432,56 +432,58 @@ func (s *UDMAuthController) Removes(c *gin.Context) {
if strings.Contains(data, "ok") {
s.udmAuthService.LoadData(neId, imsi, num)
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// UDM鉴权用户导出
//
// POST /export
// GET /export
//
// @Tags network_data/udm/auth
// @Accept json
// @Produce json
// @Param data body object true "Request Param"
// @Success 200 {object} object "Response Results"
// @Param neId query string true "NE ID" default(001)
// @Param type query string true "File Type" Enums(csv,txt) default(txt)
// @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 UDM Authenticated User Export
// @Description UDM Authenticated User Export
// @Router /neData/udm/auth/export [post]
// @Router /neData/udm/auth/export [get]
func (s *UDMAuthController) Export(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
neId := querys["neId"].(string)
fileType := querys["type"].(string)
if neId == "" || fileType == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
neId := c.Query("neId")
fileType := c.Query("type")
if neId == "" {
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
if !(fileType == "csv" || fileType == "txt") {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserSubFileFormat")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserSubFileFormat")))
return
}
querys["pageNum"] = 1
querys["pageSize"] = 10000
total, rows := s.udmAuthService.SelectPage(querys)
query := reqctx.QueryMap(c)
total, rows := s.udmAuthService.FindByPage(query)
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
}
// rows := s.udmAuthService.SelectList(model.UDMAuthUser{NeId: neId})
if len(rows) <= 0 {
// 导出数据记录为空
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
// 文件名
fileName := fmt.Sprintf("udm_auth_user_export_%s_%d.%s", neId, time.Now().UnixMilli(), fileType)
filePath := filepath.Join(file.ParseUploadFileDir(uploadsubpath.EXPORT), fileName)
filePath := filepath.Join(file.ParseUploadFileDir(constants.UPLOAD_EXPORT), fileName)
if fileType == "csv" {
// 转换数据
@@ -497,7 +499,7 @@ func (s *UDMAuthController) Export(c *gin.Context) {
// 输出到文件
err := file.WriterFileCSV(data, filePath)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
}
@@ -515,7 +517,7 @@ func (s *UDMAuthController) Export(c *gin.Context) {
// 输出到文件
if err := file.WriterFileTXT(data, ",", filePath); err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
}
@@ -537,59 +539,60 @@ func (s *UDMAuthController) Export(c *gin.Context) {
// @Description UDM Authenticated User Import
// @Router /neData/udm/auth/import [post]
func (s *UDMAuthController) Import(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var body struct {
NeId string `json:"neId" binding:"required"` // 网元ID
UploadPath string `json:"uploadPath" binding:"required"` // 上传文件路径
TypeVal string `json:"typeVal" binding:"required,oneof=default k4"` // default: 默认导入方式, k4: k4类型导入方式
TypeData any `json:"typeData"` // k4类型的数据密钥
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); 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
}
// 判断文件名
if !(strings.HasSuffix(body.UploadPath, ".csv") || strings.HasSuffix(body.UploadPath, ".txt")) {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserAuthFileFormat")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserAuthFileFormat")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", body.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", 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
}
// 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP()
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sftpClient.Close()
// 本地文件
localFilePath := file.ParseUploadFilePath(body.UploadPath)
localFilePath := file.ParseUploadFileAbsPath(body.UploadPath)
neFilePath := fmt.Sprintf("/tmp/%s", filepath.Base(localFilePath))
// 复制到远程
if err = sftpClient.CopyFileLocalToRemote(localFilePath, neFilePath); err != nil {
c.JSON(200, result.ErrMsg("error uploading file"))
c.JSON(200, resp.ErrMsg("error uploading file"))
return
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient(neInfo.NeType, neInfo.NeId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -612,7 +615,7 @@ func (s *UDMAuthController) Import(c *gin.Context) {
}
if resultErr != nil {
c.JSON(200, result.ErrMsg(resultErr.Error()))
c.JSON(200, resp.ErrMsg(resultErr.Error()))
return
}
@@ -627,5 +630,5 @@ func (s *UDMAuthController) Import(c *gin.Context) {
go s.udmAuthService.InsertData(neInfo.NeId, "txt", data)
}
}
c.JSON(200, result.OkMsg(resultMsg))
c.JSON(200, resp.OkMsg(resultMsg))
}

View File

@@ -6,18 +6,18 @@ import (
"strings"
"time"
"be.ems/src/framework/constants/uploadsubpath"
"be.ems/src/framework/constants"
"be.ems/src/framework/i18n"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/telnet"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/file"
"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"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 UDMSubController 结构体
@@ -48,15 +48,15 @@ type UDMSubController struct {
// @Description UDM Subscriber User Reload Data
// @Router /neData/udm/sub/resetData/{neId} [put]
func (s *UDMSubController) ResetData(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
if neId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
data := s.udmSubService.ResetData(neId)
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// UDM签约用户列表
@@ -77,9 +77,9 @@ func (s *UDMSubController) ResetData(c *gin.Context) {
// @Description UDM Subscriber User List
// @Router /neData/udm/sub/list [get]
func (s *UDMSubController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
total, rows := s.udmSubService.SelectPage(querys)
c.JSON(200, result.Ok(map[string]any{"total": total, "rows": rows}))
query := reqctx.QueryMap(c)
total, rows := s.udmSubService.FindByPage(query)
c.JSON(200, resp.OkData(map[string]any{"total": total, "rows": rows}))
}
// UDM签约用户信息
@@ -97,24 +97,24 @@ func (s *UDMSubController) List(c *gin.Context) {
// @Description UDM Subscriber User Information
// @Router /neData/udm/sub/{neId}/{value} [get]
func (s *UDMSubController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
imsi := c.Param("imsi")
if neId == "" || imsi == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -123,19 +123,19 @@ func (s *UDMSubController) Info(c *gin.Context) {
cmd := fmt.Sprintf("dsp udmuser:imsi=%s", imsi)
data, err := telnet.ConvertToMap(telnetClient, cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
if len(data) == 0 {
c.JSON(200, result.ErrMsg("No Subs Data"))
c.JSON(200, resp.ErrMsg("No Subs Data"))
return
}
// 解析返回的数据
u := s.udmSubService.ParseInfo(imsi, neId, data)
s.udmSubService.Insert(neId, u)
c.JSON(200, result.OkData(u))
c.JSON(200, resp.OkData(u))
}
// UDM签约用户新增
@@ -153,30 +153,34 @@ func (s *UDMSubController) Info(c *gin.Context) {
// @Description UDM Subscriber User Added
// @Router /neData/udm/sub/{neId} [post]
func (s *UDMSubController) Add(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
if neId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
var body model.UDMSubUser
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || len(body.IMSI) < 15 {
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 len(body.IMSI) != 15 {
c.JSON(400, resp.CodeMsg(40010, "bind err: IMSI length is not 15 bits"))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -186,7 +190,7 @@ func (s *UDMSubController) Add(c *gin.Context) {
cmd += s.udmSubService.ParseCommandParams(body)
data, err := telnet.ConvertToStr(telnetClient, cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -195,7 +199,7 @@ func (s *UDMSubController) Add(c *gin.Context) {
body.NeId = neId
s.udmSubService.Insert(neId, body)
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// UDM签约用户批量新增
@@ -214,31 +218,35 @@ func (s *UDMSubController) Add(c *gin.Context) {
// @Description UDM Subscriber User Batch Add
// @Router /neData/udm/sub/{neId}/{value} [post]
func (s *UDMSubController) Adds(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
num := c.Param("num")
if neId == "" || num == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
var body model.UDMSubUser
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || len(body.IMSI) < 15 {
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 len(body.IMSI) != 15 {
c.JSON(400, resp.CodeMsg(40010, "bind err: IMSI length is not 15 bits"))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -251,7 +259,7 @@ func (s *UDMSubController) Adds(c *gin.Context) {
cmd = strings.Replace(cmd, omemsisdn, ",", 1)
data, err := telnet.ConvertToStr(telnetClient, cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -259,7 +267,7 @@ func (s *UDMSubController) Adds(c *gin.Context) {
if strings.Contains(data, "ok") {
s.udmSubService.LoadData(neId, body.IMSI, num, body.Remark)
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// UDM签约用户修改
@@ -277,30 +285,34 @@ func (s *UDMSubController) Adds(c *gin.Context) {
// @Description UDM Subscriber User Modification
// @Router /neData/udm/sub/{neId} [put]
func (s *UDMSubController) Edit(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
if neId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
var body model.UDMSubUser
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || len(body.IMSI) < 15 {
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 len(body.IMSI) != 15 {
c.JSON(400, resp.CodeMsg(40010, "bind err: IMSI length is not 15 bits"))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -310,7 +322,7 @@ func (s *UDMSubController) Edit(c *gin.Context) {
cmd += s.udmSubService.ParseCommandParams(body)
data, err := telnet.ConvertToStr(telnetClient, cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -319,7 +331,7 @@ func (s *UDMSubController) Edit(c *gin.Context) {
body.NeId = neId
s.udmSubService.Insert(neId, body)
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// UDM签约用户删除
@@ -337,11 +349,11 @@ func (s *UDMSubController) Edit(c *gin.Context) {
// @Description UDM Subscriber User Deletion
// @Router /neData/udm/sub/{neId}/{value} [delete]
func (s *UDMSubController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
imsi := c.Param("imsi")
if neId == "" || len(imsi) < 15 {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -349,20 +361,20 @@ func (s *UDMSubController) Remove(c *gin.Context) {
imsiArr := strings.Split(imsi, ",")
uniqueIDs := parse.RemoveDuplicates(imsiArr)
if len(uniqueIDs) <= 0 {
c.JSON(200, result.Err(nil))
c.JSON(200, resp.Err(nil))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -383,7 +395,7 @@ func (s *UDMSubController) Remove(c *gin.Context) {
resultData[imsi] = data
}
c.JSON(200, result.OkData(resultData))
c.JSON(200, resp.OkData(resultData))
}
// UDM签约用户批量删除
@@ -402,25 +414,25 @@ func (s *UDMSubController) Remove(c *gin.Context) {
// @Description UDM Subscriber User Batch Deletion
// @Router /neData/udm/sub/{neId}/{imsi}/{num} [delete]
func (s *UDMSubController) Removes(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
neId := c.Param("neId")
imsi := c.Param("imsi")
num := c.Param("num")
if neId == "" || len(imsi) < 15 || num == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != 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
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -429,7 +441,7 @@ func (s *UDMSubController) Removes(c *gin.Context) {
cmd := fmt.Sprintf("bde udmuser:start_imsi=%s,sub_num=%s", imsi, num)
data, err := telnet.ConvertToStr(telnetClient, cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -437,56 +449,59 @@ func (s *UDMSubController) Removes(c *gin.Context) {
if strings.Contains(data, "ok") {
s.udmSubService.LoadData(neId, imsi, num, "-(Deleted)-")
}
c.JSON(200, result.OkData(data))
c.JSON(200, resp.OkData(data))
}
// UDM签约用户导出
//
// POST /export
// GET /export
//
// @Tags network_data/udm/sub
// @Accept json
// @Produce json
// @Param data body object true "Request Param"
// @Success 200 {object} object "Response Results"
// @Param neId query string true "NE ID" default(001)
// @Param type query string true "File Type" Enums(csv,txt) default(txt)
// @Param imsi query string false "IMSI"
// @Param msisdn query string false "Msisdn"
// @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 UDM Subscriber User Export
// @Description UDM Subscriber User Export
// @Router /neData/udm/sub/export [post]
func (s *UDMSubController) Export(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
neId := querys["neId"].(string)
fileType := querys["type"].(string)
neId := c.Query("neId")
fileType := c.Query("type")
if neId == "" || fileType == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
if !(fileType == "csv" || fileType == "txt") {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserSubFileFormat")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserSubFileFormat")))
return
}
querys["pageNum"] = 1
querys["pageSize"] = 10000
total, rows := s.udmSubService.SelectPage(querys)
query := reqctx.QueryMap(c)
total, rows := s.udmSubService.FindByPage(query)
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
}
// rows := s.udmSubService.SelectList(model.UDMSubUser{NeId: neId})
if len(rows) <= 0 {
// 导出数据记录为空
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
// 文件名
fileName := fmt.Sprintf("udm_sub_user_export_%s_%d.%s", neId, time.Now().UnixMilli(), fileType)
filePath := filepath.Join(file.ParseUploadFileDir(uploadsubpath.EXPORT), fileName)
filePath := filepath.Join(file.ParseUploadFileDir(constants.UPLOAD_EXPORT), fileName)
if fileType == "csv" {
// 转换数据
@@ -498,7 +513,7 @@ func (s *UDMSubController) Export(c *gin.Context) {
}
// 输出到文件
if err := file.WriterFileCSV(data, filePath); err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
}
@@ -512,7 +527,7 @@ func (s *UDMSubController) Export(c *gin.Context) {
}
// 输出到文件
if err := file.WriterFileTXT(data, ",", filePath); err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
}
@@ -534,57 +549,58 @@ func (s *UDMSubController) Export(c *gin.Context) {
// @Description UDM Subscriber User Import
// @Router /neData/udm/sub/import [post]
func (s *UDMSubController) Import(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var body struct {
NeId string `json:"neId" binding:"required"`
UploadPath string `json:"uploadPath" binding:"required"`
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); 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
}
// 判断文件名
if !(strings.HasSuffix(body.UploadPath, ".csv") || strings.HasSuffix(body.UploadPath, ".txt")) {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserSubFileFormat")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "ne.udm.errImportUserSubFileFormat")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", body.NeId)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UDM", 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
}
// 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP()
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sftpClient.Close()
// 本地文件
localFilePath := file.ParseUploadFilePath(body.UploadPath)
localFilePath := file.ParseUploadFileAbsPath(body.UploadPath)
neFilePath := fmt.Sprintf("/tmp/%s", filepath.Base(localFilePath))
// 复制到远程
if err = sftpClient.CopyFileLocalToRemote(localFilePath, neFilePath); err != nil {
c.JSON(200, result.ErrMsg("error uploading file"))
c.JSON(200, resp.ErrMsg("error uploading file"))
return
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient(neInfo.NeType, neInfo.NeId, 1)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
@@ -593,7 +609,7 @@ func (s *UDMSubController) Import(c *gin.Context) {
cmd := fmt.Sprintf("import udmuser:path=%s", neFilePath)
data, err := telnet.ConvertToStr(telnetClient, cmd)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -608,5 +624,5 @@ func (s *UDMSubController) Import(c *gin.Context) {
go s.udmSubService.InsertData(neInfo.NeId, "txt", data)
}
}
c.JSON(200, result.OkMsg(data))
c.JSON(200, resp.OkMsg(data))
}

View File

@@ -2,25 +2,26 @@ package controller
import (
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo/result"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
neDataService "be.ems/src/modules/network_data/service"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
)
// 实例化控制层 UPFController 结构体
var NewUPF = &UPFController{
neInfoService: neService.NewNeInfo,
perfKPIService: neDataService.NewPerfKPI,
neInfoService: neService.NewNeInfo,
kpiReportService: neDataService.NewKpiReport,
}
// 网元UPF
//
// PATH /upf
type UPFController struct {
neInfoService *neService.NeInfo // 网元信息服务
perfKPIService *neDataService.PerfKPI // 统计信息服务
neInfoService *neService.NeInfo // 网元信息服务
kpiReportService *neDataService.KpiReport // 统计信息服务
}
// 总流量数 N3上行 N6下行
@@ -38,25 +39,24 @@ type UPFController struct {
// @Summary Total number of flows N3 upstream N6 downstream
// @Description Total number of flows N3 upstream N6 downstream
// @Router /neData/upf/totalFlow [get]
func (s *UPFController) TotalFlow(c *gin.Context) {
language := ctx.AcceptLanguage(c)
func (s UPFController) TotalFlow(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var querys struct {
NeID string `form:"neId" binding:"required"`
Day int `form:"day"`
}
if err := c.ShouldBindQuery(&querys); querys.Day < 0 || err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UPF", querys.NeID)
neInfo := s.neInfoService.FindByNeTypeAndNeID("UPF", 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
}
data := s.perfKPIService.SelectUPFTotalFlow(neInfo.NeType, neInfo.RmUID, querys.Day)
c.JSON(200, result.OkData(data))
data := s.kpiReportService.FindUPFTotalFlow(neInfo.RmUID, querys.Day)
c.JSON(200, resp.OkData(data))
}