add: multi-tenancy

This commit is contained in:
2024-06-14 17:52:06 +08:00
parent fde377fbd4
commit 10d3a3b863
8 changed files with 57 additions and 22 deletions

View File

@@ -1,7 +1,6 @@
package repository
import (
"fmt"
"strconv"
"strings"
@@ -15,9 +14,11 @@ import (
// 实例化数据层 UDMSubImpl 结构体
var NewUDMSubImpl = &UDMSubImpl{
selectSql: `select
id, msisdn, imsi, ambr, nssai, rat, arfb, sar, cn, sm_data, smf_sel, eps_dat, ne_id, eps_flag, eps_odb, hplmn_odb, ard, epstpl, context_id, apn_context, static_ip,
tenant_name
from u_sub_user`,
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,
t.tenant_id, t.tenant_name
from u_sub_user s
left join sys_tenant t on t.tenant_id = s.tenant_id`,
resultMap: map[string]string{
"id": "ID",
@@ -41,6 +42,7 @@ var NewUDMSubImpl = &UDMSubImpl{
"context_id": "ContextId",
"apn_context": "ApnContext",
"static_ip": "StaticIp",
"tenant_id": "TenantID",
"tenant_name": "TenantName", // Tenant name for multi-tenancy
},
}
@@ -97,11 +99,11 @@ func (r *UDMSubImpl) SelectPage(query map[string]any) map[string]any {
params = append(params, v)
}
// for multi-tenancy solution
if v, ok := query["tenantName"]; ok && v != "" {
conditions = append(conditions, "tenant_name = ?")
params = append(params, v)
fmt.Printf("tenantName = %s", v)
}
// if v, ok := query["tenantName"]; ok && v != "" {
// conditions = append(conditions, "tenant_name = ?")
// params = append(params, v)
// fmt.Printf("tenantName = %s", v)
// }
// 构建查询条件语句
whereSql := ""