From 1b2d8c9d589b233e7614de234f795f120adb60b6 Mon Sep 17 00:00:00 2001 From: zhangsz Date: Sat, 17 May 2025 18:07:58 +0800 Subject: [PATCH] feat: support mf calling api --- config/param/mf_param_config.yaml | 7 +++ features/features.go | 2 + features/ue/api.go | 18 ++++++++ features/ue/mf_calling/controller.go | 66 ++++++++++++++++++++++++++++ features/ue/mf_calling/model.go | 24 ++++++++++ features/ue/mf_calling/service.go | 38 ++++++++++++++++ restagent/etc/restconf.yaml | 6 +-- 7 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 features/ue/api.go create mode 100644 features/ue/mf_calling/controller.go create mode 100644 features/ue/mf_calling/model.go create mode 100644 features/ue/mf_calling/service.go diff --git a/config/param/mf_param_config.yaml b/config/param/mf_param_config.yaml index 61c4d989..53d080ac 100644 --- a/config/param/mf_param_config.yaml +++ b/config/param/mf_param_config.yaml @@ -49,3 +49,10 @@ mf: filter: "" display: "Domain" comment: "ip:port" + - name: "onlineStatus" + type: "bool" + value: "false" + access: "read-only" + filter: '{"0":"false", "1":"true"}' + display: "Online Status" + comment: "Online Status" diff --git a/features/features.go b/features/features.go index e4f68c75..49c5eb70 100644 --- a/features/features.go +++ b/features/features.go @@ -5,6 +5,7 @@ import ( "be.ems/features/lm" "be.ems/features/nbi" "be.ems/features/pm" + "be.ems/features/ue" "be.ems/lib/log" "github.com/gin-gonic/gin" ) @@ -18,5 +19,6 @@ func InitServiceEngine(r *gin.Engine) { lm.InitSubServiceRoute(r) cm.InitSubServiceRoute(r) nbi.InitSubServiceRoute(r) + ue.InitSubServiceRoute(r) // return featuresGroup } diff --git a/features/ue/api.go b/features/ue/api.go new file mode 100644 index 00000000..f81ced35 --- /dev/null +++ b/features/ue/api.go @@ -0,0 +1,18 @@ +// log management package + +package ue + +import ( + "be.ems/features/ue/mf_calling" + "be.ems/lib/log" + "github.com/gin-gonic/gin" +) + +func InitSubServiceRoute(r *gin.Engine) { + log.Info("======init UE management group gin.Engine") + + mfGroup := r.Group("/psap/v1/mf") + + mf_calling.Register(mfGroup) + // register other sub modules routes +} diff --git a/features/ue/mf_calling/controller.go b/features/ue/mf_calling/controller.go new file mode 100644 index 00000000..bd3a9451 --- /dev/null +++ b/features/ue/mf_calling/controller.go @@ -0,0 +1,66 @@ +package mf_calling + +import ( + "be.ems/src/framework/i18n" + "be.ems/src/framework/middleware" + "be.ems/src/framework/utils/ctx" + "be.ems/src/framework/vo/result" + "github.com/gin-gonic/gin" + + neService "be.ems/src/modules/network_element/service" +) + +// @Description Register Routes for mf calling +func Register(r *gin.RouterGroup) { + + mfCallingGroup := r.Group("/callings") + { + var m *MfCallingInfo + mfCallingGroup.GET("/:neId/list", + middleware.PreAuthorize(nil), + m.List, + ) + } +} + +func (s *MfCallingInfo) List(c *gin.Context) { + language := ctx.AcceptLanguage(c) + var querys struct { + NeId string `form:"neId" binding:"required"` + TenantName string `form:"tenantName"` + } + if err := c.ShouldBindQuery(&querys); err != nil { + c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) + return + } + + // 处理租户逻辑 + loginUser, _ := ctx.LoginUser(c) + if len(loginUser.User.Roles) > 0 { + for _, v := range loginUser.User.Roles { + if v.RoleKey == "tenant" { + querys.TenantName = loginUser.User.UserName + break + } + } + } + + // 查询网元信息 + neInfo := neService.NewNeInfo.SelectNeInfoByNeTypeAndNeID("MF", querys.NeId) + if neInfo.NeId != querys.NeId || neInfo.IP == "" { + c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo"))) + return + } + // 1. 调用服务层方法,向网元MF发起API请求 + data, total, err := s.GetCallingInfoFromMF(neInfo) + if err != nil { + c.JSON(500, result.ErrMsg(err.Error())) + return + } + + // 2. 返回前端 + c.JSON(200, result.Ok(gin.H{ + "total": total, + "rows": data, + })) +} diff --git a/features/ue/mf_calling/model.go b/features/ue/mf_calling/model.go new file mode 100644 index 00000000..a4cc68cf --- /dev/null +++ b/features/ue/mf_calling/model.go @@ -0,0 +1,24 @@ +package mf_calling + +// @Description VoLTE用户信息 +type MfCallingInfo struct { + AnsweredTime string `json:"answeredTime" gorm:"column:answered_time"` // 接听时间 + BLegUuid string `json:"bLegUuid" gorm:"column:b_leg_uuid"` // BLeg UUID + CallDuration string `json:"callDuration" gorm:"column:call_duration"` // 通话时长 + CallState string `json:"callState" gorm:"column:call_state"` // 通话状态 + CalleeIdName string `json:"calleeIdName" gorm:"column:callee_id_name"` // 被叫用户名称 + CalleeIdNumber string `json:"calleeIdNumber" gorm:"column:callee_id_number"` // 被叫用户电话号码 + CallerIdName string `json:"callerIdName" gorm:"column:caller_id_name"` // 主叫用户名称 + CallerIdNumber string `json:"callerIdNumber" gorm:"column:caller_id_number"` // 主叫用户电话号码 + CreatedTime string `json:"createdTime" gorm:"column:created_time"` // 创建时间 + Direction string `json:"direction" gorm:"column:direction"` // 通话方向 + Uuid string `json:"uuid" gorm:"column:uuid"` // uuid + + TenantID string `json:"tenantID" gorm:"column:tenant_id"` + TenantName string `json:"tenantName" gorm:"-"` +} + +// TableName 表名称 +func (*MfCallingInfo) TableName() string { + return "mf_calling_info" +} diff --git a/features/ue/mf_calling/service.go b/features/ue/mf_calling/service.go new file mode 100644 index 00000000..fde3c2a7 --- /dev/null +++ b/features/ue/mf_calling/service.go @@ -0,0 +1,38 @@ +package mf_calling + +import ( + "encoding/json" + "fmt" + "io" + "net/http" + + neModel "be.ems/src/modules/network_element/model" +) + +func (s *MfCallingInfo) GetCallingInfoFromMF(neInfo neModel.NeInfo) ([]MfCallingInfo, int, error) { + // 构造网元MF的API地址 + url := fmt.Sprintf("http://%s:%d/api/rest/psap/v1/mf/callingInfo", neInfo.IP, neInfo.Port) + + // 可根据querys拼接更多参数 + + resp, err := http.Get(url) + if err != nil { + return nil, 0, err + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, 0, err + } + + // 假设MF返回格式为 {"totalCalls": 10, "Data": [...]} + var mfResp struct { + TotalCalls int `json:"totalCalls"` + Data []MfCallingInfo `json:"data"` + } + if err := json.Unmarshal(body, &mfResp); err != nil { + return nil, 0, err + } + return mfResp.Data, mfResp.TotalCalls, nil +} diff --git a/restagent/etc/restconf.yaml b/restagent/etc/restconf.yaml index f9ca55a9..9836dc69 100644 --- a/restagent/etc/restconf.yaml +++ b/restagent/etc/restconf.yaml @@ -32,7 +32,7 @@ rest: webServer: enabled: true - rootDir: /home/simon/omc.git/fe.ems.vue3/dist # front-end build dist directory + rootDir: /home/simon/psap.git/fe.ems.vue3/dist # front-end build dist directory listen: - addr: :8080 schema: http @@ -47,7 +47,7 @@ database: type: mysql user: root password: "1000omc@kp!" - host: "127.0.0.1" + host: "192.168.2.223" port: 33066 name: omc_db connParam: charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&interpolateParams=True @@ -59,7 +59,7 @@ redis: # OMC system db default: port: 6379 # Redis port - host: "127.0.0.1" # Redis host + host: "192.168.2.223" # Redis host password: "helloearth" db: 10 # Redis db_num # used to specify the default data source for multiple data resourece