feat: cbs message enhance
This commit is contained in:
@@ -7,17 +7,38 @@ import (
|
||||
"be.ems/features/ue/mf_callback_ticket"
|
||||
"be.ems/features/ue/mf_calling"
|
||||
"be.ems/lib/log"
|
||||
"be.ems/src/framework/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Register registers the UE management routes
|
||||
// @Description Register UE management routes
|
||||
// @Tags UE Management
|
||||
// @Router /api/ue/v1 [get]
|
||||
func Register(r *gin.RouterGroup) {
|
||||
log.Info("======init UE management group gin.Engine")
|
||||
|
||||
cbGroup := r.Group("/:neType")
|
||||
{
|
||||
cbGroup.POST("/:cbsState",
|
||||
middleware.PreAuthorize(nil),
|
||||
PostCBSState,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func InitSubServiceRoute(r *gin.Engine) {
|
||||
log.Info("======init UE management group gin.Engine")
|
||||
|
||||
mfGroup := r.Group("/psap/v1/mf")
|
||||
cbeGroup := r.Group("/psap/v1/cbc")
|
||||
cbsGroup := r.Group("/api/ue/v1")
|
||||
|
||||
mf_calling.Register(mfGroup)
|
||||
mf_callback_ticket.Register(mfGroup)
|
||||
cb_message.Register(cbeGroup)
|
||||
Register(cbsGroup)
|
||||
// register other sub modules routes
|
||||
|
||||
log.Info("======init UE management group gin.Engine end")
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ func (m *CBMessage) List(c *gin.Context) {
|
||||
"neId": msg.NeId,
|
||||
"messageJson": messageJson, // 这里是解析后的 JSON 对象
|
||||
"status": msg.Status.Enum(),
|
||||
"detail": msg.Detail,
|
||||
"createdAt": msg.CreatedAt,
|
||||
"updatedAt": msg.UpdatedAt,
|
||||
}
|
||||
@@ -274,6 +275,7 @@ func (m *CBMessage) GetById(c *gin.Context) {
|
||||
"neId": data.NeId,
|
||||
"messageJson": messageJson, // 这里是解析后的 JSON 对象
|
||||
"status": data.Status.Enum(),
|
||||
"detail": data.Detail,
|
||||
"createdAt": data.CreatedAt,
|
||||
"updatedAt": data.UpdatedAt,
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ type CBMessage struct {
|
||||
NeId string `json:"neId" gorm:"column:ne_id"` // 网元ID
|
||||
MessageJson json.RawMessage `json:"messageJson" gorm:"column:message_json"` // 消息内容JSON
|
||||
Status CBEventStatus `json:"status" gorm:"column:status"` // 消息状态
|
||||
Detail string `json:"detail" gorm:"column:detail"` // 详情
|
||||
CreatedAt int64 `json:"createdAt" gorm:"column:created_at"` // 创建时间
|
||||
UpdatedAt *int64 `json:"updatedAt" gorm:"column:updated_at;autoUpdateTime:false"` // 更新时间
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
neDataModel "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/go-resty/resty/v2"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
@@ -830,3 +831,61 @@ func GetUEInfoFileExportNF(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
// 走Gin
|
||||
UriCBSStateG = "/api/ue/v1/:neType/:objectType"
|
||||
// 走Mux
|
||||
UriCBSState = config.DefaultUriPrefix + "/ueManagement/v1/elementType/{elementTypeValue}/objectType/cbsState"
|
||||
CustomUriCBSState = config.UriPrefix + "/ueManagement/v1/elementType/{elementTypeValue}/objectType/cbsState"
|
||||
)
|
||||
|
||||
// @Description CBSManagement CB消息
|
||||
type CBSState struct {
|
||||
NeName string `json:"neName"` // 网元名称
|
||||
RmUID string `json:"rmUID"` // 网元唯一标识
|
||||
EventData []struct {
|
||||
EventName string `json:"eventName"` // 事件名称
|
||||
MessageId int64 `json:"messageId"` // 消息ID
|
||||
Detail string `json:"detail"` // 详情
|
||||
} `json:"eventData"` // 事件数据
|
||||
}
|
||||
|
||||
// PostCBSState 接收来自CBC的CBS状态信息
|
||||
// @Summary Post CBS State
|
||||
// @Description 接收来自CBC的CBS状态信息
|
||||
func PostCBSState(c *gin.Context) {
|
||||
PostCBSStateFromCBC(c.Writer, c.Request)
|
||||
}
|
||||
|
||||
// PostCBSStateFromCBC 接收来自CBC的CBS状态信息
|
||||
// @Summary Post CBS State from CBC
|
||||
// @Description 接收来自CBC的CBS状态信息
|
||||
// @Tags UE Management
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
func PostCBSStateFromCBC(w http.ResponseWriter, r *http.Request) {
|
||||
log.Info("PostStateFromCBC processing... ")
|
||||
|
||||
var state CBSState
|
||||
if err := ctx.ShouldBindJSON(r, &state); err != nil {
|
||||
log.Error("Failed to Unmarshal CBSState:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now().UnixMicro()
|
||||
for _, eventData := range state.EventData {
|
||||
if err := dborm.DefaultDB().Table("cb_message").
|
||||
Where("JSON_EXTRACT(message_json, '$.eventName') = ?", eventData.EventName).
|
||||
Updates(map[string]any{
|
||||
"detail": eventData.Detail,
|
||||
"updated_at": now,
|
||||
}).Error; err != nil {
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
services.ResponseStatusOK204NoContent(w)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user