feat: cbs message enhance
This commit is contained in:
@@ -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