Merge branch 'main' into multi-tenant

This commit is contained in:
2024-10-31 17:50:10 +08:00
229 changed files with 11395 additions and 11870 deletions

View File

@@ -16,26 +16,35 @@ import (
// 实例化数据层 UDMSubUser 结构体
var NewUDMSub = &UDMSubUser{
selectSql: `select
s.id, s.msisdn, s.imsi, s.ambr, s.nssai, s.rat, s.arfb, s.sar, s.cn, s.sm_data, s.smf_sel, s.eps_dat,
s.ne_id, s.eps_flag, s.eps_odb, s.hplmn_odb, s.ard, s.epstpl, s.context_id, s.apn_context, s.static_ip,
s.cag,
s.id, s.imsi, s.msisdn, s.ne_id,
s.am_dat, s.ambr, s.nssai, s.rat, s.arfb, s.sar, s.cn_type, s.rfsp_index, s.reg_timer, s.ue_usage_type, s.active_time, s.mico, s.odb_ps, s.group_id,
s.eps_dat, s.eps_flag, s.eps_odb, s.hplmn_odb, s.ard, s.epstpl, s.context_id, s.apn_mum, s.apn_context, s.static_ip,
s.sm_data, s.smf_sel, s.cag,
t.tenant_id, t.tenant_name
from u_sub_user s
from u_sub_user s
left join sys_tenant t on t.tenant_id = s.tenant_id and t.status = 1`,
resultMap: map[string]string{
"id": "ID",
"imsi": "IMSI",
"msisdn": "MSISDN",
"ne_id": "NeId",
"ambr": "Ambr",
"nssai": "Nssai",
"rat": "Rat",
"arfb": "Arfb",
"sar": "Sar",
"cn": "Cn",
"sm_data": "SmData",
"smf_sel": "SmfSel",
"id": "ID",
"imsi": "IMSI",
"msisdn": "MSISDN",
"ne_id": "NeId",
"am_dat": "AmDat",
"ambr": "UeAmbrTpl",
"nssai": "NssaiTpl",
"rat": "RatRestrictions",
"arfb": "AreaForbiddenTpl",
"sar": "ServiceAreaRestrictionTpl",
"cn_type": "CnTypeRestrictions",
"rfsp_index": "RfspIndex",
"reg_timer": "SubsRegTime",
"ue_usage_type": "UeUsageType",
"active_time": "ActiveTime",
"mico": "MicoAllowed",
"odb_ps": "OdbPs",
"group_id": "GroupId",
"eps_dat": "EpsDat",
"eps_flag": "EpsFlag",
"eps_odb": "EpsOdb",
@@ -43,9 +52,13 @@ var NewUDMSub = &UDMSubUser{
"ard": "Ard",
"epstpl": "Epstpl",
"context_id": "ContextId",
"apn_mum": "ApnNum",
"apn_context": "ApnContext",
"static_ip": "StaticIp",
"cag": "Cag",
"sm_data": "SmData",
"smf_sel": "SmfSel",
"cag": "Cag",
"tenant_id": "TenantID",
"tenant_name": "TenantName", // Tenant name for multi-tenancy
@@ -76,9 +89,10 @@ func (r *UDMSubUser) convertResultRows(rows []map[string]any) []model.UDMSubUser
}
// ClearAndInsert 清空ne_id后新增实体
func (r *UDMSubUser) ClearAndInsert(neID string, u []model.UDMSubUser) int64 {
func (r *UDMSubUser) ClearAndInsert(neId string, u []model.UDMSubUser) int64 {
// 不指定neID时用 TRUNCATE 清空表快
_, err := datasource.ExecDB("", "TRUNCATE TABLE u_sub_user", nil)
// _, err := datasource.ExecDB("", "TRUNCATE TABLE u_sub_user", nil)
_, err := datasource.ExecDB("", "DELETE FROM u_sub_user WHERE ne_id = ?", []any{neId})
if err != nil {
logger.Errorf("TRUNCATE err => %v", err)
}
@@ -91,20 +105,15 @@ func (r *UDMSubUser) SelectPage(query map[string]any) map[string]any {
// 查询条件拼接
var conditions []string
var params []any
if v, ok := query["imsi"]; ok && v != "" {
conditions = append(conditions, "imsi like concat(concat('%', ?), '%')")
params = append(params, strings.Trim(v.(string), " "))
}
if v, ok := query["msisdn"]; ok && v != "" {
conditions = append(conditions, "msisdn like concat(concat('%', ?), '%')")
params = append(params, strings.Trim(v.(string), " "))
}
if v, ok := query["imsi"]; ok && v != "" {
//conditions = append(conditions, "imsi like concat(concat('%', ?), '%')")
//params = append(params, strings.Trim(v.(string), " "))
conditions = append(conditions, "imsi like ?")
params = append(params, v)
}
if v, ok := query["neId"]; ok && v != "" {
conditions = append(conditions, "ne_id = ?")
params = append(params, v)
}
// for multi-tenancy solution
if v, ok := query["tenantName"]; ok && v != "" {
var tenantID []string
@@ -129,13 +138,13 @@ func (r *UDMSubUser) SelectPage(query map[string]any) map[string]any {
if tenantID != "" {
conditions = append(conditions, "s.tenant_id = ?")
params = append(params, tenantID)
query["neId"] = ""
}
// if len(tenantID) > 0 {
// conditions = append(conditions, "s.tenant_id = ?")
// params = append(params, tenantID[0])
// }
}
if v, ok := query["neId"]; ok && v != "" {
conditions = append(conditions, "ne_id = ?")
params = append(params, v)
}
// 构建查询条件语句
whereSql := ""
if len(conditions) > 0 {