feat: 新增UE会话事件
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 实例化控制层 PerfKPIController 结构体
|
// 实例化控制层 CDREventController 结构体
|
||||||
var NewCDREventController = &CDREventController{
|
var NewCDREventController = &CDREventController{
|
||||||
neInfoService: neService.NewNeInfoImpl,
|
neInfoService: neService.NewNeInfoImpl,
|
||||||
cdrEventService: neDataService.NewCDREventImpl,
|
cdrEventService: neDataService.NewCDREventImpl,
|
||||||
|
|||||||
51
src/modules/network_data/controller/ue_event.go
Normal file
51
src/modules/network_data/controller/ue_event.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ems.agt/src/framework/i18n"
|
||||||
|
"ems.agt/src/framework/utils/ctx"
|
||||||
|
"ems.agt/src/framework/vo/result"
|
||||||
|
"ems.agt/src/modules/network_data/model"
|
||||||
|
neDataService "ems.agt/src/modules/network_data/service"
|
||||||
|
neService "ems.agt/src/modules/network_element/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化控制层 UEEventController 结构体
|
||||||
|
var NewUEEventController = &UEEventController{
|
||||||
|
neInfoService: neService.NewNeInfoImpl,
|
||||||
|
ueEventService: neDataService.NewUEEventImpl,
|
||||||
|
}
|
||||||
|
|
||||||
|
// UE会话事件
|
||||||
|
//
|
||||||
|
// PATH /ue
|
||||||
|
type UEEventController struct {
|
||||||
|
// 网元信息服务
|
||||||
|
neInfoService neService.INeInfo
|
||||||
|
// CDR会话事件服务
|
||||||
|
ueEventService neDataService.IUEEvent
|
||||||
|
}
|
||||||
|
|
||||||
|
// UE会话列表
|
||||||
|
//
|
||||||
|
// GET /list
|
||||||
|
func (s *UEEventController) List(c *gin.Context) {
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
|
var querys model.UEEventQuery
|
||||||
|
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||||
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
|
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
|
||||||
|
|
||||||
|
// 查询数据
|
||||||
|
data := s.ueEventService.SelectPage(querys)
|
||||||
|
c.JSON(200, result.Ok(data))
|
||||||
|
}
|
||||||
28
src/modules/network_data/model/ue_event.go
Normal file
28
src/modules/network_data/model/ue_event.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
// UEEvent UE会话对象 ue_event
|
||||||
|
type UEEvent struct {
|
||||||
|
ID string `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
|
||||||
|
NeType string `json:"neType" gorm:"column:ne_type"`
|
||||||
|
NeName string `json:"neName" gorm:"column:ne_name"`
|
||||||
|
RmUID string `json:"rmUID" gorm:"column:rm_uid"`
|
||||||
|
Timestamp int64 `json:"timestamp" gorm:"column:timestamp"`
|
||||||
|
EventType string `json:"eventType" gorm:"column:event_type"`
|
||||||
|
EventJSONStr string `json:"eventJSON" gorm:"column:event_json"`
|
||||||
|
CreatedAt time.Time `json:"createdAt" gorm:"column:created_at;default:CURRENT_TIMESTAMP"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UEEventQuery UE会话对象查询参数结构体
|
||||||
|
type UEEventQuery struct {
|
||||||
|
NeType string `json:"neType" form:"neType" binding:"required"`
|
||||||
|
NeID string `json:"neId" form:"neId" binding:"required"`
|
||||||
|
RmUID string `json:"rmUID" form:"rmUID"`
|
||||||
|
StartTime string `json:"startTime" form:"startTime"`
|
||||||
|
EndTime string `json:"endTime" form:"endTime"`
|
||||||
|
SortField string `json:"sortField" form:"sortField" binding:"omitempty,oneof=timestamp"`
|
||||||
|
SortOrder string `json:"sortOrder" form:"sortOrder" binding:"omitempty,oneof=asc desc"`
|
||||||
|
PageNum int64 `json:"pageNum" form:"pageNum" binding:"required"`
|
||||||
|
PageSize int64 `json:"pageSize" form:"pageSize" binding:"required"`
|
||||||
|
}
|
||||||
@@ -36,4 +36,13 @@ func Setup(router *gin.Engine) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UE会话事件信息
|
||||||
|
ueGroup := neDataGroup.Group("/ue")
|
||||||
|
{
|
||||||
|
ueGroup.GET("/list",
|
||||||
|
middleware.PreAuthorize(nil),
|
||||||
|
controller.NewUEEventController.List,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ import (
|
|||||||
"ems.agt/src/modules/network_data/model"
|
"ems.agt/src/modules/network_data/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 实例化数据层 PerfKPIImpl 结构体
|
// 实例化数据层 CDREventImpl 结构体
|
||||||
var NewCDREventImpl = &CDREventImpl{
|
var NewCDREventImpl = &CDREventImpl{
|
||||||
selectSql: `select id, ne_type, ne_name, rm_uid, timestamp, cdr_json ,created_at from cdr_event`,
|
selectSql: `select id, ne_type, ne_name, rm_uid, timestamp, cdr_json, created_at from cdr_event`,
|
||||||
|
|
||||||
resultMap: map[string]string{
|
resultMap: map[string]string{
|
||||||
"id": "ID",
|
"id": "ID",
|
||||||
@@ -120,7 +120,6 @@ func (r *CDREventImpl) SelectPage(querys model.CDREventQuery) map[string]any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 查询数据
|
// 查询数据
|
||||||
|
|
||||||
querySql := r.selectSql + whereSql + orderSql + pageSql
|
querySql := r.selectSql + whereSql + orderSql + pageSql
|
||||||
results, err := datasource.RawDB("", querySql, params)
|
results, err := datasource.RawDB("", querySql, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
9
src/modules/network_data/repository/ue_event.go
Normal file
9
src/modules/network_data/repository/ue_event.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import "ems.agt/src/modules/network_data/model"
|
||||||
|
|
||||||
|
// UE会话事件 数据层接口
|
||||||
|
type IUEEvent interface {
|
||||||
|
// SelectPage 根据条件分页查询
|
||||||
|
SelectPage(querys model.UEEventQuery) map[string]any
|
||||||
|
}
|
||||||
133
src/modules/network_data/repository/ue_event.impl.go
Normal file
133
src/modules/network_data/repository/ue_event.impl.go
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"ems.agt/src/framework/datasource"
|
||||||
|
"ems.agt/src/framework/logger"
|
||||||
|
"ems.agt/src/framework/utils/date"
|
||||||
|
"ems.agt/src/framework/utils/parse"
|
||||||
|
"ems.agt/src/framework/utils/repo"
|
||||||
|
"ems.agt/src/modules/network_data/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化数据层 UEEventImpl 结构体
|
||||||
|
var NewUEEventImpl = &UEEventImpl{
|
||||||
|
selectSql: `select id, ne_type, ne_name, rm_uid, timestamp, event_type, event_json, created_at from ue_event`,
|
||||||
|
|
||||||
|
resultMap: map[string]string{
|
||||||
|
"id": "ID",
|
||||||
|
"ne_type": "NeType",
|
||||||
|
"ne_name": "NeName",
|
||||||
|
"rm_uid": "RmUID",
|
||||||
|
"timestamp": "Timestamp",
|
||||||
|
"event_type": "EventType",
|
||||||
|
"event_json": "EventJSONStr",
|
||||||
|
"created_at": "CreatedAt",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// UEEventImpl UE会话事件 数据层处理
|
||||||
|
type UEEventImpl struct {
|
||||||
|
// 查询视图对象SQL
|
||||||
|
selectSql string
|
||||||
|
// 结果字段与实体映射
|
||||||
|
resultMap map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
// convertResultRows 将结果记录转实体结果组
|
||||||
|
func (r *UEEventImpl) convertResultRows(rows []map[string]any) []model.UEEvent {
|
||||||
|
arr := make([]model.UEEvent, 0)
|
||||||
|
for _, row := range rows {
|
||||||
|
item := model.UEEvent{}
|
||||||
|
for key, value := range row {
|
||||||
|
if keyMapper, ok := r.resultMap[key]; ok {
|
||||||
|
repo.SetFieldValue(&item, keyMapper, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arr = append(arr, item)
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
||||||
|
// SelectPage 根据条件分页查询
|
||||||
|
func (r *UEEventImpl) SelectPage(querys model.UEEventQuery) map[string]any {
|
||||||
|
// 查询条件拼接
|
||||||
|
var conditions []string
|
||||||
|
var params []any
|
||||||
|
if querys.NeType != "" {
|
||||||
|
conditions = append(conditions, "ne_type = ?")
|
||||||
|
params = append(params, querys.NeType)
|
||||||
|
}
|
||||||
|
if querys.RmUID != "" {
|
||||||
|
conditions = append(conditions, "rm_uid = ?")
|
||||||
|
params = append(params, querys.RmUID)
|
||||||
|
}
|
||||||
|
if querys.StartTime != "" {
|
||||||
|
conditions = append(conditions, "timestamp >= ?")
|
||||||
|
beginDate := date.ParseStrToDate(querys.StartTime, date.YYYY_MM_DD_HH_MM_SS)
|
||||||
|
params = append(params, beginDate.Unix())
|
||||||
|
}
|
||||||
|
if querys.EndTime != "" {
|
||||||
|
conditions = append(conditions, "timestamp <= ?")
|
||||||
|
endDate := date.ParseStrToDate(querys.EndTime, date.YYYY_MM_DD_HH_MM_SS)
|
||||||
|
params = append(params, endDate.Unix())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建查询条件语句
|
||||||
|
whereSql := ""
|
||||||
|
if len(conditions) > 0 {
|
||||||
|
whereSql += " where " + strings.Join(conditions, " and ")
|
||||||
|
}
|
||||||
|
|
||||||
|
result := map[string]any{
|
||||||
|
"total": 0,
|
||||||
|
"rows": []model.CDREvent{},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询数量 长度为0直接返回
|
||||||
|
totalSql := "select count(1) as 'total' from ue_event"
|
||||||
|
totalRows, err := datasource.RawDB("", totalSql+whereSql, params)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("total err => %v", err)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
total := parse.Number(totalRows[0]["total"])
|
||||||
|
if total == 0 {
|
||||||
|
return result
|
||||||
|
} else {
|
||||||
|
result["total"] = total
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分页
|
||||||
|
pageNum, pageSize := repo.PageNumSize(querys.PageNum, querys.PageSize)
|
||||||
|
pageSql := " limit ?,? "
|
||||||
|
params = append(params, pageNum*pageSize)
|
||||||
|
params = append(params, pageSize)
|
||||||
|
|
||||||
|
// 排序
|
||||||
|
orderSql := ""
|
||||||
|
if querys.SortField != "" {
|
||||||
|
sortSql := querys.SortField
|
||||||
|
if querys.SortOrder != "" {
|
||||||
|
if querys.SortOrder == "desc" {
|
||||||
|
sortSql += " desc "
|
||||||
|
} else {
|
||||||
|
sortSql += " asc "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
orderSql = fmt.Sprintf(" order by %s ", sortSql)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询数据
|
||||||
|
querySql := r.selectSql + whereSql + orderSql + pageSql
|
||||||
|
results, err := datasource.RawDB("", querySql, params)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("query err => %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换实体
|
||||||
|
result["rows"] = r.convertResultRows(results)
|
||||||
|
return result
|
||||||
|
}
|
||||||
9
src/modules/network_data/service/ue_event.go
Normal file
9
src/modules/network_data/service/ue_event.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import "ems.agt/src/modules/network_data/model"
|
||||||
|
|
||||||
|
// UE会话事件 服务层接口
|
||||||
|
type IUEEvent interface {
|
||||||
|
// SelectPage 根据条件分页查询
|
||||||
|
SelectPage(querys model.UEEventQuery) map[string]any
|
||||||
|
}
|
||||||
22
src/modules/network_data/service/ue_event.impl.go
Normal file
22
src/modules/network_data/service/ue_event.impl.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ems.agt/src/modules/network_data/model"
|
||||||
|
"ems.agt/src/modules/network_data/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化数据层 UEEventImpl 结构体
|
||||||
|
var NewUEEventImpl = &UEEventImpl{
|
||||||
|
ueEventRepository: repository.NewUEEventImpl,
|
||||||
|
}
|
||||||
|
|
||||||
|
// UEEventImpl UE会话事件 服务层处理
|
||||||
|
type UEEventImpl struct {
|
||||||
|
// UE会话事件数据信息
|
||||||
|
ueEventRepository repository.IUEEvent
|
||||||
|
}
|
||||||
|
|
||||||
|
// SelectPage 根据条件分页查询
|
||||||
|
func (r *UEEventImpl) SelectPage(querys model.UEEventQuery) map[string]any {
|
||||||
|
return r.ueEventRepository.SelectPage(querys)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user