add: multi-tenant phase III
This commit is contained in:
@@ -39,4 +39,7 @@ type ISysTenant interface {
|
||||
|
||||
// SelectTenantTreeSelect 查询租户树结构信息
|
||||
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,
|
||||
}
|
||||
|
||||
// SysTenantImpl 部门表 服务层处理
|
||||
// SysTenantImpl 租户表 服务层处理
|
||||
type SysTenantImpl struct {
|
||||
// 部门服务
|
||||
// 租户服务
|
||||
sysTenantRepository repository.ISysTenant
|
||||
// 角色服务
|
||||
sysRoleRepository repository.ISysRole
|
||||
// 角色与部门关联服务
|
||||
// 角色与租户关联服务
|
||||
sysRoleTenantRepository repository.ISysRoleTenant
|
||||
}
|
||||
|
||||
// SelectTenantList 查询部门管理数据
|
||||
// SelectTenantList 查询租户管理数据
|
||||
func (r *SysTenantImpl) SelectTenantList(sysTenant model.SysTenant, dataScopeSQL string) []model.SysTenant {
|
||||
return r.sysTenantRepository.SelectTenantList(sysTenant, dataScopeSQL)
|
||||
}
|
||||
|
||||
// SelectTenantListByRoleId 根据角色ID查询部门树信息 TODO
|
||||
// SelectTenantListByRoleId 根据角色ID查询租户树信息 TODO
|
||||
func (r *SysTenantImpl) SelectTenantListByRoleId(roleId string) []string {
|
||||
roles := r.sysRoleRepository.SelectRoleByIds([]string{roleId})
|
||||
if len(roles) > 0 {
|
||||
@@ -46,7 +46,7 @@ func (r *SysTenantImpl) SelectTenantListByRoleId(roleId string) []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
// SelectTenantById 根据部门ID查询信息
|
||||
// SelectTenantById 根据租户ID查询信息
|
||||
func (r *SysTenantImpl) SelectTenantById(tenantId string) model.SysTenant {
|
||||
return r.sysTenantRepository.SelectTenantById(tenantId)
|
||||
}
|
||||
@@ -56,12 +56,12 @@ func (r *SysTenantImpl) HasChildByTenantId(tenantId string) int64 {
|
||||
return r.sysTenantRepository.HasChildByTenantId(tenantId)
|
||||
}
|
||||
|
||||
// CheckTenantExistUser 查询部门是否存在用户
|
||||
// CheckTenantExistUser 查询租户是否存在用户
|
||||
func (r *SysTenantImpl) CheckTenantExistUser(tenantId string) int64 {
|
||||
return r.sysTenantRepository.CheckTenantExistUser(tenantId)
|
||||
}
|
||||
|
||||
// CheckUniqueTenantName 校验同级部门名称是否唯一
|
||||
// CheckUniqueTenantName 校验同级租户名称是否唯一
|
||||
func (r *SysTenantImpl) CheckUniqueTenantName(tenantName, parentId, tenantId string) bool {
|
||||
uniqueId := r.sysTenantRepository.CheckUniqueTenant(model.SysTenant{
|
||||
TenantName: tenantName,
|
||||
@@ -73,7 +73,7 @@ func (r *SysTenantImpl) CheckUniqueTenantName(tenantName, parentId, tenantId str
|
||||
return uniqueId == ""
|
||||
}
|
||||
|
||||
// CheckUniqueTenantName 校验同级部门名称是否唯一
|
||||
// CheckUniqueTenantName 校验同级租户名称是否唯一
|
||||
func (r *SysTenantImpl) IsUniqueTenancy(tenantID, tenancyType, tenancyKey string) bool {
|
||||
return r.sysTenantRepository.IsUniqueTenancy(model.SysTenant{
|
||||
TenantID: tenantID,
|
||||
@@ -82,16 +82,16 @@ func (r *SysTenantImpl) IsUniqueTenancy(tenantID, tenancyType, tenancyKey string
|
||||
})
|
||||
}
|
||||
|
||||
// InsertTenant 新增部门信息
|
||||
// InsertTenant 新增租户信息
|
||||
func (r *SysTenantImpl) InsertTenant(sysTenant model.SysTenant) string {
|
||||
return r.sysTenantRepository.InsertTenant(sysTenant)
|
||||
}
|
||||
|
||||
// UpdateTenant 修改部门信息
|
||||
// UpdateTenant 修改租户信息
|
||||
func (r *SysTenantImpl) UpdateTenant(sysTenant model.SysTenant) int64 {
|
||||
parentTenant := r.sysTenantRepository.SelectTenantById(sysTenant.ParentID)
|
||||
tenant := r.sysTenantRepository.SelectTenantById(sysTenant.TenantID)
|
||||
// 上级与当前部门祖级列表更新
|
||||
// 上级与当前租户祖级列表更新
|
||||
if parentTenant.TenantID == sysTenant.ParentID && tenant.TenantID == sysTenant.TenantID {
|
||||
newAncestors := parentTenant.Ancestors + "," + parentTenant.TenantID
|
||||
oldAncestors := tenant.Ancestors
|
||||
@@ -101,14 +101,14 @@ func (r *SysTenantImpl) UpdateTenant(sysTenant model.SysTenant) int64 {
|
||||
r.updateTenantChildren(sysTenant.TenantID, newAncestors, oldAncestors)
|
||||
}
|
||||
}
|
||||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
||||
// 如果该租户是启用状态,则启用该租户的所有上级租户
|
||||
if sysTenant.Status == common.STATUS_YES && parentTenant.Status == common.STATUS_NO {
|
||||
r.updateTenantStatusNormal(sysTenant.Ancestors)
|
||||
}
|
||||
return r.sysTenantRepository.UpdateTenant(sysTenant)
|
||||
}
|
||||
|
||||
// updateTenantStatusNormal 修改所在部门正常状态
|
||||
// updateTenantStatusNormal 修改所在租户正常状态
|
||||
func (r *SysTenantImpl) updateTenantStatusNormal(ancestors string) int64 {
|
||||
if ancestors == "" || ancestors == "0" {
|
||||
return 0
|
||||
@@ -132,14 +132,14 @@ func (r *SysTenantImpl) updateTenantChildren(tenantId, newAncestors, oldAncestor
|
||||
return r.sysTenantRepository.UpdateTenantChildren(childrens)
|
||||
}
|
||||
|
||||
// DeleteTenantById 删除部门管理信息
|
||||
// DeleteTenantById 删除租户管理信息
|
||||
func (r *SysTenantImpl) DeleteTenantById(tenantId string) int64 {
|
||||
// 删除角色与部门关联
|
||||
// 删除角色与租户关联
|
||||
r.sysRoleTenantRepository.DeleteTenantRole([]string{tenantId})
|
||||
return r.sysTenantRepository.DeleteTenantById(tenantId)
|
||||
}
|
||||
|
||||
// SelectTenantTreeSelect 查询部门树结构信息
|
||||
// SelectTenantTreeSelect 查询租户树结构信息
|
||||
func (r *SysTenantImpl) SelectTenantTreeSelect(sysTenant model.SysTenant, dataScopeSQL string) []vo.TreeSelect {
|
||||
sysTenants := r.sysTenantRepository.SelectTenantList(sysTenant, dataScopeSQL)
|
||||
tenants := r.parseDataToTree(sysTenants)
|
||||
@@ -209,3 +209,8 @@ func (r *SysTenantImpl) parseDataToTreeComponet(node model.SysTenant, nodesMap *
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// UpdateUDMSubTenantID 更新签约用户租户信息
|
||||
func (r *SysTenantImpl) UpdateUDMSubTenantID(tenantId, assetKey string) int64 {
|
||||
return r.sysTenantRepository.UpdateUDMSubTenantID(tenantId, assetKey)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user