add: multi-tenant phase III
This commit is contained in:
@@ -328,6 +328,7 @@ func PostGoldKPIFromNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
// kip_id ...
|
// kip_id ...
|
||||||
"neType": goldKpi.NEType,
|
"neType": goldKpi.NEType,
|
||||||
"neName": goldKpi.NEName,
|
"neName": goldKpi.NEName,
|
||||||
|
"rmUID": goldKpi.RmUid,
|
||||||
"startIndex": goldKpi.Index,
|
"startIndex": goldKpi.Index,
|
||||||
"timeGroup": goldKpi.StartTime,
|
"timeGroup": goldKpi.StartTime,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ func (s *AMFController) UEList(c *gin.Context) {
|
|||||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
querys.RmUID = neInfo.RmUID
|
// remove for multi amf,
|
||||||
|
//querys.RmUID = neInfo.RmUID
|
||||||
|
|
||||||
// 查询数据
|
// 查询数据
|
||||||
data := s.ueEventService.SelectPage(querys)
|
data := s.ueEventService.SelectPage(querys)
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ func (r *PerfKPIImpl) SelectKpiReport(query model.GoldKPIQuery, kpiIds []string)
|
|||||||
"min(CASE WHEN gk.index != '' THEN gk.index ELSE 0 END) AS startIndex",
|
"min(CASE WHEN gk.index != '' THEN gk.index ELSE 0 END) AS startIndex",
|
||||||
"min(CASE WHEN gk.ne_type != '' THEN gk.ne_type ELSE 0 END) AS neType",
|
"min(CASE WHEN gk.ne_type != '' THEN gk.ne_type ELSE 0 END) AS neType",
|
||||||
"min(CASE WHEN gk.ne_name != '' THEN gk.ne_name ELSE 0 END) AS neName",
|
"min(CASE WHEN gk.ne_name != '' THEN gk.ne_name ELSE 0 END) AS neName",
|
||||||
|
"min(CASE WHEN gk.rm_uid != '' THEN gk.rm_uid ELSE 0 END) AS rmUID",
|
||||||
}
|
}
|
||||||
for i, kid := range kpiIds {
|
for i, kid := range kpiIds {
|
||||||
// 特殊字段,只取最后一次收到的非0值
|
// 特殊字段,只取最后一次收到的非0值
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"be.ems/lib/log"
|
||||||
"be.ems/src/framework/constants/common"
|
"be.ems/src/framework/constants/common"
|
||||||
"be.ems/src/framework/i18n"
|
"be.ems/src/framework/i18n"
|
||||||
"be.ems/src/framework/utils/ctx"
|
"be.ems/src/framework/utils/ctx"
|
||||||
@@ -144,7 +145,7 @@ func (s *SysTenantController) Add(c *gin.Context) {
|
|||||||
uniqueTenancy := s.sysTenantService.IsUniqueTenancy(body.TenantID, body.TenancyType, body.TenancyKey)
|
uniqueTenancy := s.sysTenantService.IsUniqueTenancy(body.TenantID, body.TenancyType, body.TenancyKey)
|
||||||
if !uniqueTenancy {
|
if !uniqueTenancy {
|
||||||
// 租赁对象添加失败,租赁对象已存在
|
// 租赁对象添加失败,租赁对象已存在
|
||||||
msg := i18n.TTemplate(language, "ERROR: tenancy key already exists", map[string]any{"key": body.TenancyKey})
|
msg := i18n.TTemplate(language, "ERROR: tenancy asset already exists", map[string]any{"key": body.TenancyKey})
|
||||||
c.JSON(200, result.ErrMsg(msg))
|
c.JSON(200, result.ErrMsg(msg))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -153,9 +154,15 @@ func (s *SysTenantController) Add(c *gin.Context) {
|
|||||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||||
insertId := s.sysTenantService.InsertTenant(body)
|
insertId := s.sysTenantService.InsertTenant(body)
|
||||||
if insertId != "" {
|
if insertId != "" {
|
||||||
|
// 如果是增加SIM Card类型的,需更新udm_sub_user
|
||||||
|
if body.TenancyType == "IMSI" && body.Status == "1" {
|
||||||
|
affected := s.sysTenantService.UpdateUDMSubTenantID(body.ParentID, body.TenancyKey)
|
||||||
|
log.Tracef("body.ParentID=%s, body.TenancyKey=%s, update affected=%v", body.ParentID, body.TenancyKey, affected)
|
||||||
|
}
|
||||||
c.JSON(200, result.Ok(nil))
|
c.JSON(200, result.Ok(nil))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, result.Err(nil))
|
c.JSON(200, result.Err(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +216,7 @@ func (s *SysTenantController) Edit(c *gin.Context) {
|
|||||||
uniqueTenancy := s.sysTenantService.IsUniqueTenancy(body.TenantID, body.TenancyType, body.TenancyKey)
|
uniqueTenancy := s.sysTenantService.IsUniqueTenancy(body.TenantID, body.TenancyType, body.TenancyKey)
|
||||||
if !uniqueTenancy {
|
if !uniqueTenancy {
|
||||||
// 租赁对象添加失败,租赁对象已存在
|
// 租赁对象添加失败,租赁对象已存在
|
||||||
msg := i18n.TTemplate(language, "ERROR: tenancy key already exists", map[string]any{"key": body.TenancyKey})
|
msg := i18n.TTemplate(language, "ERROR: tenancy asset already exists", map[string]any{"key": body.TenancyKey})
|
||||||
c.JSON(200, result.ErrMsg(msg))
|
c.JSON(200, result.ErrMsg(msg))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -233,12 +240,27 @@ func (s *SysTenantController) Edit(c *gin.Context) {
|
|||||||
body.TenantName = tenantInfo.TenantName
|
body.TenantName = tenantInfo.TenantName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tenantOldInfo := s.sysTenantService.SelectTenantById(body.TenantID)
|
||||||
body.UpdateBy = ctx.LoginUserToUserName(c)
|
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||||
rows := s.sysTenantService.UpdateTenant(body)
|
rows := s.sysTenantService.UpdateTenant(body)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
|
// 如果是更新的是SIM Card类型的,需更新udm_sub_user
|
||||||
|
// 先清空签约用户原有的租户信息
|
||||||
|
if tenantOldInfo.TenancyType == "IMSI" && tenantOldInfo.Status == "1" {
|
||||||
|
affected := s.sysTenantService.UpdateUDMSubTenantID("", tenantOldInfo.TenancyKey)
|
||||||
|
log.Tracef("tenantOldInfo.ParentID=%s, tenantOldInfo.TenancyKey=%s, update affected=%v",
|
||||||
|
tenantOldInfo.ParentID, tenantOldInfo.TenancyKey, affected)
|
||||||
|
}
|
||||||
|
// 设置新的租户信息
|
||||||
|
if body.TenancyType == "IMSI" && body.Status == "1" {
|
||||||
|
affected := s.sysTenantService.UpdateUDMSubTenantID(body.ParentID, body.TenancyKey)
|
||||||
|
log.Tracef("body.ParentID=%s, body.TenancyKey=%s, update affected=%v",
|
||||||
|
body.ParentID, body.TenancyKey, affected)
|
||||||
|
}
|
||||||
c.JSON(200, result.Ok(nil))
|
c.JSON(200, result.Ok(nil))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, result.Err(nil))
|
c.JSON(200, result.Err(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,13 +301,20 @@ func (s *SysTenantController) Remove(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tenantOldInfo := s.sysTenantService.SelectTenantById(tenantId)
|
||||||
rows := s.sysTenantService.DeleteTenantById(tenantId)
|
rows := s.sysTenantService.DeleteTenantById(tenantId)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
|
// 如果是删除的是SIM Card类型的,需删除相关的udm_sub_user的租户信息
|
||||||
|
if tenantOldInfo.TenancyType == "IMSI" && tenantOldInfo.Status == "1" {
|
||||||
|
affected := s.sysTenantService.UpdateUDMSubTenantID("", tenantOldInfo.TenancyKey)
|
||||||
|
log.Tracef("tenantOldInfo.ParentID=%s, tenantOldInfo.TenancyKey=%s, update affected=%v", tenantOldInfo.ParentID, tenantOldInfo.TenancyKey, affected)
|
||||||
|
}
|
||||||
// 删除成功:%d
|
// 删除成功:%d
|
||||||
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
||||||
c.JSON(200, result.OkMsg(msg))
|
c.JSON(200, result.OkMsg(msg))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, result.Err(nil))
|
c.JSON(200, result.Err(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,4 +42,7 @@ type ISysTenant interface {
|
|||||||
|
|
||||||
// DeleteTenantById 删除租户管理信息
|
// DeleteTenantById 删除租户管理信息
|
||||||
DeleteTenantById(tenantId string) int64
|
DeleteTenantById(tenantId string) int64
|
||||||
|
|
||||||
|
// DeleteTenantById 删除租户管理信息
|
||||||
|
UpdateUDMSubTenantID(tenantId, assetKey string) int64
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -429,3 +429,14 @@ func (r *SysTenantImpl) DeleteTenantById(tenantId string) int64 {
|
|||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteTenantById 删除租户管理信息
|
||||||
|
func (r *SysTenantImpl) UpdateUDMSubTenantID(tenantId, assetKey string) int64 {
|
||||||
|
sql := "update u_sub_user set tenant_id = ? where imsi like ?"
|
||||||
|
results, err := datasource.ExecDB("", sql, []any{tenantId, assetKey})
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("update err: %v", err)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
|||||||
@@ -39,4 +39,7 @@ type ISysTenant interface {
|
|||||||
|
|
||||||
// SelectTenantTreeSelect 查询租户树结构信息
|
// SelectTenantTreeSelect 查询租户树结构信息
|
||||||
SelectTenantTreeSelect(sysTenant model.SysTenant, dataScopeSQL string) []vo.TreeSelect
|
SelectTenantTreeSelect(sysTenant model.SysTenant, dataScopeSQL string) []vo.TreeSelect
|
||||||
|
|
||||||
|
// set UDM sub tenant_id
|
||||||
|
UpdateUDMSubTenantID(tenantId, assetKey string) int64
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,22 +16,22 @@ var NewSysTenantImpl = &SysTenantImpl{
|
|||||||
sysRoleTenantRepository: repository.NewSysRoleTenantImpl,
|
sysRoleTenantRepository: repository.NewSysRoleTenantImpl,
|
||||||
}
|
}
|
||||||
|
|
||||||
// SysTenantImpl 部门表 服务层处理
|
// SysTenantImpl 租户表 服务层处理
|
||||||
type SysTenantImpl struct {
|
type SysTenantImpl struct {
|
||||||
// 部门服务
|
// 租户服务
|
||||||
sysTenantRepository repository.ISysTenant
|
sysTenantRepository repository.ISysTenant
|
||||||
// 角色服务
|
// 角色服务
|
||||||
sysRoleRepository repository.ISysRole
|
sysRoleRepository repository.ISysRole
|
||||||
// 角色与部门关联服务
|
// 角色与租户关联服务
|
||||||
sysRoleTenantRepository repository.ISysRoleTenant
|
sysRoleTenantRepository repository.ISysRoleTenant
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectTenantList 查询部门管理数据
|
// SelectTenantList 查询租户管理数据
|
||||||
func (r *SysTenantImpl) SelectTenantList(sysTenant model.SysTenant, dataScopeSQL string) []model.SysTenant {
|
func (r *SysTenantImpl) SelectTenantList(sysTenant model.SysTenant, dataScopeSQL string) []model.SysTenant {
|
||||||
return r.sysTenantRepository.SelectTenantList(sysTenant, dataScopeSQL)
|
return r.sysTenantRepository.SelectTenantList(sysTenant, dataScopeSQL)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectTenantListByRoleId 根据角色ID查询部门树信息 TODO
|
// SelectTenantListByRoleId 根据角色ID查询租户树信息 TODO
|
||||||
func (r *SysTenantImpl) SelectTenantListByRoleId(roleId string) []string {
|
func (r *SysTenantImpl) SelectTenantListByRoleId(roleId string) []string {
|
||||||
roles := r.sysRoleRepository.SelectRoleByIds([]string{roleId})
|
roles := r.sysRoleRepository.SelectRoleByIds([]string{roleId})
|
||||||
if len(roles) > 0 {
|
if len(roles) > 0 {
|
||||||
@@ -46,7 +46,7 @@ func (r *SysTenantImpl) SelectTenantListByRoleId(roleId string) []string {
|
|||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectTenantById 根据部门ID查询信息
|
// SelectTenantById 根据租户ID查询信息
|
||||||
func (r *SysTenantImpl) SelectTenantById(tenantId string) model.SysTenant {
|
func (r *SysTenantImpl) SelectTenantById(tenantId string) model.SysTenant {
|
||||||
return r.sysTenantRepository.SelectTenantById(tenantId)
|
return r.sysTenantRepository.SelectTenantById(tenantId)
|
||||||
}
|
}
|
||||||
@@ -56,12 +56,12 @@ func (r *SysTenantImpl) HasChildByTenantId(tenantId string) int64 {
|
|||||||
return r.sysTenantRepository.HasChildByTenantId(tenantId)
|
return r.sysTenantRepository.HasChildByTenantId(tenantId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckTenantExistUser 查询部门是否存在用户
|
// CheckTenantExistUser 查询租户是否存在用户
|
||||||
func (r *SysTenantImpl) CheckTenantExistUser(tenantId string) int64 {
|
func (r *SysTenantImpl) CheckTenantExistUser(tenantId string) int64 {
|
||||||
return r.sysTenantRepository.CheckTenantExistUser(tenantId)
|
return r.sysTenantRepository.CheckTenantExistUser(tenantId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckUniqueTenantName 校验同级部门名称是否唯一
|
// CheckUniqueTenantName 校验同级租户名称是否唯一
|
||||||
func (r *SysTenantImpl) CheckUniqueTenantName(tenantName, parentId, tenantId string) bool {
|
func (r *SysTenantImpl) CheckUniqueTenantName(tenantName, parentId, tenantId string) bool {
|
||||||
uniqueId := r.sysTenantRepository.CheckUniqueTenant(model.SysTenant{
|
uniqueId := r.sysTenantRepository.CheckUniqueTenant(model.SysTenant{
|
||||||
TenantName: tenantName,
|
TenantName: tenantName,
|
||||||
@@ -73,7 +73,7 @@ func (r *SysTenantImpl) CheckUniqueTenantName(tenantName, parentId, tenantId str
|
|||||||
return uniqueId == ""
|
return uniqueId == ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckUniqueTenantName 校验同级部门名称是否唯一
|
// CheckUniqueTenantName 校验同级租户名称是否唯一
|
||||||
func (r *SysTenantImpl) IsUniqueTenancy(tenantID, tenancyType, tenancyKey string) bool {
|
func (r *SysTenantImpl) IsUniqueTenancy(tenantID, tenancyType, tenancyKey string) bool {
|
||||||
return r.sysTenantRepository.IsUniqueTenancy(model.SysTenant{
|
return r.sysTenantRepository.IsUniqueTenancy(model.SysTenant{
|
||||||
TenantID: tenantID,
|
TenantID: tenantID,
|
||||||
@@ -82,16 +82,16 @@ func (r *SysTenantImpl) IsUniqueTenancy(tenantID, tenancyType, tenancyKey string
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertTenant 新增部门信息
|
// InsertTenant 新增租户信息
|
||||||
func (r *SysTenantImpl) InsertTenant(sysTenant model.SysTenant) string {
|
func (r *SysTenantImpl) InsertTenant(sysTenant model.SysTenant) string {
|
||||||
return r.sysTenantRepository.InsertTenant(sysTenant)
|
return r.sysTenantRepository.InsertTenant(sysTenant)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateTenant 修改部门信息
|
// UpdateTenant 修改租户信息
|
||||||
func (r *SysTenantImpl) UpdateTenant(sysTenant model.SysTenant) int64 {
|
func (r *SysTenantImpl) UpdateTenant(sysTenant model.SysTenant) int64 {
|
||||||
parentTenant := r.sysTenantRepository.SelectTenantById(sysTenant.ParentID)
|
parentTenant := r.sysTenantRepository.SelectTenantById(sysTenant.ParentID)
|
||||||
tenant := r.sysTenantRepository.SelectTenantById(sysTenant.TenantID)
|
tenant := r.sysTenantRepository.SelectTenantById(sysTenant.TenantID)
|
||||||
// 上级与当前部门祖级列表更新
|
// 上级与当前租户祖级列表更新
|
||||||
if parentTenant.TenantID == sysTenant.ParentID && tenant.TenantID == sysTenant.TenantID {
|
if parentTenant.TenantID == sysTenant.ParentID && tenant.TenantID == sysTenant.TenantID {
|
||||||
newAncestors := parentTenant.Ancestors + "," + parentTenant.TenantID
|
newAncestors := parentTenant.Ancestors + "," + parentTenant.TenantID
|
||||||
oldAncestors := tenant.Ancestors
|
oldAncestors := tenant.Ancestors
|
||||||
@@ -101,14 +101,14 @@ func (r *SysTenantImpl) UpdateTenant(sysTenant model.SysTenant) int64 {
|
|||||||
r.updateTenantChildren(sysTenant.TenantID, newAncestors, oldAncestors)
|
r.updateTenantChildren(sysTenant.TenantID, newAncestors, oldAncestors)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
// 如果该租户是启用状态,则启用该租户的所有上级租户
|
||||||
if sysTenant.Status == common.STATUS_YES && parentTenant.Status == common.STATUS_NO {
|
if sysTenant.Status == common.STATUS_YES && parentTenant.Status == common.STATUS_NO {
|
||||||
r.updateTenantStatusNormal(sysTenant.Ancestors)
|
r.updateTenantStatusNormal(sysTenant.Ancestors)
|
||||||
}
|
}
|
||||||
return r.sysTenantRepository.UpdateTenant(sysTenant)
|
return r.sysTenantRepository.UpdateTenant(sysTenant)
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateTenantStatusNormal 修改所在部门正常状态
|
// updateTenantStatusNormal 修改所在租户正常状态
|
||||||
func (r *SysTenantImpl) updateTenantStatusNormal(ancestors string) int64 {
|
func (r *SysTenantImpl) updateTenantStatusNormal(ancestors string) int64 {
|
||||||
if ancestors == "" || ancestors == "0" {
|
if ancestors == "" || ancestors == "0" {
|
||||||
return 0
|
return 0
|
||||||
@@ -132,14 +132,14 @@ func (r *SysTenantImpl) updateTenantChildren(tenantId, newAncestors, oldAncestor
|
|||||||
return r.sysTenantRepository.UpdateTenantChildren(childrens)
|
return r.sysTenantRepository.UpdateTenantChildren(childrens)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteTenantById 删除部门管理信息
|
// DeleteTenantById 删除租户管理信息
|
||||||
func (r *SysTenantImpl) DeleteTenantById(tenantId string) int64 {
|
func (r *SysTenantImpl) DeleteTenantById(tenantId string) int64 {
|
||||||
// 删除角色与部门关联
|
// 删除角色与租户关联
|
||||||
r.sysRoleTenantRepository.DeleteTenantRole([]string{tenantId})
|
r.sysRoleTenantRepository.DeleteTenantRole([]string{tenantId})
|
||||||
return r.sysTenantRepository.DeleteTenantById(tenantId)
|
return r.sysTenantRepository.DeleteTenantById(tenantId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectTenantTreeSelect 查询部门树结构信息
|
// SelectTenantTreeSelect 查询租户树结构信息
|
||||||
func (r *SysTenantImpl) SelectTenantTreeSelect(sysTenant model.SysTenant, dataScopeSQL string) []vo.TreeSelect {
|
func (r *SysTenantImpl) SelectTenantTreeSelect(sysTenant model.SysTenant, dataScopeSQL string) []vo.TreeSelect {
|
||||||
sysTenants := r.sysTenantRepository.SelectTenantList(sysTenant, dataScopeSQL)
|
sysTenants := r.sysTenantRepository.SelectTenantList(sysTenant, dataScopeSQL)
|
||||||
tenants := r.parseDataToTree(sysTenants)
|
tenants := r.parseDataToTree(sysTenants)
|
||||||
@@ -209,3 +209,8 @@ func (r *SysTenantImpl) parseDataToTreeComponet(node model.SysTenant, nodesMap *
|
|||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateUDMSubTenantID 更新签约用户租户信息
|
||||||
|
func (r *SysTenantImpl) UpdateUDMSubTenantID(tenantId, assetKey string) int64 {
|
||||||
|
return r.sysTenantRepository.UpdateUDMSubTenantID(tenantId, assetKey)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user