|
|
|
@ -69,7 +69,7 @@ public class TenantService : ITenantService
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<long[]> GetTenantPermission(string id)
|
|
|
|
|
{
|
|
|
|
|
var data = db.Queryable<SysPermissionTenant>().Filter(null, true).Where(x => x.TenantId == long.Parse(id))
|
|
|
|
|
var data = db.Queryable<SysPermissionTenant>().Filter(null, true).Where(x => x.TenantId == long.Parse(id) && x.IsHidden == false)
|
|
|
|
|
.Select(x => x.PermissionId).ToArray();
|
|
|
|
|
return DataResult<long[]>.Success("获取数据成功!", data, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
}
|
|
|
|
@ -87,16 +87,23 @@ public class TenantService : ITenantService
|
|
|
|
|
db.Ado.BeginTran();
|
|
|
|
|
|
|
|
|
|
var existPermissions = db.Queryable<SysPermissionTenant>().Filter(null, true)
|
|
|
|
|
.Where(x => x.TenantId == req.TenantId).Select(n => n.PermissionId).ToArray();
|
|
|
|
|
.Where(x => x.TenantId == req.TenantId && x.IsHidden == false).Select(n => n.PermissionId).ToArray();
|
|
|
|
|
var hiddenPermissions = db.Queryable<SysPermissionTenant>().Filter(null, true)
|
|
|
|
|
.Where(x => x.TenantId == req.TenantId && x.IsHidden == true).Select(n => n.PermissionId).ToArray();
|
|
|
|
|
var tenant = db.Queryable<SysTenant>().First(x => x.Id == req.TenantId);
|
|
|
|
|
IEnumerable<long> delPermissions = existPermissions.AsQueryable().Except(req.PermissionIds);
|
|
|
|
|
// if (delPermissions.Count() > 0)
|
|
|
|
|
// {
|
|
|
|
|
// var delPers = db.Queryable<SysPermissionTenant>().Filter(null, true).Where(x =>
|
|
|
|
|
// x.TenantId == req.TenantId && delPermissions.Contains(x.PermissionId))
|
|
|
|
|
// .ToList();
|
|
|
|
|
// db.Deleteable(delPers).ExecuteCommand();
|
|
|
|
|
// }
|
|
|
|
|
//取消权限
|
|
|
|
|
if (delPermissions.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
var delPers = db.Queryable<SysPermissionTenant>().Filter(null, true).Where(x =>
|
|
|
|
|
x.TenantId == req.TenantId && delPermissions.Contains(x.PermissionId))
|
|
|
|
|
.ToList();
|
|
|
|
|
foreach (var item in delPers)
|
|
|
|
|
{
|
|
|
|
|
item.IsHidden = true;
|
|
|
|
|
}
|
|
|
|
|
db.Updateable(delPers).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerable<long> addPermissions = req.PermissionIds.AsQueryable().Except(existPermissions);
|
|
|
|
|
if (addPermissions.Count() > 0)
|
|
|
|
@ -111,24 +118,37 @@ public class TenantService : ITenantService
|
|
|
|
|
//写入租户管理员权限
|
|
|
|
|
var rolePerList = new List<SysRolePermission>();
|
|
|
|
|
foreach (var item in addPers)
|
|
|
|
|
{
|
|
|
|
|
var rolePer = item.Adapt<SysRolePermission>();
|
|
|
|
|
rolePer.RoleId = tenantRole.Id;
|
|
|
|
|
rolePer.PermissionId = item.Id;
|
|
|
|
|
rolePer.IsPermission = 1;
|
|
|
|
|
{
|
|
|
|
|
if (!db.Queryable<SysRolePermission>().Where(x => x.RoleId == tenantRole.Id && x.PermissionId == item.Id).Any())
|
|
|
|
|
{
|
|
|
|
|
var rolePer = item.Adapt<SysRolePermission>();
|
|
|
|
|
rolePer.RoleId = tenantRole.Id;
|
|
|
|
|
rolePer.PermissionId = item.Id;
|
|
|
|
|
rolePer.IsPermission = 1;
|
|
|
|
|
|
|
|
|
|
rolePerList.Add(rolePer);
|
|
|
|
|
rolePerList.Add(rolePer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
db.Insertable(rolePerList).ExecuteCommandAsync();
|
|
|
|
|
#endregion 处理租户管理员新增权限
|
|
|
|
|
var tenantPerList = new List<SysPermissionTenant>();
|
|
|
|
|
foreach (var item in addPers)
|
|
|
|
|
{
|
|
|
|
|
var tenantPer = item.Adapt<SysPermissionTenant>();
|
|
|
|
|
tenantPer.TenantId = req.TenantId;
|
|
|
|
|
tenantPer.PermissionId = item.Id;
|
|
|
|
|
if (hiddenPermissions.Contains(item.Id))
|
|
|
|
|
{
|
|
|
|
|
var tenantPer = db.Queryable<SysPermissionTenant>().Filter(null, true).Where(x => x.PermissionId == item.Id && x.TenantId == req.TenantId && x.IsHidden == true).First();
|
|
|
|
|
tenantPer.IsHidden = false;
|
|
|
|
|
db.Updateable(tenantPer).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var tenantPer = item.Adapt<SysPermissionTenant>();
|
|
|
|
|
tenantPer.TenantId = req.TenantId;
|
|
|
|
|
tenantPer.PermissionId = item.Id;
|
|
|
|
|
|
|
|
|
|
tenantPerList.Add(tenantPer);
|
|
|
|
|
tenantPerList.Add(tenantPer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.Insertable(tenantPerList).ExecuteCommand();
|
|
|
|
|