add: multi-tenancy
This commit is contained in:
@@ -664,5 +664,10 @@ INSERT INTO `sys_dict_data` VALUES (2137, 2137, 'dictData.ne_version_status.3',
|
||||
INSERT INTO `sys_dict_data` VALUES (2138, 2138, 'menu.fault.event', '事件通知', 'i18n_zh', '', '', '1', 'supervisor', 1717051745866, '', 0, '');
|
||||
INSERT INTO `sys_dict_data` VALUES (2139, 2139, 'menu.security.tenant', '租户管理', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
INSERT INTO `sys_dict_data` VALUES (2140, 2140, 'menu.security.tenantRemark', '租户管理菜单', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
INSERT INTO `sys_dict_data` VALUES (2141, 2141, 'menu.common.batchadd', '批量增加', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
INSERT INTO `sys_dict_data` VALUES (2142, 2142, 'menu.common.checkdel', '勾选删除', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
INSERT INTO `sys_dict_data` VALUES (2143, 2143, 'menu.common.loaddata', '加载数据', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
INSERT INTO `sys_dict_data` VALUES (2144, 2144, 'menu.common.export', '导出', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
INSERT INTO `sys_dict_data` VALUES (2145, 2145, 'menu.common.checkexport', '勾选导出', 'i18n_zh', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
@@ -664,5 +664,10 @@ INSERT INTO `sys_dict_data` VALUES (4137, 4137, 'dictData.ne_version_status.3',
|
||||
INSERT INTO `sys_dict_data` VALUES (4138, 4138, 'menu.fault.event', 'Event Notification', 'i18n_en', '', '', '1', 'supervisor', 1705550000000, '', 0, '');
|
||||
INSERT INTO `sys_dict_data` VALUES (4139, 4139, 'menu.security.tenant', 'Tenant Management', 'i18n_en', '', '', '1', 'supervisor', 1705550000000, '', 0, '');
|
||||
INSERT INTO `sys_dict_data` VALUES (4140, 4140, 'menu.security.tenantRemark', 'Tenant Management Menu', 'i18n_en', '', '', '1', 'supervisor', 1705550000000, '', 0, '');
|
||||
INSERT INTO `sys_dict_data` VALUES (4141, 4141, 'menu.common.batchadd', 'Batch Add', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
INSERT INTO `sys_dict_data` VALUES (4142, 4142, 'menu.common.checkdel', 'Check Delete', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
INSERT INTO `sys_dict_data` VALUES (4143, 4143, 'menu.common.loaddata', 'Load Data', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
INSERT INTO `sys_dict_data` VALUES (4144, 4144, 'menu.common.export', 'Export', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
INSERT INTO `sys_dict_data` VALUES (4145, 4145, 'menu.common.checkexport', 'Check Export', 'i18n_en', NULL, NULL, '1', 'supervisor', 1700000000000, NULL, 0, NULL);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
@@ -186,6 +186,6 @@ INSERT INTO `sys_menu` VALUES (2144, 'menu.config.neSoftware', 4, 23, 'neSoftwar
|
||||
INSERT INTO `sys_menu` VALUES (2145, 'menu.config.neVersion', 4, 26, 'neVersion', 'ne/neVersion/index', '1', '0', 'M', '1', '1', 'ne:neVersion:list', 'icon-fuzhidaima', 'supervisor', 1708580000000, '', 0, '');
|
||||
INSERT INTO `sys_menu` VALUES (2146, 'menu.ne.neConfPara5G', 4, 8, 'neConfPara5G', 'ne/neConfPara5G/index', '1', '0', 'M', '1', '1', 'ne:neConfPara5G:list', 'icon-wofaqi', 'supervisor', 1708580000000, '', 0, '');
|
||||
INSERT INTO `sys_menu` VALUES (2147, 'menu.fault.event', 2129, 3, 'event', 'faultManage/event/index', '1', '0', 'M', '1', '1', 'faultManage:event:index', 'icon-tubiaoku', 'supervisor', 1717051993146, '', 0, '');
|
||||
INSERT INTO `sys_menu` VALUES (2148, 'menu.security.tenant', 2148, 5, 'tenant', 'system/tenant/index', '1', '1', 'M', '1', '1', 'system:tenant:list', 'icon-yuzhanghao1', 'supervisor', 1700000000000, NULL, 0, 'menu.security.tenantRemark');
|
||||
INSERT INTO `sys_menu` VALUES (2155, 'menu.security.tenant', 2149, 5, 'tenant', 'system/tenant/index', '1', '1', 'M', '1', '1', 'system:tenant:list', 'icon-yuzhanghao1', 'supervisor', 1700000000000, NULL, 0, 'menu.security.tenantRemark');
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
@@ -24,6 +24,7 @@ type UdmSubUser struct {
|
||||
ContextId string `json:"contextId" xorm:"context_id"`
|
||||
ApnContext string `json:"apnContext" xorm:"apn_context"`
|
||||
StaticIp string `json:"staticIp" xorm:"static_ip"`
|
||||
TenantID string `json:"tenantID" xorm:"tenant_id"`
|
||||
TenantName string `json:"tenantName" xorm:"tenant_name"`
|
||||
|
||||
SubNum string `json:"subNum,omitempty" xorm:"-"` // 批量数
|
||||
|
||||
@@ -14,9 +14,11 @@ import (
|
||||
// 实例化数据层 RepoUdmSubUser 结构体
|
||||
var NewRepoUdmSubUser = &RepoUdmSubUser{
|
||||
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",
|
||||
@@ -40,6 +42,7 @@ var NewRepoUdmSubUser = &RepoUdmSubUser{
|
||||
"context_id": "ContextId",
|
||||
"apn_context": "ApnContext",
|
||||
"static_ip": "StaticIp",
|
||||
"tenant_id": "TenantID",
|
||||
"tenant_name": "TenantName",
|
||||
},
|
||||
}
|
||||
@@ -85,10 +88,10 @@ func (r *RepoUdmSubUser) 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)
|
||||
}
|
||||
// if v, ok := query["tenantName"]; ok && v != "" {
|
||||
// conditions = append(conditions, "tenant_name = '?'")
|
||||
// params = append(params, v)
|
||||
// }
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
@@ -165,10 +168,11 @@ func (r *RepoUdmSubUser) SelectList(auth model.UdmSubUser) []model.UdmSubUser {
|
||||
conditions = append(conditions, "ne_id = ?")
|
||||
params = append(params, auth.NeID)
|
||||
}
|
||||
if auth.TenantName != "" {
|
||||
conditions = append(conditions, "tenant_name = '?'")
|
||||
params = append(params, auth.TenantName)
|
||||
}
|
||||
// multi-tenancy
|
||||
// if auth.TenantName != "" {
|
||||
// conditions = append(conditions, "tenant_name = '?'")
|
||||
// params = append(params, auth.TenantName)
|
||||
// }
|
||||
|
||||
// 构建查询条件语句
|
||||
whereSql := ""
|
||||
@@ -490,3 +494,19 @@ func (r *RepoUdmSubUser) SetTenantName(subArr *[]model.UdmSubUser) {
|
||||
(*subArr)[s].TenantName = tenantName
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RepoUdmSubUser) SetTenantID(subArr *[]model.UdmSubUser) {
|
||||
for s := 0; s < len(*subArr); s++ {
|
||||
var tenantID string
|
||||
err := datasource.DefaultDB().Table("sys_tenant").
|
||||
Where("tenancy_type='IMSI' and tenancy_key='?'", (*subArr)[s].Imsi).Cols("tenant_id").Find(tenantID)
|
||||
if err != nil {
|
||||
log.Errorf("Find tenant_id err => %v", err)
|
||||
continue
|
||||
}
|
||||
if tenantID != "" {
|
||||
log.Infof("tenantID=%s imsi=%s", tenantID, (*subArr)[s].Imsi)
|
||||
}
|
||||
(*subArr)[s].TenantID = tenantID
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ type UDMSub struct {
|
||||
ContextId string `json:"contextId" gorm:"column:context_id"`
|
||||
ApnContext string `json:"apnContext" gorm:"column:apn_context"`
|
||||
StaticIp string `json:"staticIp" gorm:"column:static_ip"`
|
||||
TenantID string `json:"tenantID" gorm:"column:tenant_id"`
|
||||
TenantName string `json:"tenantName" gorm:"column:tenant_name"`
|
||||
|
||||
// ====== 非数据库字段属性 ======
|
||||
|
||||
@@ -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 := ""
|
||||
|
||||
@@ -15,7 +15,8 @@ import (
|
||||
// 实例化数据层 SysTenantImpl 结构体
|
||||
var NewSysTenantImpl = &SysTenantImpl{
|
||||
selectSql: `select
|
||||
t.tenant_id, t.parent_id, t.ancestors, t.tenant_name, t.order_num, t.tenancy_type, t.tenancy_key, t.status, t.del_flag, t.create_by, t.create_time
|
||||
t.tenant_id, t.parent_id, t.ancestors, t.tenant_name, t.order_num, t.tenancy_type, t.tenancy_key, t.status,
|
||||
t.del_flag, t.create_by, t.create_time
|
||||
from sys_tenant t`,
|
||||
|
||||
resultMap: map[string]string{
|
||||
|
||||
Reference in New Issue
Block a user