add: cdr and ue event for multi-tenancy
This commit is contained in:
@@ -2,6 +2,7 @@ package cdr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -212,6 +213,7 @@ type CDREvent struct {
|
||||
RmUID string `json:"rmUID" xorm:"rm_uid"`
|
||||
Timestamp int `json:"timestamp" xorm:"timestamp"`
|
||||
CDR map[string]any `json:"CDR" xorm:"cdr_json"`
|
||||
TenantID string `json:"tenantID" xorm:"tenant_id"`
|
||||
}
|
||||
|
||||
func PostCDREventFromIMS(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -234,6 +236,16 @@ func PostCDREventFromIMS(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
log.Trace("cdrEvent:", cdrEvent)
|
||||
|
||||
// for multi-tenancy
|
||||
where := fmt.Sprintf("'%v' like msisdn", cdrEvent.CDR["callerParty"])
|
||||
tenantID, err := dborm.XormGetSingleColStringByWhere("u_sub_user", "tenant_id", where)
|
||||
if err != nil {
|
||||
log.Errorf("failed to get tenant_id:%v", err)
|
||||
}
|
||||
if tenantID != "" {
|
||||
cdrEvent.TenantID = tenantID
|
||||
}
|
||||
|
||||
affected, err := dborm.XormInsertTableOne("cdr_event_ims", cdrEvent)
|
||||
if err != nil && affected <= 0 {
|
||||
log.Error("Failed to insert cdr_event_ims:", err)
|
||||
@@ -271,6 +283,29 @@ func PostCDREventFromSMF(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
log.Trace("cdrEvent:", cdrEvent)
|
||||
|
||||
cdrJson, err := json.Marshal(cdrEvent.CDR)
|
||||
if err != nil {
|
||||
log.Error("Failed to Marshal cdr:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
cdr := new(ChargingRecord)
|
||||
err = json.Unmarshal(cdrJson, &cdr)
|
||||
if err != nil {
|
||||
log.Error("Failed to Unmarshal cdr:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
// for multi-tenancy
|
||||
where := fmt.Sprintf("'%v' like imsi or '%v' like msisdn", cdr.SubscriberIdentifier.SubscriptionIDData, cdr.SubscriberIdentifier.SubscriptionIDData)
|
||||
tenantID, err := dborm.XormGetSingleColStringByWhere("u_sub_user", "tenant_id", where)
|
||||
if err != nil {
|
||||
log.Errorf("failed to get tenant_id:%v", err)
|
||||
}
|
||||
if tenantID != "" {
|
||||
cdrEvent.TenantID = tenantID
|
||||
}
|
||||
|
||||
affected, err := dborm.XormInsertTableOne("cdr_event_smf", cdrEvent)
|
||||
if err != nil && affected <= 0 {
|
||||
log.Error("Failed to insert cdr_event_smf:", err)
|
||||
|
||||
Reference in New Issue
Block a user